Skip to main content

Show Jenkins Build Metrics on Grafana Using InfluxDB

  • Install InfluxDB - Here's the link for how to install influxdb on AWS EKS - https://devopsautomationblogs.blogspot.com/2020/04/install-influxdb-on-aws-eks-using-helm.html

  • Configure InfluxDB for jenkins build metrics collection

    Go inside the influxdb pod and Run below 2 commands
                        
    kubectl exec -it -n influxdb influxdbPodName /bin/bash    
    
    influx                                                          # open influx database
    CREATE DATABASE jenkins_db                                      # create jenkins database
    CREATE USER jenkins WITH PASSWORD 'admin' WITH ALL PRIVILEGES   # create jenkins username
                            
                    
  • Install Grafana - Here's the link for how to install influxdb on AWS EKS - https://devopsautomationblogs.blogspot.com/2020/04/install-grafana-on-aws-eks-using-helm.html

  • Configure Grafana

    1. Add influxDB datasource

      Click on Settings (left side) > Data Sources > Add data source > Search & Select "InfluxDB" >
      Name: InfluxDB
      HTTP > URL: InfluxDB URL - How to get kubectl get svc -n influxdb
      InfluxDB Details >
      Database: jenkins_db
      User: jenkins
      Password: admin
      HTTP Method: Get
      Save & Test - This will test the connection and save the datasource.

    2. Import already available jenkins grafana dashboard

      Click on + sign (create) > Import > write id "10557" in "Grafana.com Dashboard" > it'll automatically load the dashboard:
      Name: Choose or keep the name as is
      Folder: Default will be created in General folder, however for our configuration create new named Jenkins
      InfluxDB: Select the datasource added in previous step
      Import

    3. As per this dashboard's plugin usage, we need to install 2 plugins in grafana

      Go inside the Grafana pod, Run below 2 commands and Delete the pod to Restart the Grafana service. Data will be persisted because we've used AWS EBS in Grafana installation process.
                                  
      kubectl exec -it -n grafana grafanaPodName /bin/bash    
      
      grafana-cli plugins install grafana-piechart-panel
      grafana-cli plugins install btplc-trend-box-panel
      exit
      
      kubectly delete po -n grafana grafanaPodName
                                      
                              
    4. In order to get the data from influxdb, we need to change the Query in dashboard configurations, For this
      Home > Select the dashboard created in 2nd step > Click on "Dashboard Settings"(Top right side) > Variables > Delete any one variable from out of 2 there > In remaining one variable > Change the query to "select project_path from jenkins_data" > Save > Save Dashboard

    5. We need to change the query for all metrics panel on the dashboard, which I've already done. Copy entire json from https://github.com/JaydeepUniverse/automation/blob/master/grafanaJenkinsJSON.json and paste it in Home > Select the dashboard created in 2nd step > Click on "Dashboard Settings"(Top right side) > JSON Model > Save Dashboard

  • Configure Jenkins
    1. Install Plugin - InfluxDB and Restart Jenkins
    2. Manage Jenkins > Configure System > Search for InfluxDB > Add Target >

      Description: influxdb-monitoring - This name we will going to use to send the build metrics to InfluxDB
      URL: InfluxDB URL - How to get kubectl get svc -n influxdb
      Username: jenkins
      Password: admin
      Database: jenkins_db
      Apply & Save the configurations
    3. Configure job to use this configuration
      • FreeStyle Job > Cofigure > Add Post-Build action > select "Publish build data to InfluxDB" > there provide Description name configured in previous step - "influxdb-monitoring" > save the configuration
        Next time when job will run it will send the data to influxdb

      • Declarative Pipeline Job - Add below syntax in Jenkinsfile
                                     
        post{
            always{
                script{
                    try {
                        if (currentBuild.result == null) {
                            currentBuild.result = 'SUCCESS'
                        }
                    } catch (err) {
                        if (currentBuild.result == null) {
                            currentBuild.result = 'FAILURE'
                        }
                        throw err
                    } finally {
                        influxDbPublisher selectedTarget: 'influxdb-monitoring'
                    }
                }
            }
        }                            
                                     
                                 
        Next time when job will run it will send the data to influxdb

  • Voila!! Go to Grafana UI, Check for the metrics and Dashboard visualization.

    This dashboard is really eye catchy!!

Below are screenshot taken from Grafana dashboard.

Comments

Popular posts from this blog

How to skip resources, compiler, surfire, install plugin in maven's default build process

When we want to use maven command line to upload zip type artifact to artifact repository then we don't want resources, compiler, surefire, install phases in maven process, only assembly would be enough. To skip particular phases go to each plugin's original website phase according to latest running plugin version download the same to our own project refer the skip phase configuration of particular phase, either it can be done command line or as part of the build-plugin-configuration. Example using POM.xml file <project> [...] <build> <plugins> <plugin> <groupId...

Install AWS CLI on Ubuntu localhost using Ansible Playbook

Install AWS CLI on Ubuntu localhost using Ansible Playbook --- - hosts: localhost tasks: - name: Installing Unzip package package: name: unzip state: present when: ansible_facts['os_family'] == "Debian" become: true - name: Create awscli directory in home directory file: path: ~/awscli state: directory mode: '0755' - name: Download bundled installer zip file get_url: url: https://s3.amazonaws.com/aws-cli/awscli-bundle.zip dest: ~/awscli/awscli-bundle.zip - name: Extract zip file unarchive: src: ~/awscli/awscli-bundle.zip dest: ~/awscli - name: Run install command shell: /home/ubuntu/awscli/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws become: true Same script is also avail...

How to give permission to particular user to particular dir. or file in Linux

Permission error: ubuntu@ip-192-168-62-113:~/bbb/testing$ ls -ltrh total 4.0K -rwx------ 1 ubuntu ubuntu 70 Mar 18 09:43 test.sh ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo su - abc abc@ip-192-168-62-113:~$ cat /home/ubuntu/jaydeep/testing/test.sh cat: /home/ubuntu/bbb/testing/test.sh: Permission denied Command - how to give permission to particular user to particular dir. or file ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo setfacl -m u:abc:r test.sh ubuntu@ip-192-168-62-113:~/bbb/testing$ sudo su - abc abc@ip-192-168-62-113:~$ cat /home/ubuntu/bbb/testing/test.sh #!/bin/bash read -p "What is your name? " name echo "Welcome $name!" For the Directory setfacl -m u:userID:rwx /dir/subdir/ setfacl -m u:userID:rwx /d...