Setting up the monitoring with the Prometheus server
This section explains, in the case of a Kubernetes deployment, how to use SonarQube Community Build's native integration with Prometheus to collect the Prometheus metrics.
Introduction
The SonarQube Community Build’s Helm chart triggers the deployment of a Prometheus server that will pull the metrics from the SonarQube Community Build instance. The deployment process is as follows:
- When you install the SonarQube Community Build’s Helm chart in the Kubernetes cluster, the chart creates a PodMonitor resource (
podmonitor.yaml
) which configures the pulling of metrics from SonarQube Community Build. - The Prometheus operator deploys a Prometheus server based on the created PodMonitor resource.
- The Prometheus server will pull the metrics from SonarQube Community Build according to the PodMonitor configuration. To pull the metrics from the Web API endpoint, it needs to authenticate to the Web API. (The Helm chart sets up the PodMonitor to use the Bearer authentication scheme.)
The figure below illustrates this process.
The Prometheus Operator must be installed in the Kubernetes cluster.
Monitoring setup roadmap
To set up the monitoring of SonarQube Community Build with the Prometheus server:
- Set up the authentication of the Prometheus server to the Web API’s monitoring endpoint.
- Enable the JMX Exporter.
- Configure the collection of the JMX metrics.
- Set up the export of the metrics to an observability platform. See the List of Prometheus metrics.
These steps are described below.
Setting up the Prometheus server authentication to the Web API endpoint
The PodMonitor needs to authenticate to the SonarQube Community Build’s Web API for getting metrics from the /api/monitoring/metrics
endpoint. To setup this authentication, you must define the monitoring password in values.yaml:
the Helm chart will store this value in the SONAR_WEB_SYSTEMPASSCODE
environment variable on SonarQube Community Build.
To setup the monitoring passcode in SonarQube Community Build, use one of the following methods (see also the Helm chart documentation):
- Define the passcode in the
monitoringPasscode
property within thevalues.yaml
file (default value is “define_it”).
For security reasons, this method is not recommended. - Use a secret that contains the passcode that will be retrieved at runtime, and define the following properties in
values.yaml
:monitoringPasscodeSecretName
: name of the secret object.monitoringPasscodeSecretKey
: key identifying the passcode to be extracted from the secret object.
Enabling the export of the JMX metrics
To expose the Prometheus JMX metrics, the JMX exporter must be enabled in the Helm chart configuration as follows:
- Add the following block in the
values.yaml
file of the SonarQube Community Build Helm chart:
Configuring the collection of the JMX metrics
By default, the SonarQube Community Buildv’s Helm chart does not collect the JMX metrics. If you want the Prometheus server to collect the JMX metrics, you must create and configure a PodMonitor resource that will be used by the Prometheus server to collect the JMX metrics.
In a future release of SonarQube Community Build, all metrics will be managed through the PodMonitor created by default by the Helm chart. At that point, this configuration step will no longer be necessary.
Proceed as follows:
- Create a
podmonitor.yaml
file (as illustrated below) and apply it to the Kubernetes cluster.
SonarQube Community Build Developer and Enterprise Editions, SonarQube Community Build
Was this page helpful?