【spring-boot】配置grafana

项目配置(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>
<!-- 1.1.1 -->
<!-- prometheus相关依赖 -->
<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>

<!-- Actuator (with security enabled) -->
<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
# 监控consul
scrape_configs:
# cousul_services
- job_name: 'consul_services'
consul_sd_configs:
- server: '${consul-server}:8500'
services: ['${server.name}']

# 修改抓取route
relabel_configs:
- source_labels: ['__metrics_path__']
regex: '/metrics'
target_label: __metrics_path__
replacement: '/prometheus'

# 通过consul监控所有服务
- job_name: 'consul_server'
metrics_path: '/prometheus'
consul_sd_configs:
- server: '${consul-server}:8500'
services: ['${server.name}']
# 修改抓取route
relabel_configs:
- source_labels: ['__meta_consul_service']
regex: '(.*)'
replacement: '$1'
action: replace
target_label: 'job'

# 监控普通spring-boot项目
# for https
- 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"

# for http
- job_name: my-app-prod
scheme: http
metrics_path: /MyApp/actuator/prometheus
static_configs:
- targets:
- "your_hostname:your_port"

效果预览

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注