docker安装grafana,prometheus,exporter以及springboot整合详细教程(GPE)

springboot项目ip:192.168.168.1

测试服务器ip:192.168.168.81

文章来自互联网,自己略微整理下,更容易上手,方便自己,方便大家

最终效果:

node

springboot

1.下载镜像

docker pull prom/node-exporter

docker pull prom/mysqld-exporter

docker pull google/cadvisor

docker pull prom/prometheus

docker pull grafana/grafana

2.启动

2.1node-exporter

docker run -d -p 19100:9100 \
  -v /proc:/host/proc:ro \
  -v /sys:/host/sys:ro \
  -v /:/rootfs:ro \
  prom/node-exporter

访问url:

http://192.168.168.81:19100/metrics

2.2启动mysqld-exporter:

docker run -d --name mysqld_exporter -p 19104:9104 -e DATA_SOURCE_NAME="数据库用户:数据库密码@(数据库ip:端口)/" prom/mysqld-exporter

ps:经过测试需要指定版本,最新的版本不识别配置

指定版本

Swift 复制代码
docker run -d --name mysqld_exporter \
-p 19104:9104 \
-e DATA_SOURCE_NAME="root:123456@(192.168.168.81:3306)/" \
prom/mysqld-exporter:v0.14.0

访问url:

http://192.168.168.81:19104/metrics

2.3启动cadvisor

docker run -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker/:/var/lib/docker:ro -v /dev/disk/:/dev/disk:ro -p 18080:8080 -d --name=cadvisor --restart=always google/cadvisor:latest

访问url:

http://127.0.0.1:18080/metrics

2.4启动prometheus

新建prometheus目录,并编辑prometheus.yml文件

mkdir  -p /opt/prometheus/data
cd /opt/prometheus/data
vim prometheus.yml

配置如下内容:

global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: [192.168.168.81:19090']
        labels:
          instance: prometheus

  - job_name: node
    static_configs:
      - targets: ['192.168.168.81:19100']
        labels:
          instance: node

  - job_name: cadvisor
    static_configs:
      - targets: ['192.168.168.81:18080']
        labels:
          instance: cadvisor

  - job_name: mysqld
    static_configs:
      - targets: ['192.168.168.81:19104']
        labels:
          instance: mysqld

  - job_name: springboot-prometheus
    metrics_path: '/actuator/springboot-prometheus/prometheus'
    static_configs:
      - targets: ['192.168.168.1:8080']
        labels:
          instance: springboot-prometheus

启动prometheus:

sudo docker run -d -p 19090:9090 --name prom -v /usr/local/prometheus/data:/data  prom/prometheus --config.file=/data/prometheus.yml

访问url:

http://192.168.168.81:19090/

2.5、启动grafana

创建文件夹并设置权限:
mkdir /opt/grafana-storage
chmod 777 -R /opt/grafana-storage

启动grafana:

  docker run -d \
  -p 13000:3000 \
  --name=grafana \
  -v /opt/grafana-storage:/var/lib/grafana \
  grafana/grafana

3.使用

访问url:

http://192.168.168.81:13000/

账号:admin/admin

跳转到登录页面后,默认的用户名和密码都是admin,第一次登陆可重置密码后进去首页

设置data source:

点击Save & Test按钮,出现绿色提示,说明配置成功

3.1、docker模板

搜索导入193模板

3.2、springboot模板

搜索导入4701/6756模板

3.3、主机监控

搜索导入9276/8919模板

3.4、mysql模板

搜索导入7362模板

4、springboot 集成prometheus

4.1、引入依赖

在spring boot工程中引入actuator以及micrometer-registry-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>

4.3、配置文件

暴露prometheus的接口,暴露metrics.tags,和spring.application.name一致

spring:
  application:
    name: springboot-prometheus
management:
  endpoints:
    web:
      exposure:
        include: 'prometheus'
      base-path: /actuator/${spring.application.name}
  metrics:
    tags:
      application: ${spring.application.name}

项目指标访问地址是:192.168.168.1:8080/actuator/springboot-prometheus/prometheus

这个路径是项目路径+"management.endpoints.web.exposure.base-path"+prometheus

相关推荐
福大大架构师每日一题14 小时前
37.1 prometheus管理接口源码讲解
ios·iphone·prometheus
Cairry.1 天前
WatchAlert - 开源多数据源告警引擎
云原生·开源·prometheus
Mitch3111 天前
【漏洞复现】CVE-2023-37461 Arbitrary File Writing
web安全·网络安全·prometheus·metersphere·漏洞复现
福大大架构师每日一题4 天前
36.3 grafana-dashboard看图分析
linux·网络·grafana·prometheus
福大大架构师每日一题4 天前
36.2 内置的k8s采集任务分析
算法·贪心算法·kubernetes·prometheus
点燃银河尽头的篝火(●'◡'●)5 天前
【环境搭建】Grafana本地部署搭建(windows系统)
windows·grafana·环境搭建
Algorithm15765 天前
linux/ubuntu安装Prometheus&Grafana
linux·ubuntu·prometheus
福大大架构师每日一题9 天前
35.4 thanos-query 源码阅读
java·spring·ios·prometheus
福大大架构师每日一题9 天前
35.3 thanos-store 源码阅读
ios·iphone·prometheus
童安格粉丝10 天前
Grafana配置告警规则推送企微机器人服务器资源告警
机器人·企业微信·grafana·告警·dashboard·阈值