Monitoring Jenkins with Grafana and Prometheus

Mohamed Saeed
3 min readDec 24, 2018

--

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.

Dashboard can contain statistics about failed and success jobs numbers, JVM memory, CPU utilization and more!!

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:

  • 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:8086”
  • 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.
  • You can visit Grafana’s website for more info about how to create more panels.

--

--