- 服务器环境
CentOS Linux release 7.9.2009 (Core)
Docker version 18.03.1-ce
安装前先同步服务器时间,prometheus对时间比较敏感
安装Grafana
docker run -d --restart always -p 3000:3000 --name=grafana -v /etc/localtime:/etc/localtime -v /data/grafana:/var/lib/grafana grafana/grafana:lstest
安装Prometheus
docker run -d --restart always -p 9090:9090 --name=prometheus -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
安装Node-exporter
docker run -d --restart always -p 9100:9100 --name=node-exporter -v "/proc:/host/proc:ro" -v /etc/localtime:/etc/localtime -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" --net="host" prom/node-exporter
- 注:注意resatrt参数,根据需求确定是否使用。
linux主机监控
prometheus.yml
- job_name: 'jd-cloud'
metrics_path: "/metrics"
static_configs:
- targets: ['IP:9100','IP:9100']
labels:
instance: centos
Granfa官网选用监控模板
此处我选择11074模板,根据需求做一些函数的更改,这里我也不会。
java应用监控
1.在pom.xml中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.3</version>
</dependency>
<!-- 可选, 用于进程内存使用图表 -->
<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
<version>0.2.0</version>
</dependency>
2.修改spring boot配置(application.yml)
server:
port: 8080
spring:
application:
name: spring-demo
management:
endpoints:
web:
exposure:
include: 'prometheus' # 暴露/actuator/prometheus
metrics:
tags:
application: ${spring.application.name} # 暴露的数据中添加application label
3.Prometheus中采集数据
global:
scrape_interval: 15s
scrape_configs:
- job_name: "spring-demo"
metrics_path: "/actuator/prometheus"
static_configs:
- targets: ["localhost:8080"]
4.通过remote write 写入SLS的时序存储
5.Grafana中添加数据源
使用模板12856,看出来了嘛,这是[抄的](https://grafana.com/grafana/dashboards/12856)-_-