Advanced Jenkins
Jenkins Administration and Monitoring
Monitoring with Prometheus Grafana
In this guide, you’ll learn how to monitor Jenkins using Prometheus and Grafana for full visibility into build activity, resource utilization, and system health. We’ll cover:
- Installing the Prometheus Metrics plugin in Jenkins
- Deploying Prometheus and Grafana with Docker Compose
- Scraping Jenkins metrics and querying them in Prometheus
- Visualizing data in Grafana dashboards
- Generating load in Jenkins to see real-time updates
This end-to-end solution provides a scalable observability layer for your CI/CD pipelines.
1. Install and Configure the Prometheus Metrics Plugin in Jenkins
Jenkins exposes its internal metrics through the Prometheus Metrics plugin. By default, the metrics endpoint is available at /prometheus
.
- Navigate to Manage Jenkins → Manage Plugins.
- In the Available tab, search for and install Prometheus Metrics Plugin.
- Restart Jenkins when prompted.
After the restart:
- Go to Manage Jenkins → Configure System and search for Prometheus.
- Set Metrics collection interval to 10 seconds (default is 120s).
- Disable Disk Usage if you haven’t installed the CloudBees Disk Usage plugin.
- Leave other options at their defaults and note the endpoint path:
/prometheus
.
Note
Disabling Disk Usage metrics avoids extra overhead if you’re not using the CloudBees plugin.
2. Deploy Prometheus and Grafana using Docker Compose
Create a docker-compose.yml
in your project root to launch Prometheus (port 9090) and Grafana (port 8081):
version: '3.7'
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
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: password
volumes:
- ./grafana:/etc/grafana/provisioning/datasources
ports:
- "8081:3000"
restart: unless-stopped
volumes:
prom_data:
Warning
The default Grafana credentials are admin/password. Change them in production by setting GF_SECURITY_ADMIN_USER
and GF_SECURITY_ADMIN_PASSWORD
to secure values.
Once Jenkins is up, verify that Prometheus can scrape its metrics:
# HELP jvm_memory_bytes Committed (bytes) of a given JVM memory area.
# TYPE jvm_memory_bytes gauge
jvm_memory_bytes{area="heap"} 1.056188896E7
jvm_memory_bytes_used{area="heap"} 1.183386848E7
...
3. Configure Prometheus to Scrape Jenkins
Edit prometheus/prometheus.yml
to add a jenkins
job:
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
- job_name: jenkins
metrics_path: /prometheus/
static_configs:
- targets: ["<JENKINS_HOST>:<JENKINS_PORT>"]
Replace <JENKINS_HOST>:<JENKINS_PORT>
with your Jenkins URL (e.g., jenkins.example.com:8080
).
4. Launch the Monitoring Stack
docker-compose up -d
This command starts both Prometheus and Grafana in the background.
5. Verify Jenkins Target in Prometheus
Open http://<VM_IP>:9090
, then go to Status → Targets. You should see both prometheus and jenkins targets listed as UP
.
6. Explore Jenkins Metrics with Prometheus
Use Prometheus → Graph to run queries. For example:
Metric | Description | Query |
---|---|---|
jenkins_job_count_value | Total number of Jenkins jobs | jenkins_job_count_value |
jenkins_plugins_active | Count of active plugins | jenkins_plugins_active |
jenkins_plugins_withUpdate | Plugins that have updates available | jenkins_plugins_withUpdate |
- Type
jenkins_
in the Expression field to see available metrics.
- Plot a metric over time:
jenkins_job_count_value
7. Add Prometheus Data Source in Grafana
- Visit
http://<VM_IP>:8081
and log in (admin
/password
). - Go to Configuration → Data Sources → Add data source → Prometheus.
- Set URL to
http://prometheus:9090
(or your host URL). - Click Save & Test.
8. Import a Jenkins Dashboard in Grafana
Grafana’s dashboard repository includes prebuilt Jenkins dashboards. We’ll import Jenkins Performance & Health Overview (ID 9964):
- In Grafana, click Create → Import.
- Enter 9964 and click Load.
- Select your Jenkins-Prometheus data source and click Import.
9. Generate Build Activity in Jenkins
To populate your dashboards with data, create a simple Pipeline that sleeps and echoes:
In Jenkins, click New Item → Pipeline, name it monitor-jenkins, then OK.
Under Pipeline → Definition, choose Pipeline script and paste:
node { stage('Echo Message') { sh 'sleep 25' } } node('ubuntu-docker-jdk17-node20') { stage('Echo Message2') { sh 'echo 1' } }
Save and run Build Now ~20 times.
10. Visualize Real-Time Metrics in Grafana
After a few minutes, refresh your Grafana dashboard. You’ll see metrics for queue rate, processing speed, executor usage, and more updating live.
Customize panels by clicking a panel title and selecting Edit. You can switch graph types, adjust legends, or add thresholds.
You’ve successfully set up a robust monitoring stack for Jenkins using Prometheus and Grafana. With this integration, you gain deep insights into build performance, system health, and resource trends. Explore additional dashboards, custom PromQL alerts, and Grafana panels to tailor your CI/CD observability.
Links and References
- Prometheus Metrics Plugin for Jenkins
- Docker Compose Documentation
- Grafana Dashboards Repository
- Jenkins Documentation
- Prometheus Documentation
Watch Video
Watch video content