【监控】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的使用。

相关推荐
qq_2975746714 小时前
【实战教程】SpringBoot 实现多文件批量下载并打包为 ZIP 压缩包
java·spring boot·后端
tb_first17 小时前
LangChain4j简单入门
java·spring boot·langchain4j
计算机学姐21 小时前
基于SpringBoot的民宿预定管理系统【三角色+个性化推荐算法+数据可视化统计】
java·vue.js·spring boot·mysql·信息可视化·intellij-idea·推荐算法
计算机程序设计小李同学1 天前
基于 Spring Boot + Vue 的龙虾专营店管理系统的设计与实现
java·spring boot·后端·spring·vue
LiZhen7981 天前
SpringBoot 实现动态切换数据源
java·spring boot·mybatis
qq_12498707531 天前
基于Java Web的城市花园小区维修管理系统的设计与实现(源码+论文+部署+安装)
java·开发语言·前端·spring boot·spring·毕业设计·计算机毕业设计
VX:Fegn08951 天前
计算机毕业设计|基于springboot + vue云租车平台系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
Chasmれ1 天前
Spring Boot 1.x(基于Spring 4)中使用Java 8实现Token
java·spring boot·spring
汤姆yu1 天前
2026基于springboot的在线招聘系统
java·spring boot·后端
计算机学姐1 天前
基于SpringBoot的校园社团管理系统
java·vue.js·spring boot·后端·spring·信息可视化·推荐算法