广告
返回顶部
首页 > 资讯 > 精选 >SpringBoot如何使用prometheus监控
  • 873
分享到

SpringBoot如何使用prometheus监控

2023-06-14 05:06:30 873人浏览 安东尼
摘要

这篇文章主要介绍SpringBoot如何使用prometheus监控,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.关于PrometheusPrometheus是一个根据应用的metrics来进行监控的开源工具。相

这篇文章主要介绍SpringBoot如何使用prometheus监控,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1.关于Prometheus

Prometheus是一个根据应用的metrics来进行监控的开源工具。相信很多工程都在使用它来进行监控,有关详细介绍可以查看官网:https://prometheus.io/docs/introduction/overview/。

2.有关Grafana

Grafana是一个开源监控利器,如图所示。

SpringBoot如何使用prometheus监控

从图中就可以看出来,使用Grafana监控很高大上,提供了很多可视化的图标。

官网地址:Https://grafana.com/

3.springBoot使用Prometheus

3.1 依赖内容

在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>

3.2 配置文件

配置文件中加入配置,这里就只进行一些简单配置,management.metrics.tags.application属性是本文配合Grafana的Dashboard设置的,如下所示:

spring.application.name=springboot_prometheusmanagement.endpoints.web.exposure.include=*management.metrics.tags.application=${spring.application.name}

3.3 设置application

修改启动类,如下所示.

@SpringBootApplicationpublic class Springboot2PrometheusApplication {public static void main(String[] args) {SpringApplication.run(Springboot2PrometheusApplication.class, args);}@BeanMeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {return (registry) -> registry.config().commonTags("application", applicationName);}}

SpringBoot项目到这里就配置完成了,启动项目,访问http://localhost:8080/actuator/prometheus,如图所示,可以看到一些度量指标。

SpringBoot如何使用prometheus监控

4.Prometheus配置

4.1 配置应用

在prometheus配置监控我们的SpringBoot应用,完整配置如下所示。

# my global configglobal: 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 configurationalerting: 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']

4.2 启动Prometheus

启动Prometheus,浏览器访问,查看Prometheus页面,如图所示。

SpringBoot如何使用prometheus监控

点击如图所示位置,可以查看Prometheus监控的应用。

SpringBoot如何使用prometheus监控

列表中UP的页面为存活的实例,如图所示。

SpringBoot如何使用prometheus监控

也可以查看很多指数,如下所示。

SpringBoot如何使用prometheus监控

5.Grafana配置

