项目地址: https://github.com/prometheus/jmx_exporter
jar包下载地址: https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar
配置文件实例地址:
https://github.com/prometheus/jmx_exporter/blob/master/example_configs/tomcat.yml
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: 'Catalina<>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
help: Tomcat global $3
type: COUNTER
- pattern: 'Catalina<>(requestCount|maxTime|processingTime|errorCount):'
name: tomcat_servlet_$3_total
labels:
module: "$1"
servlet: "$2"
help: Tomcat servlet $3 total
type: COUNTER
- pattern: 'Catalina<>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
name: tomcat_threadpool_$3
labels:
port: "$2"
protocol: "$1"
help: Tomcat threadpool $3
type: GAUGE
- pattern: 'Catalina<>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
name: tomcat_session_$3_total
labels:
context: "$2"
host: "$1"
help: Tomcat session $3 total
type: COUNTER
- pattern: ".*" #让所有的jmx metrics全部暴露出来
安装github上的方式启动就好了
java -javaagent:./jmx_prometheus_javaagent-0.3.0.jar=9151:config.yaml -jar yourJar.jar
进入bin目录$TOMCAT_HOME/bin,将jmx_exporter.jar包文件和config.yaml文件复制到这里。然后修改里面的一个catalina.sh的脚本,找到JAVA_OPTS,加上以下配置(代理):
如果有多tomcat,建议将jmx_prometheus_javaagent和config.yaml文件放到固定的目录,$TOMCAT_HOME/bin/catalina.sh文件中写绝对路径.
#修改bin/catalina.sh 文件
添加:
JAVA_OPTS="-javaagent:bin/jmx_prometheus_javaagent-0.3.1.jar=39081:bin/config.yaml"
访问服务器上的39081端口,查看是否采集到数据
[root@sfa_1-47 sfa_haid]# curl -s http://192.168.1.47:39081/ | more
# HELP jmx_config_reload_success_total Number of times configuration have successfully been reloaded.
# TYPE jmx_config_reload_success_total counter
jmx_config_reload_success_total 0.0
# HELP jmx_config_reload_failure_total Number of times configuration have failed to be reloaded.
# TYPE jmx_config_reload_failure_total counter
jmx_config_reload_failure_total 0.0
# HELP jvm_buffer_pool_used_bytes Used bytes of a given JVM buffer pool.
# TYPE jvm_buffer_pool_used_bytes gauge
jvm_buffer_pool_used_bytes{pool="direct",} 381497.0
jvm_buffer_pool_used_bytes{pool="mapped",} 0.0
# HELP jvm_buffer_pool_capacity_bytes Bytes capacity of a given JVM buffer pool.
# TYPE jvm_buffer_pool_capacity_bytes gauge
jvm_buffer_pool_capacity_bytes{pool="direct",} 381497.0
jvm_buffer_pool_capacity_bytes{pool="mapped",} 0.0
# HELP jvm_buffer_pool_used_buffers Used buffers of a given JVM buffer pool.
# TYPE jvm_buffer_pool_used_buffers gauge
jvm_buffer_pool_used_buffers{pool="direct",} 5.0
jvm_buffer_pool_used_buffers{pool="mapped",} 0.0
# HELP jvm_threads_current Current thread count of a JVM
# TYPE jvm_threads_current gauge
jvm_threads_current 155.0
添加自动发现文件
[root@localhost prometheus]# vim /opt/prometheus/prometheus.yml
- job_name: 'tomcat'
file_sd_configs:
- files: ['/opt/prometheus/sd_config/tomcat.yml']
refresh_interval: 180s
配置文件
[root@localhost prometheus]# vim /opt/prometheus/sd_config/tomcat.yml
- targets:
- 192.168.1.47:39081
labels:
idc: bj_company
service: tomcat
重载配置文件
kill -hup `ps -ef |grep prometheus|grep -v grep|awk '{print $2}'`
到Prometheus控制台查询
111.png
导入模板, 需要略作修改就可以使用了
最终效果图
-VZjGlBNv-1589358745908)]
111.png
导入模板, 需要略作修改就可以使用了
最终效果图
[外链图片转存中…(img-X8aPv4vg-1589358745912)]
222.png