海南省住房和城乡建设厅官方网站,个人简历模板免费下载手机版,怎么做网络直播卖衣服的网站,阿里云可以做几个网站这篇文章主要介绍了springboot集成普罗米修斯(Prometheus)的方法#xff0c;文中通过示例代码介绍的非常详细#xff0c;对大家的学习或者工作具有一定的参考学习价值#xff0c;需要的朋友们下面随着小编来一起学习学习吧#xff01;Prometheus 是一套开源的系统监控报警框…这篇文章主要介绍了springboot集成普罗米修斯(Prometheus)的方法文中通过示例代码介绍的非常详细对大家的学习或者工作具有一定的参考学习价值需要的朋友们下面随着小编来一起学习学习吧Prometheus 是一套开源的系统监控报警框架。它由工作在 SoundCloud 的 员工创建并在 2015 年正式发布的开源项目。2016 年Prometheus 正式加入 Cloud Native Computing Foundation非常的受欢迎。简介Prometheus 具有以下特点一个多维数据模型其中包含通过度量标准名称和键/值对标识的时间序列数据PromQL一种灵活的查询语言可利用此维度不依赖分布式存储 单服务器节点是自治的时间序列收集通过HTTP上的拉模型进行通过中间网关支持推送时间序列通过服务发现或静态配置发现目标多种图形和仪表板支持模式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 后会进行去除重复数据分组并路由到对收的接受方式发出报警。常见的接收方式有电子邮件pagerdutyOpsGenie, 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-weborg.springframework.boot spring-boot-starter-actuatorio.micrometer micrometer-registry-prometheus暴露prometheus的接口暴露metrics.tags和spring.application.name一致。server: port: 8081spring: application: name: my-prometheusmanagement: endpoints: web: exposure: include: prometheus metrics: tags: application: ${spring.application.name}写一个API接口用作测试。代码如下RestControllerpublic 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 gaugejvm_gc_max_data_size_bytes{applicationmy-prometheus,} 2.863661056E9# HELP http_server_requests_seconds # TYPE http_server_requests_seconds summaryhttp_server_requests_seconds_count{applicationmy-prometheus,exceptionNone,methodGET,outcomeCLIENT_ERROR,status404,uri/**,} 1.0http_server_requests_seconds_sum{applicationmy-prometheus,exceptionNone,methodGET,outcomeCLIENT_ERROR,status404,uri/**,} 0.018082327# HELP http_server_requests_seconds_max # TYPE http_server_requests_seconds_max gaugehttp_server_requests_seconds_max{applicationmy-prometheus,exceptionNone,methodGET,outcomeCLIENT_ERROR,status404,uri/**,} 0.018082327# HELP jvm_threads_states_threads The current number of threads having NEW state# TYPE jvm_threads_states_threads gaugejvm_threads_states_threads{applicationmy-prometheus,statewaiting,} 12.0jvm_threads_states_threads{applicationmy-prometheus,staterunnable,} 8.0jvm_threads_states_threads{applicationmy-prometheus,statetimed-waiting,} 2.0jvm_threads_states_threads{applicationmy-prometheus,stateterminated,} 0.0jvm_threads_states_threads{applicationmy-prometheus,stateblocked,} 0.0jvm_threads_states_threads{applicationmy-prometheus,statenew,} 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/)下载并安装。23 wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.darwin-amd64.tar.gztar xvfz prometheus-*.tar.gzcd 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 its 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.fileprometheus.yml多次请求springboot项目的接口http://localhost:8081/test , 并访问prometheus的控制台http://localhost:9090/展示的界面如下prometheus提供了一些可视化图比如使用柱状图来展示每秒请求数安装grafanagrafana 是一款采用 go 语言编写的开源应用主要用于大规模指标数据的可视化展现是网络架构和应用分析中最流行的时序数据展示工具目前已经支持绝大部分常用的时序数据库。使用grafana去展示prometheus上的数据。先安装安装命令如下wget https://dl.grafana.com/oss/release/grafana-7.0.4.darwin-amd64.tar.gztar -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即展示了以时间为横轴请求数为纵轴的请求曲线如图所示到此这篇关于文章就结束了总结另外本人整理了一些spring的视频资料一共有8集以及一些Java的学习视频以及资料免费分享给大家想要资料的可以点赞关注私信 ‘资料’ 即可免费领取。深入底层剖析源码。了解本质。 爱编程爱生活爱分享希望对大家有所帮助有用的话点赞给我支持