【监控】Spring Boot+Prometheus+Grafana实现可视化监控

目录

1.概述

[2.spring actuator](#2.spring actuator)

3.Prometheus

3.1.介绍

3.2.使用

1.client端的配置

2.server端的配置

4.grafana

5.留个尾巴


1.概述

本文是博主JAVA监控技术系列的第四篇,前面已经聊过了JMX、Spring actuator等技术,本文我们就将依托于Spring actuator+监控组件prometheus+数据可视化组件grafana来实现对Spring Boot应用的可视化监控。

关于Spring actuator的相关内容,可移步:

Spring Boot 监控_springboot 监控-CSDN博客

【监控】spring actuator源码速读-CSDN博客

2.spring actuator

Spring actuator是spring体系中自带的监控组件,用来监测应用本身以及所处环境等内容。前文已经详细介绍过了,自处就不再重复和展开了。

依赖:

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

配置:

management:

endpoints:

web:

exposure:

include: "*"

看一下效果:

以上这些指标都是actuator自带的,要适配Prometheus的数据采集格式的话需要引入promethus的适配层。ok,接下来我们讲一下Prometheus。

3.Prometheus

3.1.介绍

先看看整个prometheus的架构:

看起来很复杂对吧?其实并不复杂,最核心的就是Prometheus Server,其内置一个时序数据库,用来存采集上来的监控指标。然后就是Prometheus提供了很多client端,放在应用侧采集监控指标然后pull metrics(推送采集到的监控指标)个Prometheus Server。然后就是支持对接多种图形化界面如grafana来进行图形化的展示。最后就是支持各种方式的告警,如发送email等。

3.2.使用

1.client端的配置

即应用内的配置。

依赖:

复制代码
 <dependency>
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
   <scope>runtime</scope>
 </dependency>

配置:

management:

endpoints:

web:

exposure:

include: "*"

endpoint:

prometheus:

enabled: true

health:

show-details: always

可以看到promethus的监控指标已经出来了:

在主启动类里面,将应用的名字告诉Prometheus:

复制代码
@SpringBootApplication
public class Main {
 ?  public static void main(String[] args) {
 ? ? ?  SpringApplication.run(Main.class);
 ?  }
?
 ?  @Bean
 ?  MeterRegistryCustomizer<MeterRegistry> configure(@Value("${spring.application.name}") String applicationName){
 ? ? ?  return register -> {
 ? ? ? ? ?  register.config().commonTags("application", applicationName);
 ? ? ?  };
 ?  }
}

配置一下应用名:

spring:

application:

name: myApplicationDemo

2.server端的配置

先下载Prometheus,然后解压:

Download | Prometheus

配置Prometheus的prometheus.yml配置文件:

上面标红的要和应用对齐,否则会出现:

./prometheus启动Prometheus:

可以看到:

4.grafana

Grafana 是一个流行的开源数据可视化和监控工具,它提供了丰富的图表和仪表盘功能,用于展示和分析时间序列数据以及其他类型的数据。

官网下载地址:

Download Grafana | Grafana Labs

Linux的下载方式,官网上写的很清楚:

下载后解压即可使用。

./grafana-server启动应用,默认访问地址是IP:3000,默认账号密码都是admin。首次登录会要求修改密码。

登陆后,新建一个promethus的连接,配置好自己的promethus的地址和端口号保存即可:

在配置数据源的同时,可以选择grafana为我们准备的几套Prometheus的监控面板来使用:

我们选择其中一个,可以看到我们自己的应用了:

5.留个尾巴

ok,到这里聊完了吗?当然没有!

首先是如何自定义Prometheus的监控指标?其次grafana作为一款强大的数据可视化组件,功能当然很丰富,本文先讲解如何使用spring actuator+Prometheus+grafana实现基础的可视化监控,下文会详细介绍Prometheus和grafana的使用。

相关推荐
Coder_Boy_15 小时前
基于SpringAI的在线考试系统-相关技术栈(分布式场景下事件机制)
java·spring boot·分布式·ddd
韩立学长18 小时前
基于Springboot泉州旅游攻略平台d5h5zz02(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·旅游
摇滚侠18 小时前
在 SpringBoot 项目中,开发工具使用 IDEA,.idea 目录下的文件需要提交吗
java·spring boot·intellij-idea
打工的小王20 小时前
Spring Boot(三)Spring Boot整合SpringMVC
java·spring boot·后端
毕设源码-赖学姐20 小时前
【开题答辩全过程】以 高校体育场馆管理系统为例,包含答辩的问题和答案
java·spring boot
vx_Biye_Design20 小时前
【关注可免费领取源码】房屋出租系统的设计与实现--毕设附源码40805
java·spring boot·spring·spring cloud·servlet·eclipse·课程设计
翱翔-蓝天20 小时前
为什么“看起来很规范”的后端项目反而臃肿且性能下降
spring boot
80530单词突击赢21 小时前
JavaWeb进阶:SpringBoot核心与Bean管理
java·spring boot·后端
long3161 天前
Aho-Corasick 模式搜索算法
java·数据结构·spring boot·后端·算法·排序算法
独断万古他化1 天前
【SSM开发实战:博客系统】(三)核心业务功能开发与安全加密实现
spring boot·spring·mybatis·博客系统·加密