springboot 监控

-

依赖

1
2
3
4
5
6
7
8
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

config

1
2
3
4
5
6
7
8
management:
endpoints:
web:
exposure:
include: "prometheus"
metrics:
tags:
application: ${spring.application.name}

test

1
2
3
4
5
6
7
8
# HELP jvm_threads_states_threads The current number of threads having NEW state
# TYPE jvm_threads_states_threads gauge
jvm_threads_states_threads{application="demo",state="waiting",} 11.0
jvm_threads_states_threads{application="demo",state="blocked",} 0.0
jvm_threads_states_threads{application="demo",state="timed-waiting",} 4.0
jvm_threads_states_threads{application="demo",state="runnable",} 8.0
jvm_threads_states_threads{application="demo",state="new",} 0.0
jvm_threads_states_threads{application="demo",state="terminated",} 0.0

对接 prometheus

prometheus 一款开源的监控 + 时序数据库 + 报警软件

prometheus.yml

1
2
3
4
5
6
7
8
9
10
11
12
scrape_configs:
# 任意写,建议英文,不要包含特殊字符
- job_name: "spring"
# 多久采集一次数据
scrape_interval: 15s
# 采集时的超时时间
scrape_timeout: 10s
# 采集的路径是啥
metrics_path: "/actuator/prometheus"
# 采集服务的地址,设置成上面Spring Boot应用所在服务器的具体地址。
static_configs:
- targets: ["host.docker.internal:8000"]

在prometheus.yml 文件所在目录执行如下命令,启动Prometheus

1
2
3
docker run -d -p 9090:9090 \
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus --config.file=/etc/prometheus/prometheus.yml

test

Grafana可视化

1
docker run -d -p 3001:3000 grafana/grafana

test


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×