DevOpsIT技术篇

【4.7】服务器安装 Docker Swarm中搭建 系统监控

2021-08-10  本文已影响0人  王滕辉

参考
https://www.cnblogs.com/wx170119/p/12418835.html
https://blog.csdn.net/qq_29635485/article/details/103337840
https://www.itmuch.com/spring-boot/actuator-prometheus-grafana/
https://grafana.com/grafana/dashboards/12856

1. 搭建Prometheus

docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana

mkdir -p /home/promethes/node/proc
mkdir -p /home/promethes/node/sys

docker run -d -p 9100:9100 \
  -v "/home/promethes/node/proc:/host/proc:ro" \
  -v "/home/promethes/node/sys:/host/sys:ro" \
  -v "/home/promethes/node/:/rootfs:ro" \
  --net="host" \
  prom/node-exporter


http://192.168.0.105:9100/metrics

image.png
mkdir /home/promethes/prometheus
cd /home/promethes/prometheus
vim prometheus.yml
global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9190']
        labels:
          instance: prometheus
 
  - job_name: linux
    static_configs:
      - targets: ['192.168.0.105:9100']
        labels:
          instance: localhost
docker run  -d \
  -p 9190:9190 \
  -v /home/promethes/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
  prom/prometheus

http://192.168.0.105:9190/graph

image.png
http://192.168.0.105:9190/targets image.png

2启动grafana

mkdir /home/promethes/grafana
chmod 777 -R /home/promethes/grafana

docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -v /home/promethes/grafana:/var/lib/grafana \
  grafana/grafana

访问: http://192.168.0.105:3000

image.png image.png image.png image.png
image.png
image.png
查看
https://grafana.com/grafana/dashboards

找到合适的模板


image.png image.png image.png image.png

3 SpringBoot应用集成Prometheus

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 可选, 用于进程内存使用图表 -->
<dependency>
  <groupId>io.github.mweirauch</groupId>
    <artifactId>micrometer-jvm-extras</artifactId>
    <version>0.2.0</version>
 </dependency>

修改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

添加配置
vim prometheus.yml

 - job_name: "spring-demo"
    metrics_path: "/actuator/prometheus"
    static_configs:
    - targets: ["localhost:8080"]

重启Prometheus

Grafana配置数据源
添加看板 12856
https://grafana.com/grafana/dashboards/12856

image.png

点波关注 系统搭建(docker)

上一篇下一篇

猜你喜欢

热点阅读