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
- 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
-
Grafana dashboard: you can find 2s dashboard overview.json and dashboard details.json on this GitHub.
-
Generate a SonarQube token, you can reference https://docs.sonarqube.org/latest/user-guide/user-token/
-
How to start this exporter
-
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
-
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
-
-
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
-
Restart Prometheus and rebuild the project, and you can see the result in Grafana.
-
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
- Run SonarQube on Linux Docker with Mono to scan .NET 4.8 Code
- GitLab SonarQube Integration with .NET
- Use Grafana to Manage SonarQube KPI
- Use Grafana to Manage GitLab CI/CD Pipelines
- Use GitLab to do .NET 4.8 CI/CD
- GitLab Checkmarx CI/CD Integration
- GitLab Checkmarx SonarQube Integration