搭建后的应用信息
springboot应用:192.168.97.128:8001
prometheus:192.168.97.128:9090 (默认配置端口的是9090)
grafana:192.168.97.128:3000(默认端口3000,用户名密码 admin/admin)
一、springboot配置
引入项目依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
在yml添加actuator配置,开启监控
management:
endpoints:
enabled: true
web:
base-path: /actuator # 访问根路径
exposure:
include: "*"
访问http://192.168.97.128:8001/actuator/prometheus,可以看到指标信息。
二、安装配置prometheus
下载linux安装包,tar解压缩
https://github.com/prometheus/prometheus/releases
修改prometheus.yml
# 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: 'spring-actuator'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['192.168.97.128:8001']
执行./prometheus --config.file=prometheus.yml启动应用后
访问http://192.168.97.128:9090/targets 可以看到监控应用是否正常
三、安装grafana
下载Grafana:https://grafana.com/grafana/download
wget https://dl.grafana.com/oss/release/grafana-7.0.3-1.x86_64.rpm
sudo yum install grafana-7.0.3-1.x86_64.rpm
进行安装
启动服务
service grafana-server start
访问http://192.168.97.128:3000/
配置datasource,也就是之前yml里prometheus的地址
https://grafana.com/dashboards 可以找到别人已经配置好的监控指标,找一个。下载json文件。
点击import
拷贝下载的json内容和对应dashborad的id
配置数据源
监控系统搭建完成