技术标签: SpringBoot springboot
本文介绍SpringBoot如何使用Prometheus配合Grafana监控。
Prometheus是一个根据应用的metrics来进行监控的开源工具。相信很多工程都在使用它来进行监控,有关详细介绍可以查看官网:https://prometheus.io/docs/introduction/overview/。
Grafana是一个开源监控利器,如图所示。
从图中就可以看出来,使用Grafana监控很高大上,提供了很多可视化的图标。
官网地址:https://grafana.com/
在SpringBoot中使用Prometheus其实很简单,不需要配置太多的东西,在pom文件中加入依赖,完整内容如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dalaoyang</groupId>
<artifactId>springboot2_prometheus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot2_prometheus</name>
<description>springboot2_prometheus</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置文件中加入配置,这里就只进行一些简单配置,management.metrics.tags.application属性是本文配合Grafana的Dashboard设置的,如下所示:
spring.application.name=springboot_prometheus
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}
修改启动类,如下所示.
@SpringBootApplication
public class Springboot2PrometheusApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot2PrometheusApplication.class, args);
}
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(
@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName);
}
}
SpringBoot项目到这里就配置完成了,启动项目,访问http://localhost:8080/actuator/prometheus,如图所示,可以看到一些度量指标。
在prometheus配置监控我们的SpringBoot应用,完整配置如下所示。
# 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:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9090']
###以下内容为SpringBoot应用配置
- job_name: 'springboot_prometheus'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['127.0.0.1:8080']
启动Prometheus,浏览器访问,查看Prometheus页面,如图所示。
点击如图所示位置,可以查看Prometheus监控的应用。
列表中UP的页面为存活的实例,如图所示。
也可以查看很多指数,如下所示。
启动Grafana,配置Prometheus数据源,这里以ID是4701的Doshboard为例(地址:https://grafana.com/dashboards/4701)如图。
在Grafana内点击如图所示import按钮
在如图所示位置填写4701,然后点击load。
接下来导入Doshboard。
导入后就可以看到我们的SpringBoot项目对应的指标图表了,如图。
源码地址:https://gitee.com/dalaoyang/springboot_learn/tree/master/springboot2_prometheus
文章浏览阅读6.7k次。一、Mysql启用SSL配置1.检查mysql是否支持ssl在linux端用root账号进入mysql命令行界面,查看当前版本mysql数据库是否支持ssl,如果出现以下结果表示支持,如果没有考虑更换版本,或者编译一个带有SSL版本的mysqlshell>show variables like ‘%ssl%’;2.设置用户是否使用ssl连接1.查看用户是否使用SSL连接she..._jdbc mysql ssl
文章浏览阅读612次。java jwt使用,springboot 整合java-jwt,java jwt工具类================================Copyright 蕃薯耀2020-12-03https://www.cnblogs.com/fanshuyao/一、引入java-jwt的maven依赖<dependency> <groupId>..._jwtproperties
文章浏览阅读753次,点赞21次,收藏15次。列出现有主题,创建主题,该主题包含一个分区,该分区为Leader分区,它没有Follower分区副本。启动成功,可以看到控制台输出的最后一行的started状态:此时kafka安装成功。查看zookeeper状态,zookeeper启动成功,再启动kafka。onsole-producer.sh用于生产消息**开启消费者和生产者,生产并消费消息。开启消费者和生产者,生产并消费消息。在Zookeeper中的根节点路径。创建主题,该主题包含多个分区。的地址,此处使用本地启动的。查看指定主题的详细信息。
文章浏览阅读695次。6-7 在一个数组中实现两个堆栈(20 分)本题要求在一个数组中实现两个堆栈。函数接口定义:Stack CreateStack( int MaxSize );bool Push( Stack S, ElementType X, int Tag );ElementType Pop( Stack S, int Tag );其中Tag是堆栈编号,取1或2;Max_pta数据结构6-7
文章浏览阅读123次。概述 您可能有大量应用程序产生的JSON数据,您可能需要对这些JSON数据进行整理,去除不想要的字段,或者只保留想要的字段,或者仅仅是进行数据查询。 那么,利用阿里云Data Lake Analytics或许是目前能找到的云上最为便捷的达到这一目标的服务了。仅仅需要3步,就可以完成对海量..._什么云服务可以直接存储json数据
文章浏览阅读413次。diff 算法 虚拟dom 理论_react diff 面试题
文章浏览阅读9.6k次,点赞11次,收藏89次。鼠标滚轮实现图像放大缩小的主要思想:通过wheelEvent来获得鼠标滚轮的angleDelta,即滚轮转角。然后通过数据类型转换,将读取的值转换成整型数值叠加到图像的尺寸长和宽上,从而实现图像的放大和缩小。注意:滚轮向上滑转角为正,所以图像放大。滚轮向下滑转角为负,所以图像缩小。下边直接上代码,头文件中只需要加上使用鼠标滚轮的声明函数就行:void wheelEvent(QWheelEve..._qt滚轮放大缩小
文章浏览阅读7.9w次,点赞53次,收藏235次。若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936本文章博客地址:https://blog.csdn.net/qq21497936/article/details/94585803目录前话相关博客QGLWidget概述QGLWidget子类示例更新绘制覆盖层绘制技术线程方案一:在线程中进..._qt 用qopenglwidget生成release版,依赖什么库
文章浏览阅读5.3k次。C 语言的浮点数类型_c语言float和double保留小数点后几位
文章浏览阅读3k次,点赞4次,收藏2次。gradle 打包时报以下错误:二、解决方法在 build.gradle 文件中找到 http://mirrors.huaweicloud.com/repository/maven/ 所在的位置,增加 allowInsecureProtocol = true 一行:_gradle using insecure protocols with repositories, without explicit opt-in,
文章浏览阅读7.3k次。微信群,请扫描二维码加入 本人在北京,主场北京,位置不限, 仅限java行业交流,C C##以及python请另外加群,谢谢欢迎准 java行业的进入,杜绝假冒程序员加入,精兵简政群内与java无关私事请私聊,任何java的问题,欢迎讨论——————————————————————————————————如若二维码失效,请加微信拉群..._java开发接单群
文章浏览阅读3.7k次,点赞2次,收藏43次。一、数据库系统概述数据库的四个基本概念:数据、数据库、数据库管理系统、数据库系统:1、数据:描述事物的符号记录称为数据。 (1)、数据是数据库中存储的基本对象。 (2)、数据是分类型的。 (3)、数据的含义称为数据的语义,数据与其语义是不可分的。 2、数据库:数据库是长期储存在计算机内、有组织的、可共享的大量数..._系统的数据管理逻辑