栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Docker运行Prometheus(普罗米修斯),grafana,springboot整合

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker运行Prometheus(普罗米修斯),grafana,springboot整合

1.编辑yaml格式,进行自我监控
# mkdir /etc/prometheus
# cd /etc/prometheus/
 
# vi /etc/prometheus/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:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['127.0.0.1:9090']
###以下内容为SpringBoot应用配置
  - job_name: 'api'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['172.16.168.105:8080']

2.运行Docker的prometheus(普罗米修斯)容器
docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
3.打开浏览器 ,输入ip:9090

2. docker安装grafana

参考:https://www.cnblogs.com/xiao987334176/p/9930517.html
新建空文件夹grafana-storage,用来存储数据

mkdir /opt/grafana-storage

设置权限

chmod 777 -R /opt/grafana-storage

启动grafana

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

默认会先跳转到登录页面,默认的用户名和密码都是admin

// TODO 基本操作!!!

监控项目jvm

参考:https://blog.csdn.net/weixin_34240520/article/details/92074929
第一步:
mvn的pom.xml引入actuator、prometheus、micrometer


    org.springframework.boot
    spring-boot-starter-actuator



    io.micrometer
    micrometer-registry-prometheus
    1.0.6



    io.github.mweirauch
    micrometer-jvm-extras
    0.1.2

第二步:
在application.properties配置中,添加prometheus相关配置

# 暴露监控端点
management:
  #prometheus+grafana+springboot2监控集成配置
  endpoints:
    web:
      exposure:
        include: '*'
    prometheus:
      enabled: true
  metrics:
    export:
      prometheus:
        enabled: true
        step: 1ms
        descriptions: true
    tags:
      application: ${spring.profiles}-${spring.application.name}
  #prometheus+grafana+springboot2监控集成配置

第三步:

修改prometheus.yml,添加job添加下面代码,其中xxx替换为项目启动路径。
然后再启动prometheus,访问http://localhost:9090,查看targets启动是否正常如下图

# 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:
#  - job_name: 'prometheus'
#    static_configs:
#    - targets: ['127.0.0.1:9090']
###以下内容为SpringBoot应用配置
  - job_name: 'uat-api'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['172.16.168.105:8080']


第四步: 安装Grafana,默认启动后Grafana地址为:http://localhost:3000/,登录用户名和密码是admin/admin,配置prometheus为database如下图一所示,import配置grafana id = 4701jvm使用情况面板如图





配置数据源:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/762745.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号