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

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. c语言实现双链表的基本操作—增删改查

    //初始化 Node*InitList() { Node*head=(Node*)malloc(sizeof(Node)); if(NULL==head) { printf("内存分配失败! ...

  2. pod和容器(容易混淆的地方)

    在Kubenetes中,所有的容器均在 pod 中运行,一个pod可以承载一个或者多个相关的docker容器(或rkt,以及用户自定义容器),同一个Pod中的容器可以部署在同一个物理机器(可以叫宿主机 ...

  3. for .. range中的坑

    最近在开发中使用了for range来遍历一个slice,结果在测试的时候遇到了bug,最后定位是错误使用for range造成的,这里记录一下: func redisSlaveScanBigKeys ...

  4. 新手小白入门C语言第三章:关于数据类型

    C 语言包含的数据类型 1.整型 整型分为整形常量和整形变量,常量就是我们平时所看到的准确的数字,例如:1.20.333等等,变量则按我的理解是我像内存去申请一个存储空间,告诉内存空间我申请了这个地方 ...

  5. 2021.08.05 P1738 洛谷的文件夹(树形结构)

    2021.08.05 P1738 洛谷的文件夹(树形结构) P1738 洛谷的文件夹 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 重点: 1.树!! 题意: 给出n个网页路径,求 ...

  6. 原生实现C#和Lua相互调用-Unity3D可用

    引言     本篇简单介绍如何在C#中执行Lua脚本,传递数据到Lua中使用,以及Lua中调用C#导出的方法等.在Unity中开发测试,并打IL2CPP的Android包在模拟器上运行通过.Lua版本 ...

  7. Android 蓝牙串口通信工具类 SerialPortUtil 3.0.+

    建议使用4.+版本,避免一些不必要的bug.4.+版本文档地址:https://www.cnblogs.com/shanya/articles/16062256.html SerialPortUtil ...

  8. k8s入门之Ingress(七)

    Ingress 的功能其实很容易理解:所谓 Ingress,就是 Service 的"Service",代理不同后端 Service 而设置的负载均衡服务. 一.安装ingress ...

  9. 02稀疏数组(java版本)

    1 package com.aixuexi.contact; 2 3 public class SpareArray { 4 public static void main(String[] args ...

  10. Bugku CTF练习题---MISC---telnet

    Bugku CTF练习题---MISC---telnet flag:flag{d316759c281bf925d600be698a4973d5} 解题步骤: 1.观察题目,下载附件 2.拿到手以后发现 ...