9.prometheus监控--监控springboot2.x(Java)
一、环境部署
yum search java | grep jdk
yum install -y java-11-openjdk-devel
二、监控java应用(tomcat/jar)
JMX exporter 负责收集 Java 虚拟机信息---没举例,等以后再做测试
进入到tomcat安装目录,vim
PROMETHEUS_JMX_EXPORTER_OPTS="-javaagent:../prometheus-exporter/jmx_prometheus_javaagent-0.18.0.jar=12345:../prometheus-exporter/tomcat.yml"
JAVA_OPTS="-Xmx4096m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=2048m -Xss1024K $PROMETHEUS_JMX_EXPORTER_OPTS"
三、监控java应用(springboot)
分4个步骤
1、引入maven依赖
2、application.propertiesl配置
3、prometheus配置采集springboot2.x应用提供的监控样本数据
4、grafana将prometheus作为数据源进行可视化展示
3.1 springboot项目(二选一)
引入maven依赖
修改pom.xml添加如下代码,引入Spring Boot Actuator的相关依赖。
<!-- spring-boot-actuator依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- prometheus依赖 -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
application.propertiesl配置
在application.properties中添加相关配置暴露监测数据端口,如果是application.yaml格式,需要转成yaml
出于安全考虑,默认情况下除了/health和/info之外的所有actuator都是关闭的
server.port=8081
spring.application.name=springboot-demo management.endpoints.web.exposure.include=prometheus,health
#management.endpoints.web.exposure.include=*
#management.endpoints.web.exposure.exclude=env,beans
management.metrics.tags.application=${spring.application.name}
3.2 使用现成的springboot项目(二选一)
docker安装
CAdvisor已经把8080端口占用了。所以映射为8081端口docker run -d --restart=always -p 8081:8080 --name springboot-demo linge365/springboot-demo
检查:
http://192.168.10.100:8081/actuator/prometheus
3.3 Prometheus配置
prometheus配置采集springboot2.x的应用target提供的数据
cd /data/docker-prometheus #在scrape_configs(搜刮配置):下面增加如下配置: cat >> prometheus/prometheus.yml << "EOF"
# Spring Boot 2.x 应用数据采集配置
- job_name: 'springboot-demo'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['192.168.10.100:8081']
EOF
重新加载:curl -X POST http://localhost:9090/-/reload
查看:
http://192.168.10.14:9090/graph
http://192.168.10.14:9090/targets?search=

