Jenkins Monitoring: How to Monitor Your Jenkins Server and Jobs. Jenkins is an integral tool for automating continuous integration and continuous delivery (CI/CD) pipelines. Unfortunately, as your Jenkins environment grows and your CI/CD workflows become more complex, things can go wrong. As a result, ensuring the health and performance of your Jenkins server and jobs becomes increasingly critical.
Monitoring your Jenkins setup allows you to stay ahead of potential issues, optimize performance, and streamline your development processes. In this blog post, we show you how to effectively monitor your Jenkins infrastructure.
What is Jenkins Monitoring?
Jenkins monitoring involves actively observing and tracking the health, performance, and operational aspects of your Jenkins server and its associated CI/CD pipelines. Using the right tools, you detect issues and optimize workflows by collecting, analysing, and visualizing key metrics. By doing so, you’re able to proactively detect issues and optimize workflows. Some of the key metrics include resource usage, job execution durations, queue sizes, and build success rates.
How to Monitor Jenkins
There’s no doubt that continuous monitoring helps to guide your projects towards success. In this section, we dive into how you use freely available tools (Prometheus and Grafana) to monitor Jenkins. From tracking build statuses to analyzing resource utilization, this powerful combination provides powerful insights into the performance and health of your Jenkins server.
What is Prometheus?
Prometheus is an open-source monitoring toolkit that’s built to gather, store, and facilitate queries of time-series data. As a result, it’s a robust foundation for monitoring applications, systems, and services. It excels in real-time visibility into metrics, supports dynamic service discovery, and enables custom alerting rules for timely notifications. With its adaptable nature and integrations, Prometheus helps you maintain system reliability and performance in dynamic and distributed environments.
What is Grafana?
Grafana is free and open source visualization tool that provides various dashboards, charts, graphs, alerts for the particular data source. Grafana allows you to query, visualize, explore metrics and set alerts for the data sources.
To summarize, Prometheus seamlessly gathers a wide array of metrics from your Jenkins server and jobs. Grafana transforms this raw data into visually appealing and intuitive dashboards, simplifying the interpretation of complex metrics. Here’s a step-by-step guide on how to set up and monitor Jenkins using Prometheus and Grafana:
Before we dive in, let’s go over some of the components you need prior to configuring Jenkins monitoring:
Configuring the Prometheus Metrics Plugin in Jenkins
Configuring the Prometheus Metrics Plugin in Jenkins is the first step when you want to monitor Jenkins. The plugin exposes metrics in a format compatible with Prometheus. Here’s a step-by-step guide on how to seamlessly setup Jenkins for Prometheus:
Install the Prometheus Metrics Plugin
Access your Jenkins dashboard (usually located at http://localhost:8080/) and log in with administrator privileges.
After you’ve logged in, navigate to the menu on your left-hand side. Click on Manage Jenkins.
From the subsequent menu, select Plugins under the System Configuration section.
Next, select Available plugins tab and search for “Prometheus Metrics” using the search box.
Enable the plugin by marking the checkbox next to its name. Subsequently, initiate the installation process by clicking “Install without restart.”
Finally, restart Jenkins by marking the checkbox adjacent to Restart Jenkins when installation is complete and no jobs are running.
Configure the Prometheus Metrics Plugin
After the plugin is installed, go back to the main Jenkins dashboard. Click on Manage Jenkins.
Under System Configuration, click on System.
Scroll down to the Prometheus Metrics section. Here, you’ll find a field labelled “Path.” This is the endpoint where Jenkins will expose its metrics in a format that Prometheus can scrape. The default path is “/prometheus.” Customize the path to whatever works for you. But we’ll stick to the default (“/prometheus”) for this tutorial. Also, customize the Metrics collection time, in seconds field to adjust the amount of time, in seconds, that must elapse for the metrics to be collected again.
Once you have configured the Prometheus Metrics Plugin settings, scroll down and click the Save button at the bottom of the page. In some cases, the changes might require a Jenkins restart to take effect. If prompted, restart Jenkins.
Verify Metrics Exposure
Now access Prometheus data at http://localhost:8080/prometheus. Make sure to use your Jenkins server’s URL followed by the path you configured.
Edit Configuration File
Create or modify the prometheus.yml configuration file in the directory where Prometheus is installed or from where it is being executed. This file contains the scrape targets and other settings for Prometheus. You need to specify the target Jenkins server’s URL and port for metrics scraping. Here’s a basic example of how to configure Prometheus to scrape metrics from Jenkins:
scrape_configs: - job_name: 'jenkins' metrics_path: '/prometheus' static_configs: - targets: ['jenkins-server:port']
In this configuration, the
targets value under the
static_configs section specifies the address and port where Prometheus should scrape metrics. If your Jenkins server is running locally on the same machine as Prometheus, you can use
'localhost:8080' as the target.
Make sure to replace any existing
scrape_configs sections or adjust the
job_name as needed based on your Prometheus configuration.
Reload or Restart Prometheus
With the configuration updates completed, it’s now time to reload or restart Prometheus. Once you’re done, your Prometheus instance is ready to collect and manage metrics from your Jenkins server.
Now that we’ve set up Prometheus to capture data from Jenkins, It’s now time to set up Grafana to use Prometheus as a data source. Configuring Grafana in Jenkins involves setting up a Grafana dashboard to visualize Jenkins metrics collected by Prometheus. Here’s a step-by-step guide on how to configure Grafana
Add Prometheus as a Data Source
After logging in, navigate to the left sidebar and click on the gear icon to access the Configuration menu. From here, click on Data Sources.
Next, start the process of adding a data source by clicking on Add Data Sources.
Choose Prometheus from the list of available data sources.
Configure the Prometheus data source by providing the following details:
- Name: A descriptive name for the data source (e.g., “Prometheus”).
- URL: The URL of your Prometheus server ( http://localhost:8080).
- Access: Choose “Server (Default)” to allow Grafana to access Prometheus directly.
After you’re done, click on the Save and Test button. If the configuration is successful, you’ll get a “Data source is working” message.
Create a Grafana Dashboard
Grafana provides pre-built dashboards for monitoring Jenkins. Import these dashboards to visualize metrics.
Type “Jenkins” into the search box to find suitable Jenkins dashboards.
Once you find a suitable dashboard, click on it. For this tutorial, we’ll go with the “Jenkins: Performance and Health Overview” dashboard.
Now you’re on the plugin’s page. Locate the Copy ID to clipboard button and click on it.
Go back to Grafana and click on the “+” icon on the left sidebar. Select Import from the dropdown menu.
Paste the dashboard ID you copied into the Import via Grafana.com field as shown below. Click Load to proceed.
Review the plugin details and select Prometheus as the data source. Click Import.
Now the dashboard is fully loaded up and running. You can now explore and interact with the panels to monitor Jenkins metrics, analyze trends, and detect issues.
Remember, the steps may vary slightly depending on the specific dashboard template you’re using and any additional customizations you want to apply. Always refer to the official Grafana documentation for more information on importing and managing dashboards.
Jenkins Monitoring: How to Monitor Your Jenkins Server and Jobs Conclusion
To guarantee the reliability and efficiency of your CI/CD pipeline, it’s important to monitor your Jenkins server. By following this guide, you are able to use Prometheus and Grafana to gain valuable insights into your Jenkins environment. While Prometheus helps you gather all the relevant metrics, Grafana makes it easier for you to consume them through tables and graphs. You get instant access to vital metrics such as build queue lengths, job durations, node utilization, and more.