项目配置(spring-boot:1.5.x)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<dependecies > <dependency > <groupId > io.micrometer</groupId > <artifactId > micrometer-spring-legacy</artifactId > <version > RELEASE</version > </dependency > <dependency > <groupId > io.micrometer</groupId > <artifactId > micrometer-registry-prometheus</artifactId > <version > RELEASE</version > </dependency > <dependency > <groupId > org.springframework.boot</groupId > <artifactId > spring-boot-starter-actuator</artifactId > </dependency > <dependency > <groupId > org.springframework.boot</groupId > <artifactId > spring-boot-starter-security</artifactId > </dependency > </dependecies >
grafana
Dashboard for Spring Boot 1.x applications, using Micrometer and Prometheus.
Features
Overall status
API stats
Tomcat
JVM
变量
Only one variable is declared in Grafana: 在该dashboard中有一个变量 $job
, 用来标识job名, 等同于prometheus
中的job_name
, 不过在监控consul
的服务时, 用来标识服务名, 即项目里配置的 spring.application.name
配置方式:
{dashboard} -> settings -> Variables
promethues 配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
scrape_configs: - job_name: 'consul_services' consul_sd_configs: - server: '${consul-server}:8500' services: ['${server.name}' ] relabel_configs: - source_labels: ['__metrics_path__' ] regex: '/metrics' target_label: __metrics_path__ replacement: '/prometheus' - job_name: 'consul_server' metrics_path: '/prometheus' consul_sd_configs: - server: '${consul-server}:8500' services: ['${server.name}' ] relabel_configs: - source_labels: ['__meta_consul_service' ] regex: '(.*)' replacement: '$1' action: replace target_label: 'job' - job_name: my-app-prod scheme: https basic_auth: username: your_actuator_user password: your_actuator_password metrics_path: /MyApp/actuator/prometheus static_configs: - targets: - "your_hostname:your_port" - job_name: my-app-prod scheme: http metrics_path: /MyApp/actuator/prometheus static_configs: - targets: - "your_hostname:your_port"
效果预览
文章导航