In the modern landscape of DevOps, effective tracking and observability are crucial for ensuring the smooth operation of complex systems. As organizations scale, they encounter an increasing need to monitor, trace, and analyze various aspects of their CI/CD pipelines and the applications they support. Tools like Jenkins, Prometheus, and Observe provide powerful capabilities to achieve these goals. This article explores how to integrate Jenkins, Prometheus, and Observe for advanced tracking and observability, supported by coding examples.
Introduction to Jenkins, Prometheus, and Observe
Jenkins is a widely-used automation server that facilitates continuous integration and continuous delivery (CI/CD). It allows developers to automate testing, building, and deploying applications, thereby speeding up the development process. However, Jenkins alone doesn’t provide sufficient insights into the performance, stability, and reliability of the CI/CD pipelines.
Prometheus is an open-source monitoring and alerting toolkit that excels at capturing time-series data and providing powerful querying capabilities. It is a perfect companion to Jenkins for monitoring pipeline metrics, such as build durations, success rates, and more.
Observe is a modern observability platform that goes beyond simple monitoring. It ingests logs, metrics, and traces from various sources, offering a unified view of your system’s performance. By integrating Jenkins and Prometheus with Observe, you can achieve comprehensive observability of your entire software delivery lifecycle.
Setting Up Jenkins for Prometheus Monitoring
To begin, you need to set up Jenkins to expose metrics that Prometheus can scrape. Jenkins supports Prometheus via the Prometheus Metrics Plugin, which exposes various metrics related to jobs, builds, nodes, and more.
Install the Prometheus Metrics Plugin
- Navigate to
Manage Jenkins > Manage Plugins > Available
. - Search for “Prometheus Metrics Plugin” and install it.
- Once installed, restart Jenkins to apply the changes.
Configure the Plugin
- Go to
Manage Jenkins > Configure System
. - Scroll down to the “Prometheus” section.
- Here, you can configure the HTTP endpoint that will expose the metrics. The default is
/prometheus
.
After completing these steps, Jenkins will start exposing metrics on the /prometheus
endpoint, which Prometheus can scrape.
Example of Jenkins Prometheus Metrics Endpoint
shell
Access the Jenkins Prometheus endpoint (assuming Jenkins is running on localhost and port 8080)
curl http://localhost:8080/prometheus
You should see a list of metrics, such as:
bash
# HELP jenkins_job_duration_seconds The duration of Jenkins jobs
# TYPE jenkins_job_duration_seconds summary
jenkins_job_duration_seconds{job_name="example-job",quantile="0.5"} 10.2
jenkins_job_duration_seconds{job_name="example-job",quantile="0.9"} 12.3
Setting Up Prometheus to Scrape Jenkins Metrics
With Jenkins exposing metrics, the next step is to configure Prometheus to scrape these metrics. Assuming you have Prometheus installed, follow these steps:
Edit Prometheus Configuration
Add a job for Jenkins in the prometheus.yml
configuration file:
yaml
scrape_configs:
- job_name: 'jenkins'
scrape_interval: 15s
static_configs:
- targets: ['localhost:8080']
labels:
service: jenkins
Step 2: Start Prometheus
Restart Prometheus to apply the changes:
shell
prometheus --config.file=prometheus.yml
Verify the Integration
Access the Prometheus dashboard and navigate to the “Targets” page (http://localhost:9090/targets
). You should see Jenkins listed as a target, with a status of “UP”.
Querying Jenkins Metrics
You can now query Jenkins metrics using the Prometheus query language (PromQL). For example, to view the average duration of a specific job:
promql
avg(jenkins_job_duration_seconds{job_name="example-job"})
Visualizing Metrics with Grafana
To visualize the data collected by Prometheus, Grafana is an ideal choice. Grafana integrates seamlessly with Prometheus, allowing you to create dashboards to monitor Jenkins pipelines.
Install Grafana
Follow the official documentation to install Grafana on your system. Once installed, start the Grafana server:
shell
sudo systemctl start grafana-server
Add Prometheus as a Data Source
- Log in to Grafana (
http://localhost:3000
). - Navigate to
Configuration > Data Sources > Add Data Source
. - Select “Prometheus” and configure it with the Prometheus URL (
http://localhost:9090
).
Create a Dashboard
You can now create dashboards using the Jenkins metrics exposed to Prometheus. For example, you can visualize job durations, success rates, and more.
Example Grafana Query for Jenkins Job Duration
promql
rate(jenkins_job_duration_seconds_sum[1m]) / rate(jenkins_job_duration_seconds_count[1m])
Observability with Observe
Prometheus and Grafana offer excellent metrics and visualization capabilities, but for full-stack observability, integrating with a platform like Observe is beneficial. Observe provides deep insights by correlating metrics, logs, and traces.
Ingest Prometheus Metrics into Observe
Observe can ingest Prometheus metrics via the Prometheus Remote Write integration.
Add the following to your prometheus.yml
:
yaml
remote_write:
- url: "https://<your-observe-tenant>.observeinc.com/api/v1/remote_write"
headers:
Authorization: "Bearer <your-api-token>"
This configuration sends all Prometheus metrics to Observe, where you can take advantage of its advanced querying and alerting features.
Ingest Jenkins Logs
Observe also supports direct ingestion of Jenkins logs. You can configure the Jenkins logging system to send logs to Observe via an HTTP or Syslog endpoint.
Example Jenkins Log Forwarding Configuration
shell
Assuming you use rsyslog for forwarding logs
/etc/rsyslog.d/50-default.conf
if $programname == ‘jenkins’ then @@<observe-logging-endpoint>:514Unified Observability in Observe
Once both Prometheus metrics and Jenkins logs are ingested into Observe, you can create dashboards, set up alerts, and run queries that correlate data across your CI/CD pipeline. This unified view helps in identifying root causes faster and understanding the impact of changes across the system.
Conclusion
Achieving advanced tracking and observability in a CI/CD environment is critical for maintaining high availability and performance. Jenkins provides a robust foundation for automating the build and deployment processes, while Prometheus offers powerful monitoring capabilities. When integrated with Observe, these tools provide a comprehensive observability solution that spans metrics, logs, and traces.
By setting up Jenkins to expose Prometheus metrics, configuring Prometheus to scrape those metrics, and using Grafana for visualization, you can gain valuable insights into your CI/CD pipelines. Further, integrating with Observe allows for full-stack observability, enabling you to correlate events, metrics, and logs for a holistic view of your system.
In summary, the combination of Jenkins, Prometheus, and Observe empowers DevOps teams to build resilient pipelines, quickly identify issues, and continuously improve the software delivery process.