在SpringBoot项目中引入Prometheus的依赖包:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 集成micrometer,将监控数据存储到prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
由于prometheus需要springboot暴露端口,需要同时引入actuator依赖,从docker仓库中拉去prometheus的镜像:docker pull bitnami/prometheus
启动一个prometheus容器:
docker run -u root --name prometheus -d -p 192.168.137.18:9090:9090 -v /usr/local/scion/prometheus/prometheus.yml:/conf/prometheus.yml bitnami/prometheus
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'auto-generator'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['192.168.137.18:9000']
"labels": {
"instance": "devtools-service",
"service": "devtools-service"
}
在prometheus.yml中添加自己的服务,格式按照prometheus这个job的示例
安装一个grafana的仪表盘:
docker run -d --name=grafana -p 3000:3000 grafana/grafana
Grafana默认用户名:密码 admin:admin,进入后修改密码
配置数据源
导入jvm监控仪表板