Skip to content

SonarQube plugin to export code quality metrics for Prometheus. Provides a /api/prometheus/metrics endpoint for scraping configurable SonarQube analysis data. Integrate SonarQube monitoring into your Prometheus setup and visualize with tools like Grafana for centralized code quality visibility. Adopted from github.com/dmeiners88/sonarqube-pro

License

Notifications You must be signed in to change notification settings

DomGiorda/sonar-metrics-exporter

Sonarqube Prometheus Exporter

Prometheus Exporter Plugin for SonarQube.

FeaturesRequirementsInstallationUsageMetricsScreenshots

Features

  • Configure which metrics to export

Requirements

Supported SonarQube versions (compatibility)

SonarQube version Notes
9.x Supported (stable) — builds against plugin API 9.4.x for broad compatibility
10.8 Supported — tested compilation against SonarQube 10.8 artifacts
25.10 Supported — tested for compatibility with SonarQube 25.10

If you need to target a specific SonarQube runtime, check pom.xml properties (sonar.apiVersion and sonar.pluginApiVersion) and build accordingly.

Installation

  1. Download latest snapshot release
  2. Drop sonar-prometheus-exporter-1.0.0-SNAPSHOT.jar into $SONARQUBE_HOME/extensions/plugins.
  3. Restart the SonarQube server.

Usage

  1. Configure which metrics you want to export under Administration → Configuration → General Settings → Prometheus Exporter
  2. Add a scrape config to your Prometheus instance similar to this:
scrape_configs:
  - job_name: 'sonarqube'
    metrics_path: '/api/prometheus/metrics'
    static_configs:
      - targets: ['localhost:9000']
  1. Alternatively, point your HTTP client to http://localhost:9000/api/prometheus/metrics
  2. You can export the dashboard from this file:
  resources/grafana_dashboard.json
  1. Prometheus configuration examples

Prometheus configuration examples are available under ./resources/prometheus/ in this repository (for example ./resources/prometheus/prometheus.yml). If you used the docker-compose.yml in the repo root, a sample Prometheus config is also provided at ./prometheus/prometheus.yml.

Metrics

  1. Which metrics can you export? This section outlines the key metrics related to code quality and analysis that can be exported from SonarQube. The exporter also adds a severity label when severity-specific metrics are detected (for example BLOCKER, CRITICAL, MAJOR, MINOR, INFO). This allows filtering in Grafana/Prometheus using the severity label (e.g. sonarqube_vulnerabilities{severity="CRITICAL"}).
  • NCLOC: Stands for Non-Commented Lines of Code, representing the actual lines of source code excluding comments and blank lines.
  • BUGS: Identifies coding errors that can lead to unexpected behavior or runtime issues.
  • VULNERABILITIES: Highlights security weaknesses in the code that could be exploited.
  • CODE_SMELLS: Points out maintainability issues that make the code harder to understand, modify, or extend.
  • COVERAGE: Measures the percentage of code lines, branches, or conditions exercised by automated tests.
  • TECHNICAL_DEBT: An estimation of the effort required to fix all Code Smells and maintainability issues, often expressed in time.
  • COMPLEXITY: Typically refers to Cyclomatic Complexity, which measures the number of independent paths through the code, indicating how difficult it is to test and understand.
  • LINES_TO_COVER: The number of executable lines of code that could potentially be covered by tests.
  • VIOLATIONS: A general term referring to any instance where the code breaks a defined quality rule (encompassing Bugs, Vulnerabilities, and Code Smells).
  • ALERT_STATUS: Indicates the overall quality gate status of the project (e.g., Passed or Failed), based on predefined conditions for key metrics.
  • SECURITY_HOTSPOTS: Highlights security-sensitive pieces of code that require manual review to determine if a vulnerability exists.
  • DUPLICATED_LINES: Shows the percentage or number of code lines that are identical or very similar to other code blocks, often indicating a need for refactoring.
  • LINES: Show the total count of lines in your project.

Screenshots

Configuration Page Prometheus Example Grafana Dashboard

About

SonarQube plugin to export code quality metrics for Prometheus. Provides a /api/prometheus/metrics endpoint for scraping configurable SonarQube analysis data. Integrate SonarQube monitoring into your Prometheus setup and visualize with tools like Grafana for centralized code quality visibility. Adopted from github.com/dmeiners88/sonarqube-pro

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages