一、整合jmx_exporter及tomcat
1、 jmx_exporter下载地址
https://github.com/prometheus/jmx_exporter/releases
2、 tomcat配置文件下载地址
https://github.com/prometheus/jmx_exporter/blob/main/example_configs/tomcat.yml
3、创建tomcat_exporter目录
[root@localhost ~]# mkdir /usr/local/jmx_prometheus
将下载的jmx_exporter的jar包及tomcat.yml文件放在此目录下
二、配置相关参数
1、配置tomcat.yml
将tomcat.yml文件中的所有Catalina字段全部替换成Tomcat
2、在/usr/local/tomcat/bin/catalina.sh文件中添加JVM参数
PROMETHEUS_JMX_EXPORTER_OPTS="-javaagent: /usr/local/tomcat_exporter /jmx_prometheus_javaagent-0.20.0.jar =12345: /usr/local/tomcat_exporter /tomcat.yml"
JAVA_OPTS="$JAVA_OPTS $PROMETHEUS_JMX_EXPORTER_OPTS"
注:以上javaagent为jmx_exporter的jar包所在路径,12345端口可以在不占用端口的情况下自定义,后面为tomcat的yml配置文件路径。
3、启动tomcat并查看业务端口及12345端口是否启动,查看tomcat启动日志,查看是否报错
[root@localhost ~]# cd /usr/local/tomcat/bin/
[root@localhost ~]# ./startup.sh
4、访问prometheus jmx exporter HTTP服务获取监控数据
http://192.168.1.11:12345/metrics
三、prometheus监控部署及配置
部署略
1、配置
[root@nginx-rtmp prometheus]# cd /usr/local/prometheus
[root@nginx-rtmp prometheus]# vi prometheus.yml
最后添加:
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: "Tomcat"
static_configs:
- targets: ["192.168.1.11:12345"]
[root@nginx-rtmp prometheus]# systemctl start prometheus.service
2、登录查看是否有数据
http://192.168.1.11:9090/