Prometheus 是一套开源的系统监控报警框架。它由工作在 SoundCloud 的 员工创建,并在 2015 年正式发布的开源项目。2016 年,Prometheus 正式加入 Cloud Native Computing Foundation,非常的受欢迎。

简介

Prometheus 具有以下特点:

一个多维数据模型,其中包含通过度量标准名称和键/值对标识的时间序列数据

PromQL,一种灵活的查询语言,可利用此维度

不依赖分布式存储; 单服务器节点是自治的

时间序列收集通过HTTP上的拉模型进行

通过中间网关支持推送时间序列

通过服务发现或静态配置发现目标

多种图形和仪表板支持模式

Prometheus 组成及架构

声明:该小节参考了文章[Prometheus 入门与实践]

Prometheus 生态圈中包含了多个组件,其中许多组件是可选的:

Prometheus Server: 用于收集和存储时间序列数据。

Client Library: 客户端库,为需要监控的服务生成相应的 metrics 并暴露给 Prometheus server。当 Prometheus server 来 pull 时,直接返回实时状态的 metrics。

Push Gateway: 主要用于短期的 jobs。由于这类 jobs 存在时间较短,可能在 Prometheus 来 pull 之前就消失了。为此,这次 jobs 可以直接向 Prometheus server 端推送它们的 metrics。这种方式主要用于服务层面的 metrics,对于机器层面的 metrices,需要使用 node exporter。

Exporters: 用于暴露已有的第三方服务的 metrics 给 Prometheus。

Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去除重复数据,分组,并路由到对收的接受方式,发出报警。常见的接收方式有:电子邮件,pagerduty,OpsGenie, webhook 等。

一些其他的工具。

其大概的工作流程是:

1.Prometheus server 定期从配置好的 jobs 或者 exporters 中拉 metrics,或者接收来自 Pushgateway 发过来的 metrics,或者从其他的 Prometheus server 中拉 metrics。

2.Prometheus server 在本地存储收集到的 metrics,并运行已定义好的 alert.rules,记录新的时间序列或者向 Alertmanager 推送警报。

3.Alertmanager 根据配置文件,对接收到的警报进行处理,发出告警。

4.在图形界面中,可视化采集数据。

springboot 集成prometheus

在spring boot工程中引入actuator的起步依赖,以及micrometer-registry-prometheus的依赖。

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-actuator

io.micrometer

micrometer-registry-prometheus

暴露prometheus的接口;暴露metrics.tags,和spring.application.name一致。

server:

port: 8081

spring:

application:

name: my-prometheus

management:

endpoints:

web:

exposure:

include: 'prometheus'

metrics:

tags:

application: ${spring.application.name}

写一个API接口,用作测试。代码如下:

@RestController

public class TestController {

Logger logger = LoggerFactory.getLogger(TestController.class);

@GetMapping("/test")

public String test() {

logger.info("test");

return "ok";

}

@GetMapping("")

public String home() {

logger.info("home");

return "ok";

}

}

在浏览器上访问http://localhost:8081/actuator/prometheus,展示的信息如下,这些信息都是actuator的一些监控信息。

# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool

# TYPE jvm_gc_max_data_size_bytes gauge

jvm_gc_max_data_size_bytes{application="my-prometheus",} 2.863661056E9

# HELP http_server_requests_seconds

# TYPE http_server_requests_seconds summary

