前面讲了安装jenkins exporter方式监控jenkins,但是grafana支持较少。
接下来,我们用Jenkins plugin的方式监控,这个方法部署简单,然后grafana支持比较完整。
首先,需要安装Jenkins,参照上一个文档完成。
1.安装Jenkins Plugin
2.检查插件配置
设置完成后重启Jenkins服务,并且访问jenkins的url查看指标情况
访问 http://192.168.0.107:8080/prometheus/
# HELP jvm_threads_current Current thread count of a JVM
# TYPE jvm_threads_current gauge
jvm_threads_current 34.0
# HELP jvm_threads_daemon Daemon thread count of a JVM
# TYPE jvm_threads_daemon gauge
jvm_threads_daemon 16.0
# HELP jvm_threads_peak Peak thread count of a JVM
# TYPE jvm_threads_peak gauge
jvm_threads_peak 47.0
# HELP jvm_threads_started_total Started thread count of a JVM
# TYPE jvm_threads_started_total counter
jvm_threads_started_total 73.0
# HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers
# TYPE jvm_threads_deadlocked gauge
jvm_threads_deadlocked 0.0
3. Prometheus监控Jenkins
Prometheus配置文件/etc/prometheus/prometheus.yml,添加如下内容:
scrape_configs:
- job_name: "jenkins"
metrics_path: "/prometheus/"
scheme: http
static_configs:
- targets: ['192.168.0.107:8080']
这里如果用的是tls, 用下面的配置
scrape_configs:
- job_name: 'jenkins'
scheme: https # change to http if don't you have https
metrics_path: '/prometheus/'
static_configs:
- targets: ['192.168.0.107:443'] # Jenkins host and port you serve
tls_config:
insecure_skip_verify: true
重启Prometheus
systemctl restart prometheus
检查Prometheus Target
4.Grafana模板
这里我使用模板 https://grafana.com/grafana/dashboards/9964
至此,完成Prometheus对Jenkins的监控。
推荐此方法。