How to add monitoring in Jenkins
In DevOps’s dynamic and fast-paced domain, Jenkins is the cornerstone of automation, particularly in facilitating continuous integration and delivery (CI/CD). As Jenkins environments scale and become more complex, it becomes necessary to implement a robust monitoring system. This guide aims to provide a detailed and beginner-friendly exploration of monitoring Jenkins, focusing on metrics and alerting.
Table of contents
- What is Jenkins monitoring?
- Metrics Monitoring in Jenkins
- Integration of Prometheus and Grafana with Jenkins
- Alerting in Jenkins
- Troubleshooting Jenkins monitoring errors
- Conclusion
What is Jenkins monitoring?
Jenkins monitoring is a comprehensive and systematic approach used to watch, analyze, and optimize the performance of the Jenkins automation server. This server is crucial in the continuous integration and continuous delivery (CI/CD) pipeline.
The practice involves real-time and continuous collection of various metrics and establishing proactive alerting mechanisms. This ensures the Jenkins infrastructure’s robustness, reliability, and optimal functioning.
Let’s discuss some of the key points regarding the purpose of monitoring Jenkins:
Performance optimization
One of the primary objectives of Jenkins monitoring is to facilitate performance optimization. This involves meticulously tracking resource utilization metrics such as CPU, memory, and disk space, which provides a granular understanding of the server’s operational load.
With this insight, teams can identify potential bottlenecks and allocate resources judiciously, fostering an environment of boosted efficiency. Additionally, analyzing build durations is instrumental in identifying areas for refinement and improving the overall speed and effectiveness of the build processes.
Issue identification and resolution
Jenkins monitoring is an early warning system that constantly assesses job success/failure rates and closely examines complex build dependencies. This watchful approach helps teams quickly detect and resolve CI/CD pipeline issues, reducing project delay risk.
Additionally, monitoring the executor queues and availability guarantees that job execution remains smooth and uninterrupted, ensuring timely delivery of software projects.
Capacity planning
Monitoring Jenkins involves analyzing the throughput of the number of builds completed within a specified period. This analysis is crucial for effective capacity planning, allowing organizations to predict resource needs and scale infrastructure accordingly to handle varying workloads.
Additionally, keeping track of build queue lengths provides insights into resource utilization trends, helping teams optimize infrastructure for sustained efficiency.
User experience and reliability
Jenkins monitoring is aimed at reducing build queue times to enhance user experience. This focus on responsiveness guarantees a seamless and satisfactory experience for developers and stakeholders.
It is essential to regularly scrutinize server logs to identify any anomalies, errors, or warnings that may compromise the reliability of the Jenkins environment.
This proactive approach allows for preemptive issue resolution, ensuring the stability of the entire CI/CD ecosystem.
Metrics monitoring in Jenkins
Metrics monitoring involves tracking, measuring, and analyzing metrics or KPIs to evaluate a system’s performance, health, or efficiency. It is used in various fields to ensure goals are met, resources are optimized, and issues are identified and resolved promptly. Technology includes tracking response times, error rates, and resource utilization to maintain reliability and performance.
Let’s explore the various types of metrics and learn how to monitor them individually:
System metrics
Description
These metrics offer a comprehensive understanding of the overall health of your Jenkins master. It encompasses vital aspects such as resource utilization, response times, and system performance, providing a holistic view of the underlying infrastructure.
How to monitor
Initiating the monitoring journey involves navigating to the Jenkins dashboard. Once there, proceed to Manage Jenkins, then navigate to Plugins.
Install the Prometheus plugin, a powerful tool for collecting and querying metrics data. This can be done by going to the Available tab in the plugin manager, selecting Prometheus, checking the box next to it, and then clicking the Install button.
Refer to the official Jenkins documentation to learn more about the Prometheus plugin.
Job metrics
Description
These metrics zoom in on individual job executions, unraveling intricate details such as execution times, success rates, and resource consumption. By monitoring job metrics, you gain critical insights into the efficiency and performance of your CI/CD pipelines.
How to monitor
Set up Prometheus and Grafana to seamlessly integrate with Jenkins. Prometheus captures detailed data on execution times, success rates, and resource usage. Meanwhile, Grafana transforms this data into practical, customizable visualizations, providing a user-friendly platform for interpreting crucial job metrics.
This useful monitoring setup becomes your go-to resource for gaining real-time insights into the efficiency and performance of your CI/CD pipelines.
Integration of Prometheus and Grafana with Jenkins
Integrating Prometheus and Grafana with Jenkins allows you to monitor and visualize Jenkins metrics and performance. By seamlessly connecting these tools, you gain real-time insights into the health of your Jenkins environment, enabling proactive responses to potential issues and performance bottlenecks.
Here’s a step-by-step guide to help you set up Prometheus and Grafana with Jenkins:
Install and configure Prometheus
Download Prometheus
Visit the Prometheus download page.
Download the appropriate version for your operating system (e.g., Linux, Windows, macOS).
Extract and configure Prometheus
Extract the downloaded archive to a directory of your choice.
Then, go to that folder directory. Inside the Prometheus folder, try to find a configuration file named prometheus.yml
.
If it’s not available, you have to create a new file with the same name as prometheus.yml
by using use this basic configuration:
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "jenkins"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:8080"]
Code language: PHP (php)
Adjust the targets
parameter with the address of your respective Jenkins server.
Run Prometheus
Open a terminal or command prompt and navigate to the Prometheus directory. Then, start Prometheus using the following command:
"C:\Program Files (x86)\prometheus\prometheus.exe" --config.file="C:\Program Files (x86)\prometheus\prometheus.yml"
Code language: JavaScript (javascript)
Replace the file path with the correct location of your Prometheus installation.
Finally, Prometheus will start, and you can access its web interface at http://localhost:9090
.
Install and configure Grafana
Download and install Grafana
Visit the Grafana download page.
Make sure to download and install the appropriate version of Grafana for your operating system. Refer to the official documentation for installation instructions.
Start Grafana
Open a terminal or command prompt and start the Grafana server using the following command:
"C:\Program Files\GrafanaLabs\grafana\bin\grafana-server.exe" start
Code language: JavaScript (javascript)
Replace the path with the correct location of your Grafana installation.
Access Grafana web interface
Open your web browser and go to http://localhost:3000
. Log in using the default credentials (username: admin, password: admin). Then, on the next page, you have to reset the password.
Configure Grafana data source
In Grafana, navigate to the dashboard page, then select Data Sources.
Under Add your first data source page, Select Prometheus from the list of available data sources.
Configure the Prometheus URL (e.g., http://localhost:9090
) and save the configuration by clicking the Save & test button.
Import Jenkins dashboard in Grafana
In Grafana, go to the search bar and search for Import dashboard. Then, to configure it, use the Grafana dashboard ID (1860) and click Load.
Adjust any additional settings if needed and click Import.
Configure Jenkins for Prometheus metrics
Before we start configuring the Prometheus metrics, ensure you have the correct plugins installed in your Jenkins application.
Now, follow these steps:
From the dashboard page of Jenkins, go to Manage Jenkins and click the System button.
Scroll down to the Prometheus tab section. Then, configure all the available settings and checkboxes according to your monitoring needs.
Then click on the Save button and restart Jenkins to apply the changes.
Verify the setup
Go to the Prometheus web interface (http://localhost:9090/targets
) to ensure Jenkins is listed as a target. Then, go to your Grafana web interface and check the Jenkins dashboard for metrics.
Now, you should have Prometheus collecting metrics from Jenkins and Grafana and visualizing these metrics through a predefined dashboard. Adjust configurations as needed for your specific environment.
Alerting in Jenkins
In Jenkins, alerting typically refers to the capability of notifying relevant stakeholders or system administrators about certain events or conditions during the build and deployment processes. Alerting mechanisms are crucial for maintaining the health and integrity of continuous integration and continuous deployment (CI/CD) pipelines.
When specific conditions are met or events occur, alerts can be triggered to promptly inform responsible parties, allowing them to take appropriate actions.
Let’s explore the various types of alerting and learn how to configure them individually:
System alerts
Description
System alerts are warning signals activated when significant issues impact Jenkins broadly. These alerts serve as early indicators, giving a heads-up about potential problems that could affect the overall stability of the Jenkins environment.
By notifying administrators or relevant personnel, system alerts enable proactive intervention, allowing teams to address issues promptly, prevent potential disruptions, and ensure the seamless operation of the CI/CD pipeline.
Essentially, system alerts act as the frontline defense, ensuring the continuous reliability and optimal performance of Jenkins.
How to configure
Open your web browser and navigate to your default Jenkins instance by logging in with your credentials.
Click on Manage Jenkins from the Jenkins dashboard. Then, select System from the options.
Scroll down to the System Message section. Enter a message in the text box provided, and this message will be displayed prominently on Jenkins’s main dashboard.
Optionally, configure the Extended Email Notification section to set up email notifications for system alerts.
Scroll down to the bottom of the page and click the Save button to apply the system configuration changes. Once the system introduces any issue, you can observe the alert notifications.
Job failure alerts
Description
Immediate notifications for job failures are crucial to facilitate a swift response and rapid issue resolution within Jenkins. These alerts provide instant notifications when a job fails, which is essential in maintaining the integrity of CI/CD pipelines.
By informing relevant stakeholders or administrators, job failure alerts enable quick identification and resolution of issues, minimizing downtime and ensuring the seamless flow of the development process. Essentially, they act as a proactive mechanism to uphold the reliability and effectiveness of Jenkins job executions.
How to configure
Open the Jenkins dashboard and navigate to the job for which you want to configure alerts by clicking New item.
Give a name for the job name and click the OK button to access its configuration page.
Inside the job configuration, find the Post-build Actions tab. Then, add a post-build action for Email Notification.
Configure the recipient’s email addresses and other notification settings.
Click the Save button to apply the job configuration changes. The E-mail alerts will be sent to the recipient’s email addresses when a build fails, becomes unstable, or returns to stable.
Troubleshooting Jenkins monitoring errors
Installing Prometheus plugin in Jenkins
This issue will appear when the necessary plugin for the Prometheus installation is either disabled or not installed in the Jenkins environment.
Failed to load - Build Failure Analyzer (2.0.0). Required plugin is disabled: Jenkins Apache HttpComponents Client 4.x API Plugin
Code language: CSS (css)
Solution
Confirm the presence of the required plugin in the Jenkins Plugin Manager. If not present, install it. If disabled, enable it. Restart Jenkins to apply changes. Ensure that the plugin version aligns with the Prometheus plugin’s compatibility requirements.
Scrutinize Jenkins logs for any messages related to plugin dependencies and their statuses. Verify that the Jenkins environment is configured correctly to support plugin dependencies.
Failed to execute Maven goal for Jenkins plugin
Failed To execute goal org.jenkins-ci.tools:maven-hpi-plugin:3.11:resolve-test-dependencies(default-cli) on project prometheus
Code language: CSS (css)
The Maven HPI (Jenkins Plugin) plugin is encountering an issue while trying to resolve test dependencies for the project named prometheus.
Solution
Please ensure the Jenkins plugin project contains the correct and current test dependencies, as declared in its pom.xml
file. Check for any mistakes or errors in the dependencies section of the pom.xml
. Ensure that the version specified for the maven-hpi-plugin
is suitable for the Jenkins plugin being developed.
Finally, run the mvn clean install
command to download all necessary dependencies and build the project.
Error reading Prometheus: No Route to Host
Failed to query Prometheus at http://192.168.x.133:9090/api/v1/query 5 - No route to host
Code language: JavaScript (javascript)
The cause for this error is when a network-related issue prevents the Jenkins server from reaching the Prometheus server, leading to a failure in querying metrics.
Solution
Investigate and address potential network connectivity problems between the Jenkins and Prometheus servers. Check for firewall restrictions, routing issues, or proxy configurations hindering communication.
Verify the operational status of the Prometheus server and its accessibility from the Jenkins server. Address any DNS resolution problems and consider using network diagnostic tools like traceroute or ping to pinpoint and resolve connectivity issues.
Jenkins Integration with Prometheus – 404 Not Found
Server returned HTTP status 404 Not Found for Prometheus integration with Jenkins
Code language: JavaScript (javascript)
When the configured URL for metrics scraping in either Jenkins or Prometheus is incorrect, or the specified endpoint is not exposing the expected metrics, this error will appear.
Solution
Thoroughly review and align the integration settings in both Jenkins and Prometheus. Verify that the URLs match and are accurately configured. Check for potential typos, trailing slashes, or port mismatches.
Ensure that Jenkins is appropriately configured to expose Prometheus metrics at the specified endpoint. Examine Jenkins logs for any anomalies related to metrics availability or Prometheus scraping.
Final thoughts on monitoring Jenkins
In conclusion, monitoring Jenkins is a multifaceted approach encompassing metrics and alerts. Organizations can ensure their Jenkins environments’ reliability, performance, and security by implementing these strategies and learning from real-world case studies. Continuous improvement, proactive monitoring, and the integration of best practices will contribute to the overall success of a Jenkins deployment in the dynamic landscape of DevOps.
Related articles
- Managing Jenkins jobs like a pro
- Creating Jenkins pipelines
- Declarative vs scripted pipelines
- Jenkins master-slave architecture
- How to integrate Jenkins with Git and SVN
- How to add credentials in Jenkins
Follow our blog
Be the first to know when we publish new content.
Jenkins monitoring tools
- Top 10 API Testing Tools - April 6, 2024
- The ABCs of UAT Testing: Understanding User Acceptance Testing - March 21, 2024
- Agile Testing: Key Principles and Practices - March 15, 2024