http_server_requests_seconds_count{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 1.0

http_server_requests_seconds_sum{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327

# HELP http_server_requests_seconds_max

# TYPE http_server_requests_seconds_max gauge

http_server_requests_seconds_max{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327

# HELP jvm_threads_states_threads The current number of threads having NEW state

# TYPE jvm_threads_states_threads gauge

jvm_threads_states_threads{application="my-prometheus",state="waiting",} 12.0

jvm_threads_states_threads{application="my-prometheus",state="runnable",} 8.0

jvm_threads_states_threads{application="my-prometheus",state="timed-waiting",} 2.0

jvm_threads_states_threads{application="my-prometheus",state="terminated",} 0.0

jvm_threads_states_threads{application="my-prometheus",state="blocked",} 0.0

jvm_threads_states_threads{application="my-prometheus",state="new",} 0.0

# HELP process_files_open_files The open file descriptor count

# TYPE process_files_open_files gauge

...省略更多

安装Prometheus

安装Prometheus很简单,在linux系统上安装,执行以下的安装命令。其他的操作系统,比如windows、mac等在官网上(https://prometheus.io/download/)下载并安装。

wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.darwin-amd64.tar.gz

tar xvfz prometheus-*.tar.gz

cd prometheus-*

修改Prometheus的配置文件prometheus.yml,代码如下:

global:

scrape_interval: 15s # By default, scrape targets every 15 seconds.

# Attach these labels to any time series or alerts when communicating with

# external systems (federation, remote storage, Alertmanager).

external_labels:

monitor: 'codelab-monitor'

# 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=` to any timeseries scraped from this config.

- job_name: 'prometheus'

# Override the global default and scrape targets from this job every 5 seconds.

scrape_interval: 5s

static_configs:

- targets: ['localhost:9090']

- job_name: 'springboot_prometheus'

scrape_interval: 5s

metrics_path: '/actuator/prometheus'

static_configs:

- targets: ['127.0.0.1:8081']

config.job_name,配置job的名称

config.scrape_interval,配置多久抓一次监控信息

config.metrics_path,获取监控信息的接口

config.static_configs.targets配置获取监控信息的地址。

使用以下的命令启动prometheus,并通过–config.file指定配置文件

./prometheus --config.file=prometheus.yml

多次请求springboot项目的接口http://localhost:8081/test , 并访问prometheus的控制台http://localhost:9090/,展示的界面如下:

prometheus提供了一些可视化图,比如使用柱状图来展示每秒请求数:

安装grafana

grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数据库。使用grafana去展示prometheus上的数据。先安装,安装命令如下:

wget https://dl.grafana.com/oss/release/grafana-7.0.4.darwin-amd64.tar.gz

tar -zxvf grafana-7.0.4.darwin-amd64.tar.gz

./grafana-server

访问http://localhost:3000/,初始密码:admin/admin。

配置数据源,如图:

配置prometheus的地址:http://localhost:9090 ,如图所示:

在dashboard界面新建panel,展示的metrics为http_server_request_seconds_count,即展示了以时间为横轴,请求数为纵轴的请求曲线,如图所示:

参考资料

[Prometheus 入门与实践]

到此这篇关于springboot集成普罗米修斯(Prometheus)的方法的文章就介绍到这了,更多相关springboot集成普罗米修斯内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

普罗米修斯java_springboot集成普罗米修斯(Prometheus)的方法相关推荐

  1. 普罗米修斯java_springboot集成普罗米修斯

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 Prometheus 是一套开源的系统监控报警框架.它由工作在 S ...

  2. springboot 接口404_资深架构带你学习Springboot集成普罗米修斯

    这篇文章主要介绍了springboot集成普罗米修斯(Prometheus)的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 ...

  3. 惠普208台式计算机,感受完美家居生活 惠普时尚一体机评测

    ·感受高品质生活 随着消费者对于计算机个性化的需求,一体机这种新兴产品逐渐被大家所认可.和传统的台式机相比,一体机产品拥有着外观简约.操作方便.易于摆放等优势.相信不少网友都知道,惠普在去年推出过一款 ...

  4. 惠普战66prog2拆机_惠普战66G2开箱

    商务笔记本的极致之选---惠普战 66Pro13 G2 开箱评测 如今轻薄型笔记本的种类繁多并且基本上都具备了轻薄的设计,如何在外观设计.配置与价 格之间取得一个平衡也是消费者所看重的点,接下来笔者将 ...

  5. 惠普800g1支持什么内存_惠普黑白激光打印机哪种好 惠普黑白激光打印机推荐【图文详解】...

    打印机的出现让我们在生活和日常工作中变得越来越方便,不过随着科技的发展,打印机的类型也变得非常多,其中就有黑白激光打印机,而黑白激光打印机的品牌也有很多,比如我们的惠普黑白激光打印机,今天小编就给大家 ...

  6. 如何给惠普计算机主机解还原,惠普系统还原,详细教您惠普电脑系统如何还原...

    当我们的电脑遇到蓝屏,黑屏,无法开机,中毒等无法正常使用电脑的状况,大部分人的第一反应是选择重装系统.重装系统确实是个不错的办法,那么有没有什么更简便的方法可以使系统恢复原样呢,答案是有的,下面,小编 ...

  7. 佳能打印机处于错误状态是怎么回事_惠普哪款打印机最稳定 惠普打印机推荐【详解】...

    惠普是 打印机 中的著名品牌,近年来深受消费者喜爱.旗下的产品种类众多,但是如果购买不当,会出现各种各样的问题.很多消费者在选购前都会了解, 惠普哪款打印机最稳定 ?甚至将惠普和佳能的打印机作比较.接 ...

  8. 对比极米Z6X Pro和RS Pro 2,极米H5值得入手吗?极米H5评测来了

    作为国内智能投影行业的领导品牌,极米科技可以说在国内的投影仪市场中占据非常重要的地位,短短几年就在国内投影仪市场做到了巨头品牌之一,它的投影仪在电商平台里面的综合排名在前三以内,彰显出了品牌强大的市场 ...

  9. 小米网关控制空调伴侣_米家智能家居组建之绿米aqara空调伴侣升级版网关

    米家智能家居组建之绿米aqara空调伴侣升级版网关 2020-06-10 16:54:33 3点赞 8收藏 22评论 购买理由 网关,组建智能家居系统必不可少的产品. 选购过程 米家网关产品目前大概有 ...

最新文章

  1. awstats CGI模式下动态生成页面缓慢的改进
  2. shell用到的命令(2) —— break,continue,echo,eval,
  3. 无路可逃java攻略_生化危机2重制版无路可逃怎么过_100丧尸模式幽灵生还者无路可逃流程攻略_3DM单机...
  4. 阶段-关系系统-stage1范围界定阶段---学习记录
  5. 离线地图显示连接服务器未打开,如何在uwp中使用OSM离线地图?没有可用的互联网连接时出现问题...
  6. 内存颗粒位宽和容量_64M的SDRAM颗粒 一般内存是多大的?
  7. 【One by One系列】IdentityServer4(四)授权码流程
  8. P1991-无线通讯网【最小生成树,瓶颈生成树】
  9. 136 - Ugly Numbers
  10. 创维25TI9000工厂模式
  11. Emmet 快速编写html代码
  12. 重装XP后无法启动LINUX的解决方案
  13. Atitit 定时器timer 总结 目录 1. 定时器 循环定时器 和timeout超时定时器 1 2. Spring定时器 1 2.1. 大概流程 1 2.2. 核心源码springboot 1
  14. 安装QQ、TIM提示:安装包可能被非法改动导致安装失败,请从官网下载最新安装包重新安装
  15. PCL实现点云选取并计算选取点法向量及可视化
  16. 妻子写给丈夫情人的催泪信
  17. 【Python2】使用python中的turtle模块学习海龟绘图(有趣的python初体验)(最全最详细的turtle介绍使用)
  18. boost circular_buffer的特性及应用
  19. 充电电池哪个牌子好用?
  20. H5创建一个简单的自动幻灯片

热门文章

  1. Scikit-learn数据预处理之范数缩放NormalizerScaler
  2. Linux驱动编程 step-by-step (十) Linux 内核链表
  3. totorisgit与git两种方式pushpull文件
  4. java springcloud版b2b2c社交电商spring cloud分布式微服务-docker-feign(四)
  5. 人中急救穴 也可通过辨别疾病
  6. Android添加垂直滚动scrollview
  7. 百度地图上进行空间插值---反距离加权法
  8. vSphere ESX 4 安装图解
  9. 通过HttpListener实现简单的Http服务
  10. 使用p3p跨域设置Cookie