Monitoring Jenkins with Grafana and Prometheus

Pranav T P
4 min readOct 18, 2021

In this article I will show you how to configure Prometheus and Grafana to monitor your Jenkins server and create a such wonderful dashboard. A dashboard that contains lots of information and statistics about your Jenkins server.

What is Jenkins?

Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.

What is Prometheus?

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.

What is Grafana?

Grafana is an open-source, nightly built dashboarding, analytics, and monitoring platform that is tinkered for connection with a variety of sources like Elasticsearch, Influxdb, Graphite, Prometheus, AWS Cloud Watch, and many others.

We will use docker containers to get our servers up and running. We will create Jenkins, Prometheus and Gravana containers. Then export data from Jenkins passing it to Prometheus then to Gravana.

Getting started:

In this step we will create the three docker containers. If you have your servers up and running you can skip this step.

docker run -d --name jenkins -p 8080:8080 -p 50000:50000 jenkins
docker run -d --name prometheus -p 9090:9090 prom/prometheus
docker run -d --name grafana -p 3000:3000 grafana/grafana

Install necessary plugin in Jenkins:

Install necessary plugin in Jenkins:

  • If this your time using Jenkins, you can have a look at their documentations here.
  • Go to “manage Jenkins” then “manage plugins” and install “ Prometheus metrics plugin”.
  • This plugin will expose an endpoint (default /prometheus) with metrics where a Prometheus Server can scrape data.
  • You can see the output of this plugin visiting this URL
    “http://Jenkins_HOST:PORT/prometheus”

Configure Prometheus to scrape metrics from Jenkins:

  • To configure Prometheus server you will need to edit in the configuration file “prometheus.yml” inside the container.
  • In the scrape_configs part you need to add a job for Jenkins server:
- job_name: ‘jenkins’
metrics_path: /prometheus
static_configs:
- targets: [‘Jenkins_Host:PORT’]
  • Replace “Jenkins_Host” and “PORT” with the URL of your Jenkins server then restart the server.

If you are using docker container, you can only restart the container.

  • This is how Prometheus looks like:
You can visit prometheus server on “localhost:9090”
  • Beside “Execute” button there is a drop down menu that contains all metrics. You will find some metrics start with “Prometheus_*” which Prometheus uses to monitor itself. You will also find some starting with “Jenkins_*” and “vm_*” and those are representing data related to Jenkins server. You can spend sometime exploring these metrics.
  • We will use those metrics later in Grafana server.

Connect Prometheus with Grafana:

  • Go to Grafana server <localhost:3000> and login. The default user and password are “admin/admin”
  • From “ Home Dashboard” click on “add data source” then click on “Prometheus”.
  • In the URL field enter Prometheus URL in our case <prometheus_container_id:9090>. you can leave all other fields to default. Then click save and test.
  • Now you are ready to create your dashboard.

Create a dashboard in Grafana to display data:

  • From “ Home Dashboard” click on “new dashboard”. Choose the panel type that you want. We will use “Singlestat”.
  • Click on “Panel Title” then “edit”.
  • In the query section you can provide the metrics from Prometheus server. Let’s take “jenkins_plugins_active” as an example.
  • Save and go back to your dashboard.
  • Now you have a dashboard with only one panel that represent one piece of information about Jenkins. You can add as many panels as you want to create your own dashboard.

This is how Grafana Dashboard looks like:

Monitoring Jenkins
  • You can visit Grafana’s website for more info about how to create more panels.

--

--

Pranav T P

I'm a Pranav T P. pursuing my Master (Mtech) at PES University, Banglore in a stream of Cloud Computing