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

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

附源码+视频

工程简介

总体框架图

简介

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/

添加依赖

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

打开即可看到暴露的信息

环境安装

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

Prometheus安装

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

修改配置

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

测试访问

http://localhost:9090

jvm_memory_used_bytes

Grafana安装

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

启动grafana

测试

http://127.0.0.1:3000/login

默认账号:admin 密码:admin

整合

增加数据源

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

添加图表

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

切换图标


源码地址: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

SpringBoot2.x整合Prometheus+Grafana【附源码+视频】的更多相关文章

  1. Springboot与Thymeleaf模板引擎整合基础教程(附源码)

    前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...

  2. Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)

    前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...

  3. PYTHON爬虫实战_垃圾佬闲鱼爬虫转转爬虫数据整合自用二手急速响应捡垃圾平台_3(附源码持续更新)

    说明 文章首发于HURUWO的博客小站,本平台做同步备份发布. 如有浏览或访问异常图片加载失败或者相关疑问可前往原博客下评论浏览. 原文链接 PYTHON爬虫实战_垃圾佬闲鱼爬虫转转爬虫数据整合自用二 ...

  4. SSM 三大框架系列:Spring 5 + Spring MVC 5 + MyBatis 3.5 整合(附源码)

    之前整理了一下新版本的 SSM 三大框架,这篇文章是关于它的整合过程和项目源码,版本号分别为:Spring 5.2.2.RELEASE.SpringMVC 5.2.2.RELEASE.MyBatis ...

  5. 日志组件Log2Net的介绍和使用(附源码开源地址)

    Log2Net是一个用于收集日志到数据库或文件的组件,支持.NET和.NetCore平台. 此组件自动收集系统的运行日志(服务器运行情况.在线人数等).异常日志.程序员还可以添加自定义日志. 该组件支 ...

  6. 在网站开发中很有用的8个 jQuery 效果【附源码】

    jQuery 作为最优秀 JavaScript 库之一,改变了很多人编写 JavaScript 的方式.它简化了 HTML 文档遍历,事件处理,动画和 Ajax 交互,而且有成千上万的成熟 jQuer ...

  7. Web 开发中很实用的10个效果【附源码下载】

    在工作中,我们可能会用到各种交互效果.而这些效果在平常翻看文章的时候碰到很多,但是一时半会又想不起来在哪,所以养成知识整理的习惯是很有必要的.这篇文章给大家推荐10个在 Web 开发中很有用的效果,记 ...

  8. MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码)

    前言:上篇介绍了下 MVC5 的核心原理,整篇文章比较偏理论,所以相对比较枯燥.今天就来根据上篇的理论一步一步进行实践,通过自己写的一个简易MVC框架逐步理解,相信通过这一篇的实践,你会对MVC有一个 ...

  9. C#进阶系列——一步一步封装自己的HtmlHelper组件:BootstrapHelper(三:附源码)

    前言:之前的两篇封装了一些基础的表单组件,这篇继续来封装几个基于bootstrap的其他组件.和上篇不同的是,这篇的有几个组件需要某些js文件的支持. 本文原创地址:http://www.cnblog ...

随机推荐

  1. 一. 为什么要用SpringMVC框架

    以前是怎么做项目的.CoreServlet,起到一个中心处理器作用.所有的请求到服务器,服务器给CoreServlet,在里面处理所有表的增删改查,跳转也在里面做.以前做部门就是 DepServlet ...

  2. python---二分查找的实现

    from cal_time import get_running_time @get_running_time def bin_search(li, val): """ ...

  3. 在Blazor中实现拖放(drag and drop)

    前言 我在实现一个含有待办列表功能的页面时,发现了一个好看的设计,它将待办分为--"待办","正在进行",和"已完成"三种状态,并且将待办通 ...

  4. Quartz 使用记录

    Quartz 使用记录 官网 https://www.quartz-scheduler.org/ 参考文档 Quartz 2.3.0 什么是 Quartz? 官方描述: Quartz is a ric ...

  5. Markdown练习

    这是一级标题 这是二级标题 这是三级标题 这是无序列表1 这是无序列表2 有序1 有序2 重点 计网 1. 第一章 第一部分 1.概念.组成.功能和分类 1. 概念 计算机网络是互连的.自治的计算机的 ...

  6. MySQL启动过程详解三:Innodb存储引擎的启动

    Innodb启动过程如下: 1. 初始化innobase_hton,它是一个handlerton类型的指针,以便在server层能够调用存储引擎的接口. 2. Innodb相关参数的检车和初始化,包括 ...

  7. 原生js 复选框全选案例

    注 : 本文章主要写功能 代码示例 : <body> <input type="checkbox" id="che" /><br& ...

  8. 基于Vue的v-charts导出图片并下载

    依赖 npm install file-saver 页面 <ve-chart ref="chart"></ve-chart> <el-button t ...

  9. macOS 安装 Nebula Graph 看这篇就够了

    本文首发于 Nebula Graph Community 公众号 背景 刚学习图数据的内容,当前网上充斥大量的安装文档,参差不齐,部署起来令人十分头疼. 现整理一份比较完整的安装文档,供大家学习参考, ...

  10. js 前端实现下拉刷新 上拉加载

    效果 css html,body{ height:100%; // 其他界面未设置html 无法监听scroll } /* 下拉刷新 */ .refresh-loading { transition: ...