Certified Jenkins Engineer
Jenkins Administration and Monitoring Part 2
Demo Monitoring with Prometheus Grafana
In this tutorial, you’ll learn how to collect and visualize Jenkins metrics using the Prometheus Metrics Plugin, Prometheus, and Grafana. We’ll cover:
- Installing and configuring the Jenkins plugin
- Deploying Prometheus and Grafana via Docker Compose
- Scraping Jenkins metrics in Prometheus
- Building dashboards in Grafana
- Generating live data with a sample pipeline
1. Install and Configure the Jenkins Prometheus Metrics Plugin
Jenkins can export runtime data through the Prometheus Metrics Plugin, which adds an HTTP endpoint for scraping.
In Jenkins, navigate to Manage Jenkins » Manage Plugins » Available, search for Prometheus, then install Prometheus Metrics Plugin.
Restart Jenkins to activate the plugin.
Go to Manage Jenkins » Configure System » Prometheus. By default, metrics are collected every 120 seconds at the
/prometheus
endpoint.For rapid feedback, set Metrics collection period to 10 seconds. Enable or disable metrics (disk usage, node status, etc.).
Now Jenkins exposes metrics at:
http://<jenkins-host>:<port>/prometheus
2. Deploy Prometheus and Grafana with Docker Compose
Create a project directory (e.g., prometheus-grafana/
) with:
docker-compose.yml
prometheus/prometheus.yml
In docker-compose.yml
:
version: '3.8'
services:
prometheus:
image: prom/prometheus
container_name: prometheus
command: --config.file=/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
- prom_data:/prometheus
restart: unless-stopped
grafana:
image: grafana/grafana
container_name: grafana
ports:
- "8081:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=password
volumes:
- ./grafana:/etc/grafana/provisioning/datasources
restart: unless-stopped
volumes:
prom_data:
2.1 Service Overview
Service | Image | Ports | Data Volume |
---|---|---|---|
prometheus | prom/prometheus | 9090:9090 | ./prometheus:/etc/prometheus , prom_data |
grafana | grafana/grafana | 8081:3000 | ./grafana:/etc/grafana/provisioning/datasources |
2.2 Prometheus Configuration
In prometheus/prometheus.yml
, set global options and scrape jobs:
alerting:
alertmanagers:
- static_configs:
- targets: ["alertmanager:9093"]
scrape_configs:
- job_name: 'prometheus'
metrics_path: /metrics
static_configs:
- targets: ['localhost:9090']
- job_name: 'jenkins'
metrics_path: /prometheus
static_configs:
- targets: ['<jenkins-host>:<jenkins-port>']
Replace <jenkins-host>
and <jenkins-port>
with your Jenkins address (e.g., jenkins-controller:8080
).
Note
If you’re not using Alertmanager, you can remove or comment out the alerting:
section above.
2.3 Launch the Stack
cd prometheus-grafana
docker compose up -d
You should see:
[+] Running 4/4
Network prometheus-grafana_default Created
Volume "prometheus-grafana_prom_data" Created
Container prometheus Started
Container grafana Started
3. Verify in Prometheus
- Open
http://<vm-ip>:9090
in your browser. - Go to Status » Targets. Both prometheus and jenkins targets should be UP.
3.1 Query Example: Jenkins Job Count
Navigate to Graph.
Enter the query:
jenkins_job_count_value{job="jenkins"}
Click Execute. You may see output like:
jenkins_job_count_value{instance="64.227.187.25:8080", job="jenkins"} => 22
3.2 Plugin Metrics
Active plugins:
jenkins_plugins_active{job="jenkins"}
Plugins requiring updates:
jenkins_plugins_withUpdate{job="jenkins"}
Confirm plugin updates in Jenkins under Manage Jenkins » Manage Plugins » Updates:
4. Visualize in Grafana
- Open Grafana at
http://<vm-ip>:8081
. Log in as admin/password. - Go to Configuration » Data Sources, and add or verify Prometheus pointing to
http://prometheus:9090
.
- Click Create » Import, enter Dashboard ID 9964, select your Prometheus data source, and import.
You’ll see the Jenkins Performance & Health Overview:
5. Generate Live Data with a Sample Pipeline
Before adding load, revisit plugin updates:
5.1 Create a New Pipeline Job
Click New Item, name it monitor-jenkins, choose Pipeline, then click OK.
In Pipeline » Script, add:
node { stage('Echo Message1') { sh 'sleep 2s' } node('ubuntu-docker-jdk17-node20') { stage('Echo Message2') { sh 'echo 15' } } }
Verify your agent label under Manage Jenkins » Manage Nodes.
Save and click Build Now 10–20 times to generate metrics.
6. Customize Grafana Panels & Observe Metrics
You can tailor any panel—switch from time series to gauge, adjust thresholds, and more:
After a few builds, refresh your dashboard:
Finally, monitor pipeline status in Jenkins:
Conclusion
By following these steps—installing the Prometheus Metrics Plugin, deploying Prometheus/Grafana, scraping Jenkins metrics, and importing a dashboard—you can achieve comprehensive real-time monitoring of your Jenkins environment. Customize scrape intervals, panel types, and alert rules to suit production requirements. Happy monitoring!
Links and References
- Jenkins Prometheus Metrics Plugin
- Prometheus Documentation
- Grafana Documentation
- Docker Compose Overview
Watch Video
Watch video content