3.4 监控指标
process_files_max_files # 最大文件处理数量
tomcat_sessions_active_current_sessions # Tomcat 当前活跃 session 数量
tomcat_sessions_alive_max_seconds # Tomcat session 最大存活时间
jvm_buffer_total_capacity_bytes # 预估的池中缓冲区的总容量
jvm_threads_daemon_threads # 当前守护进程的线程数量
tomcat_global_request_max_seconds{name="http-nio-8080",} # 全局最长一次请求的时间
tomcat_sessions_active_max_sessions # 最大活跃 session 数量
system_cpu_usage # CPU 利用率
jvm_buffer_memory_used_bytes # 预估 Java 虚拟机用于此缓冲池的内存
jvm_classes_loaded_classes # 当前在 Java 虚拟机中加载的类的数量
jvm_memory_committed_bytes # 为 Java 虚拟机提交的内存量(以字节为单位)
jvm_threads_live_threads # 当前线程数,包括守护进程和非守护进程的线程
tomcat_threads_config_max_threads # 配置的 Tomcat 的最大线程数
tomcat_global_received_bytes_total # Tomcat 接收到的数据量
tomcat_global_sent_bytes_total # Tomcat 发送的数据量
tomcat_threads_current_threads # Tomcat 当前的线程数
tomcat_sessions_created_sessions_total # Tomcat 创建的 session 数
system_load_average_1m # 在一段时间内,排队到可用处理器的可运行实体数量和可用处理器上运行的可运行实体数量的总和的平均值
tomcat_sessions_expired_sessions_total # 过期的 session 数量
jvm_buffer_count_buffers # 预估的池中的缓冲区数量
jvm_memory_used_bytes# JVM 内存使用量
process_uptime_seconds # Java 虚拟机的正常运行时间
jvm_gc_memory_allocated_bytes_total # 增加一个 GC 到下一个 GC 之后年轻代内存池的大小增加
jvm_gc_pause_seconds_count # GC暂停耗时数量和总时间
jvm_gc_pause_seconds_sum
jvm_gc_pause_seconds_max
tomcat_sessions_rejected_sessions_total # 被拒绝的 session 总数
jvm_gc_live_data_size_bytes# Full GC 后的老年代内存池的大小
tomcat_threads_busy_threads # Tomcat 繁忙线程数
jvm_threads_peak_threads # 自 Java 虚拟机启动或峰值重置以来的最高活动线程数
jvm_threads_states_threads # 当前具有 NEW 状态的线程数
jvm_gc_max_data_size_bytes # jvm_gc内存池的最大大小
http_server_requests_seconds_count #某个接口的请求数量和请求总时间
http_server_requests_seconds_sum
http_server_requests_seconds_max
jvm_gc_memory_promoted_bytes_total # GC之前到GC之后的老年代内存池大小的正增加计数
# 日志按级别计数
logback_events_total{application="prometheus-demo",level="info",} 7.0
logback_events_total{application="prometheus-demo",level="trace",} 0.0
logback_events_total{application="prometheus-demo",level="warn",} 0.0
logback_events_total{application="prometheus-demo",level="debug",} 0.0
logback_events_total{application="prometheus-demo",level="error",} 0.0
process_start_time_seconds # 启动时间
process_files_open_files # 打开文件描述符的数量
tomcat_global_error_total # 异常数量
jvm_memory_max_bytes # 可用于内存管理的最大内存量(以字节为单位)
process_cpu_usage # 最近的 CPU 利用率
jvm_classes_unloaded_classes_total # 自 Java 虚拟机开始执行以来卸载的类总数
system_cpu_count # CPU 核数
tomcat_global_request_seconds_count # 全局请求总数和总耗时
tomcat_global_request_seconds_sum
3.5 触发器
cat >> prometheus/rules/springboot.yml <<"EOF"
groups:
- name: SprinBoot
rules:
- alert: SprinBooErrorEvents
expr: increase(logback_events_total{level="error"}[2m]) > 0
for: 2m
labels:
severity: warning
annotations:
summary: "Springboot错误事件 容器: $labels.instance"
description: "在过去2分钟有新的{{ $value }}个错误事件"
EOF
重新加载配置:
curl -X POST http://localhost:9090/-/reload
检查:
http://192.168.10.14:9090/alerts?search=
http://192.168.10.14:9090/rules
3.6 grafana dashboard 数据展示
grafana将prometheus作为数据源进行可视化展示
https://grafana.com/grafana/dashboards/12856-jvm-micrometer/ # 1 SLS JVM监控大盘
https://grafana.com/grafana/dashboards/4701-jvm-micrometer/ # JVM(Micrometer)
https://grafana.com/grafana/dashboards/10280 # Sprint Boot 2.1 Statistics
https://grafana.com/grafana/dashboards/12900-springboot-apm-dashboard/ # 监控数据库连接池dashboard
hikari连接池:https://grafana.com/grafana/dashboards/6083 # SpringBoot HikariCP /JDBC
druid连接池:https://grafana.com/grafana/dashboards/11157 # Druid Connection Pool Dashboard
9.prometheus监控--监控springboot2.x(Java)的更多相关文章
- 基于Docker+Prometheus+Grafana监控SpringBoot健康信息
在微服务体系当中,监控是必不可少的.当系统环境超过指定的阀值以后,需要提醒指定的运维人员或开发人员进行有效的防范,从而降低系统宕机的风险.在CNCF云计算平台中,Prometheus+Grafana是 ...
- Prometheus自定义监控内容
Prometheus自定义监控内容 一.io.micrometer的使用 1.1 Counter 1.2 Gauge 1.3 Timer 1.4 Summary 二.扩展 相关内容原文地址: 博客园: ...
- Prometheus+Grafana监控
什么是Prometheus? Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB).Prometheus使用Go语言开发,是Google BorgMon监控系统 ...
- 实战 Prometheus 搭建监控系统
实战 Prometheus 搭建监控系统 Prometheus 是一款基于时序数据库的开源监控告警系统,说起 Prometheus 则不得不提 SoundCloud,这是一个在线音乐分享的平台,类似于 ...
- Prometheus+Grafana监控SpringBoot
Prometheus+Grafana监控SpringBoot 一.Prometheus监控SpringBoot 1.1 pom.xml添加依赖 1.2 修改application.yml配置文件 1. ...
- Prometheus 系统监控方案 一
最近一直在折腾时序类型的数据库,经过一段时间项目应用,觉得十分不错.而Prometheus又是刚刚推出不久的开源方案,中文资料较少,所以打算写一系列应用的实践过程分享一下. Prometheus 是什 ...
- VisualVM监控远程主机上的JAVA应用程序
使用VisualVM监控远程主机上JAVA应用程序时,需要开启远程主机上的远程监控访问,或者在远程JAVA应用程序启动时,开启远程监控选项,两种方法,选择其中一种就可以开启远程监控功能,配置完成后就可 ...
- Grafana+Prometheus系统监控之webhook
概述 Webhook是一个API概念,并且变得越来越流行.我们能用事件描述的事物越多,webhook的作用范围也就越大.Webhook作为一个轻量的事件处理应用,正变得越来越有用. 准确的说webho ...
- cAdvisor+Prometheus+Grafana监控docker
cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor ...
- 使用Prometheus+Grafana监控MySQL实践
一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...
随机推荐
- 记录--JS精粹,原型链继承和构造函数继承的 “毛病”
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 先从面向对象讲起,本瓜认为:面向对象编程,它的最大能力就是:复用! 咱常说,面向对象三大特点,封装.继承.多态. 这三个特点,以" ...
- 那位拿了多个Offer的大佬分享了最新Go面经
和大家分享一下我们 Go就业训练营 和 升职加薪星球 中战友们投稿的真实面经. 这是第一篇,计划还会再更新4篇最新Go面经,都是拿到Offer的那种! 欢迎大家关注我的账号,关注之后不迷路. 先秀战绩 ...
- SSH框架使用AOP代理+自定义注解遇到的相关问题总结
1.AOP注解失效问题 编写完成注解和AOP切面类时,在controller中加上注解,注解不生效.在配置文件xml中开启AOP注解: <aop:aspectj-autoproxy proxy- ...
- 使用fiddler抓取HTTPS的数据包(抓取App端的数据包)
众所周知,我们在做接口测试的时候有两种情况: 第一种是先拿到接口测试规范文档,再去做接口测试. 第二种是没有接口文档,只有通过自己抓包. 那么说到抓包,就不得不说抓包工具,对于浏览器web端,我们只需 ...
- 06 PSP成熟度模型【软件过程与管理】
PSP成熟度模型(Personal Software Process) 个体度量过程 PSP3 周期开发 个体计划过程 PSP2 代码评审 设计评审 PSP2.1 设计模板 个体质量管理过程 PSP1 ...
- #团,构造#洛谷 3524 [POI2011]IMP-Party
题目 有一个 \(3n\) 个点的无向图,保证有一个大小为 \(2n\) 的团,输出一个大小为 \(n\) 的团 分析 每次选择两个不相连的点删掉,那么剩下的 \(n\) 个点一定是团, 因为每次至少 ...
- #树形dp#洛谷 4395 [BOI2003]Gem 气垫车
题目 给出一棵树,要求你为树上的结点标上权值,权值可以是任意的正整数 唯一的限制条件是相邻的两个结点不能标上相同的权值,要求一种方案,使得整棵树的总价值最小. 分析 每个结点的权值最大可能为 \(\l ...
- Jetty的工作参数
Jetty加载参数的优先级: 命令行. $JETTY_BASE下的文件. 使用--include-jetty-dir指定的目录下的文件. $JETTY_HOME下的文件. 查看当前的配置参数,执行如下 ...
- C 语言指针完全指南:创建、解除引用、指针与数组关系解析
C 语言中的指针 创建指针 我们可以使用引用运算符 & 获取变量的内存地址: int myAge = 43; // 一个 int 变量 printf("%d", myAge ...
- SpringBoot+阿里云OCR图片识别
准备条件:阿里云OCR图片识别API购买,初次购买1分钱500次接口调用 一.控制层 @GetMapping("/uploadManual") @ApiOperation(&quo ...