Monitoring Jenkins jobs with Grafana

Joonas Venäläinen
3 min readMar 25, 2020

--

Photo by Luke Chesser on Unsplash

This article demonstrates how to use Jenkins with InfluxDB plugin to monitor Jenkins jobs through Grafana. You can get the example repository from here. There isn’t any real application code in the repository as you can modify this example Jenkinsfile to your likings.

First clone the repository and use docker-compose to create the application stack:

docker-compose up -d

Jenkins & InfluxDB Setup

Navigate to http://localhost:8080. Jenkins is now asking for Administrator password. You can get it with:

docker logs <container_id>

You should see the password near the end. Paste the password and press next. Select the default option to install suggested plugins. When plugins are installed add your user details and initial Jenkins setup is done (You can leave the jenkins url as default).

Now we need to install the InfluxDB plugin. From the left press Jenkins and navigate to Manage Jenkins > Manage Plugins. Select the available tab and search for InfluxDB and install it without restart.

Next step is to configure the InfluxDB instance in Jenkins. Go to Manage Jenkins > Configure System and find InfluxDB targets there and add new target (You can find the db, username & password from compose file):

We did uncheck the Global Listener because we don’t want to trigger it on every project. We are defining the usage in pipeline along with the custom data that contains the job url.

Create new Multibranch pipeline project with name you want. Im using Test_Project for now. Add Git as branch source:

Now it scans through the repo and should find master branch. Now we can test that the InfluxDB plugin is working by running the job. If everything works as expected you should see this in job Console Output:

Grafana Setup

You can access Grafana in http://localhost:3005. Default username/password is admin/admin. You will be prompted to enter new password. Now click Add Datasource from the frontpage and select InfluxDB as source with these settings:

Go back to home and press new New Dashboard > Choose Visualisation and select Table. Click the Queries tab and change settings to these:

Add these column styles in the Visualization tab:

The ${__cell_3:raw} basically checks cell for value. In this case it check value from third cell. Now if you save the dashboard and click the build status you should be redirected to the build job page in Jenkins. So thats it for now. I suggest that you read the InfluxDB documentation for more information and use cases.

--

--