启动Grafana,配置Prometheus数据源,这里以ID是4701的Doshboard为例(地址:https://grafana.com/dashboards/4701)如图。

SpringBoot如何使用prometheus监控

在Grafana内点击如图所示import按钮

SpringBoot如何使用prometheus监控

在如图所示位置填写4701,然后点击load。

SpringBoot如何使用prometheus监控

接下来导入Doshboard。

SpringBoot如何使用prometheus监控

导入后就可以看到我们的SpringBoot项目对应的指标图表了,如图。

SpringBoot如何使用prometheus监控

以上是“SpringBoot如何使用prometheus监控”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网精选频道!

--结束END--

本文标题: SpringBoot如何使用prometheus监控

本文链接: https://www.lsjlt.com/news/268230.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • SpringBoot如何使用prometheus监控
    这篇文章主要介绍SpringBoot如何使用prometheus监控,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.关于PrometheusPrometheus是一个根据应用的metrics来进行监控的开源工具。相...
    99+
    2023-06-14
  • Prometheus如何监控Springboot程序
    这篇文章主要介绍Prometheus如何监控Springboot程序,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1. 添加依赖我本次使用的Springboot版本为1.5.12.RELEASE,如果是Springb...
    99+
    2023-06-14
  • SpringBoot使用prometheus监控的示例代码
    目录1.关于Prometheus2.有关Grafana3.SpringBoot使用Prometheus3.1 依赖内容3.2 配置文件3.3 设置application4.Prome...
    99+
    2022-11-11
  • 使用Prometheus+Grafana监控JVM
    JMX Exporterhttps://github.com/prometheus/jmx_exporter它是Prometheus官方组件,作为一个JAVA Agent来提供本地JVM的metrics,并通过http暴露出来。这也是官方推...
    99+
    2023-01-31
    Prometheus Grafana JVM
  • prometheus+grafana如何监控nginx
    这篇文章主要介绍prometheus+grafana如何监控nginx,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!在prometheus需要向ngxin中打入探针,通过探针获取ngxin信息,并通过接口输出。下文将...
    99+
    2023-06-21
  • Prometheus监控Springboot程序的实现方法
    目录1. 添加依赖2. 修改配置文件3. 启用Prometheus监控4. 监控埋点4.1 新建拦截器4.2 注册拦截器5. 验证监控6. 指标类型6.1 Counter6.2 Ga...
    99+
    2022-11-11
  • Prometheus监控PHP应用
    文章目录 1、配置PHP-FPM,暴露php-fpm状态信息2、bakins/php-fpm-exporter监控PHP应用2.1、配置php状态页的http访问2.2、下载bakins/ph...
    99+
    2023-08-31
    php prometheus 服务器
  • Prometheus 监控MySQL使用grafana展示
    目录prometheus通过exporter监控mysql,并用grafana图表展示1、测试机器 2、配置mysql host013、创建exporter帐号4、下载,安...
    99+
    2022-11-12
  • Grafana+Prometheus如何监控MySql服务
    这篇文章主要为大家展示了“Grafana+Prometheus如何监控MySql服务”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Grafana+Prometh...
    99+
    2022-10-18
  • 利用Prometheus和Grafana监控MySQL
     一、 Prometheus 是一个开源的服务监控系统和时间序列数据库。:官方GitHub地址为:https://github.com/prometheus/prometheus 官方地...
    99+
    2022-10-18
  • 如何使用Prometheus监控Linux系统各项指标
    这篇文章主要讲解了“如何使用Prometheus监控Linux系统各项指标”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用Prometheus监控Linux系统各项指标”吧!首先在Li...
    99+
    2023-06-05
  • python如何获取Prometheus监控数据
    目录获取Prometheus监控数据获取Prometheus target数据获取Prometheus 监控信息(cpu、mem、disks)通过promsql读取prometheu...
    99+
    2022-11-11
  • 如何自定义Prometheus监控指标
    本篇内容介绍了“如何自定义Prometheus监控指标”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!目前大部分使用Spring  ...
    99+
    2023-06-17
  • 使用Grafana+Prometheus监控mysql服务性能
    Prometheus(也叫普罗米修斯)官网:https://prometheus.io/docs/introduction/overview/ Grafana官网:https://grafana.com/e...
    99+
    2022-10-18
  • CentOS7如何搭建Prometheus监控Linux主机
    这期内容当中小编将会给大家带来有关CentOS7如何搭建Prometheus监控Linux主机,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。 简介prometheus可以拆分成多个节点进行指标收...
    99+
    2023-06-15
  • Python如何调用Prometheus监控数据并计算
    小编给大家分享一下Python如何调用Prometheus监控数据并计算,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Prometheus是什么Prometheu...
    99+
    2023-06-22
  • Grafana + Prometheus如何快速搭建监控平台
    小编给大家分享一下Grafana + Prometheus如何快速搭建监控平台,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!总体可视化方案Grafana:通过将采...
    99+
    2023-06-15
  • Python调用Prometheus监控数据并计算
    目录Prometheus是什么Prometheus基础概念什么是时间序列数据什么是targets(目标)什么是metrics(指标)什么是PromQL(函数式查询语言)如何监控远程L...
    99+
    2022-11-12
  • 超级实用,解密云原生监控技术,使用prometheus轻松搞定redis监控
    前言 大家好,我是沐风晓月,本文收录于《 prometheus监控系列》 ,截止目前prometheus专栏已经更新到第8篇文章。 本文中的是prometheus已经安装好,如果你还未安装,可以参考 prometheus安装及使用入门 若...
    99+
    2023-08-18
    云原生 运维 服务器 linux 原力计划
  • prometheus监控节点程序如何安装及卸载
    这篇文章主要介绍“prometheus监控节点程序如何安装及卸载”,在日常操作中,相信很多人在prometheus监控节点程序如何安装及卸载问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”prometheus监...
    99+
    2023-07-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作