码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • SpringBoot2.x整合Prometheus+Grafana【附源码+视频】


    图文并茂,新手入门教程,建议收藏

    SpringBoot2.x整合Prometheus+Grafana【附源码+视频】

    附源码+视频

    目录
    • 工程简介
      • 简介
        • Prometheus
        • grafana
      • SpringBoot工程初始化
      • 环境安装
        • Prometheus安装
        • Grafana安装
      • 整合
    • 延伸阅读
      • 中级篇
      • 实战篇

    工程简介

    总体框架图

    image

    简介

    Prometheus

    Prometheus,是一个开源的系统监控和告警的工具包,其采用Pull方式采集时间序列的度量数据(也支持push方式),通过Http协议传输。它的工作方式是被监控的服务需要公开一个Prometheus端点,这端点是一个HTTP接口,该接口公开了度量的列表和当前的值,然后Prometheus应用从此接口定时拉取数据,一般可以存放在时序数据库中,然后通过可视化的Dashboard(e.g.Grafana)进行数据展示。

    支持的prometheus metrics

    Counter,Gauge,Histogram,Summary,untyped等等。需要注意的是counter只能增不能减,适用于服务请求量,用户访问数等统计,但是如果需要统计有增有减的指标需要用Gauge。

    exporter

    支持的 exporter 很多,可以方便的监控很多应用,同时也可以自定义开发非官方提供的exporter。

    grafana

    grafana,是一个开源的dashboard展示工具,可以支持很多主流数据源,包括时序性的和非时序性的。其提供的展示配置以及可扩展性能满足绝大部分时间序列数据展示需求,是一个比较优秀的工具。

    支持的数据源

    prometheus,inflexdb,elasticsearch,mysql,postgreSQL,openTSDB等,更多数据源:https://grafana.com/grafana/plugins/?type=datasource


    SpringBoot工程初始化

    springboot加速初始化:https://start.aliyun.com/

    image

    添加依赖

    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>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

    配置信息

    在application.yml增加以下配置项

    
    ##SpringBoot2.x整合Prometheus+Grafana
    ##源码:https://github.com/Rodert/SpringBoot-javapub
    management:
      metrics:
        export:
          prometheus:
            enabled: true
            step: 1m
            descriptions: true
      web:
        server:
          auto-time-requests: true
      endpoints:
        prometheus:
          id: springmetrics
        web:
          exposure:
            include: health,info,env,prometheus,metrics,httptrace,threaddump,heapdump,springmetrics
    server:
      port: 8080
    
    

    启动SpringBoot应用

    http://localhost:8080/actuator/prometheus

    打开即可看到暴露的信息

    image

    环境安装

    如安装包下载不成功,可以在公众号回复【prometheus安装包】or【grafana安装包】领取

    Prometheus安装

    下载地址:https://prometheus.io/download/

    image

    修改配置:

    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'.
        #暴露路径
        metrics_path: /actuator/prometheus
        static_configs:
        #SpringBoot的ip和端口号
        - targets: ['localhost:8080']

    启动Prometheus

    prometheus.exe

    image

    测试访问

    http://localhost:9090

    image

    jvm_memory_used_bytes

    image

    Grafana安装

    下载地址:https://mirrors.huaweicloud.com/grafana/

    image

    启动grafana

    image

    测试

    http://127.0.0.1:3000/login

    image

    默认账号:admin 密码:admin

    image

    整合

    增加数据源

    image

    image

    • Name填一个
    • URL填的Prometheus访问地址

    image

    添加图表

    image

    image

    指定数据源、指定监控指标 jvm_memory_used_bytes

    image

    切换图标

    image

    image


    源码地址:https://github.com/Rodert/spring-boot-prometheus-grafana

    视频地址:https://space.bilibili.com/404747369

    延伸阅读

    1. SpringBoot自定义注解
    2. SpringBoot整合docker入门
    3. SpringBoot整合ElasticSearch
    4. SpringBoot快速整合Excel
    5. SpringBoot整合MyBatis-支持批量更新
    6. SpringBoot实现链路追踪spring-boot-trace
    7. SpringBoot2.x整合Prometheus+Grafana【附源码】

    中级篇

    1. 手把手整合SSM-Spring-Spring MVC-Mybatis

    实战篇

    1. 通用后台管理系统

    将支持:Activiti + Flowable 工作流; 第三方登录; 支付; 短信; 支持 RBAC 动态权限、数据权限;监接;商城。SpringBoot Spring Security JWT MyBatis Druid Vue Vuex Element-ui Axios Sass Quill docker-compose、Kafka


    __EOF__

    本文作者:JavaPub
    本文链接:https://www.cnblogs.com/JavaPub/p/16377947.html
    关于博主:评论和私信会在第一时间回复。或者直接私信我。
    版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
    声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
  • 相关阅读:
    Mac pt-online-schema-change 图文并茂、不锁表在线修改 MySQL 表结构
    『华强买瓜』奇袭好莱坞!Jupyter也能创建可交互仪表板啦!超全面的英语论文写作套路;神经辐射场NeRF工具包;前沿论文 | ShowMeAI资讯日报
    python的小作业
    Java基于SpringBoot的藏区特产销售系统的研究与实现
    Spring框架两大核心模块(8月5号)
    python自动合成图片为gif,并能根据第一张图片自动统一图片尺寸
    【Sklearn学习】Sklearn的数据集介绍
    ​Chrome插件:Postman Interceptor 调试的终极利器
    【深度学习基础】专业术语汇总(欠拟合和过拟合、泛化能力与迁移学习、调参和超参数、训练集、测试集和验证集)
    C语言,编写程序输出半径为1到15的圆的面积,若面积在30到100之间则予以输出,否则,不予输出
  • 原文地址:https://www.cnblogs.com/JavaPub/p/16377947.html
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号