Use Grafana to Manage SonarQube KPI

Overview

Requirement

Usually we use SonarQube to check the KPI of projects:

You can also check the build history of a project:

Use Grafana to Manager SonarQube KPI

But there are some SonarQube exporters, they can export SonarQube's KPI to Grafana/Prometheus.

Solution 1

  1. Exporter: https://github.com/dmeiners88/sonarqube-prometheus-exporter: It's a SonarQube plugin, but it only supports 5 KPIs, and the last commit date is 2018/11/9. It supports SonarQube 7, not sure if it supports 8 or 9, I don't plan to try it.

Solution 2

  1. Exporter: https://github.com/nthienan/sonarqube-exporter

  2. Grafana dashboard: you can find 2s dashboard overview.json and dashboard details.json on this GitHub.

  3. Generate a SonarQube token, you can reference https://docs.sonarqube.org/latest/user-guide/user-token/

  4. How to start this exporter

    1. You can run this command directly:

      1docker run --expose 9102 -p 9102:9102 nthienan/sonarqube-exporter sqe -p 9102 --url http://sonar.x.x.x:9000 --user-token xxxxxxxxxxx --ignore-ssl-verification --log-level DEBUG
      
    2. If you use docker-compose, you can reference this docker-compose.yml

       1sonarqube-exporter:
       2container_name: sonarqube-exporter
       3image: nthienan/sonarqube-exporter
       4ports:
       5- 9102:9102
       6expose:
       7- 9102
       8command: ' sqe -p 9102 --url http://sonar.x.x.x:9000 --user-token xxxxxxxxxxx --ignore-ssl-verification --log-level DEBUG '
       9environment:
      10- TZ=Asia/Taipei
      11depends_on:
      12- sonarqube
      
  5. prometheus.yml

    1- job_name: 'sonarqube'
    2    scrape_interval: 5s
    3    metrics_path: '/metrics'
    4    static_configs:
    5    - targets: ['xxx.xxx.xxx.xxx:9102']
    

Result

  1. Restart Prometheus and rebuild the project, and you can see the result in Grafana.

  2. You can also check the detail dashboard, it contains more information like a build trend chart. The following is not a google sample, I'll update it in the future.

Posts in this Series