Monitoring your SonarQube instance is key to keeping it healthy and having happy users.
As a start, you can use this Web API to get an overview of the health of your SonarQube installation:
The SonarQube application server consists of three main Java processes:
- Compute Engine
- Web (including embedded web server)
Each of these Java processes has its own memory settings that can be configured in the
<SONARQUBE_HOME>/conf/sonar.properties file. The default memory settings that ship with SonarQube are fine for most instances. If you are supporting a large SonarQube instance (more than 100 users or more than 5,000,000 lines of code) or an instance that is part of your continuous integration pipeline, you should monitor the memory and CPU usage of all three key Java processes on your instance, along with overall disk space. Monitoring will allow you to see if any of the processes is running short of resources and take action ahead of resource shortages. There are numerous monitoring tools available, both open-source and commercial, to help you with this task. SonarSource does not recommend or endorse any particular tool.
You may need to increase your memory settings if you see the following symptoms:
- Your monitoring tools show one or more of the SonarQube processes is reaching its memory limit.
- Any of the SonarQube processes crashes and/or generates an out-of-memory error in the sonar.log file.
- A SonarQube background task fails with an out-of-memory error in the background task log.
- The store size of the Issues index of your Elasticsearch instance (visible in the System Info) is greater than or equal to the memory allocated to the Elasticsearch Java process.
You can increase the maximum memory allocated to the appropriate process by increasing the
-Xmx memory setting for the corresponding Java process in your
|Java Process||SonarQube Property||Notes|
|Elasticsearch||It is recommended to set the min and max memory to the same value to prevent the heap from resizing at runtime, which diverts JVM resources and can greatly increase response times of in-flight requests.|
-Xmx parameter accepts numbers in both megabytes (e.g.
-Xmx2048m) and gigabytes (e.g.
-Xmx2G). The metric suffix is case-insensitive.
The SonarQube Server offers visibility about what happens internally through the exposure of JMX MBeans.
In addition to the classical Java MBeans providing information about the ClassLoader, OS, Memory, and Threads you have access to three more MBeans in the SonarQube Server:
All these MBeans are read-only. It's not possible to modify or reset their values in real time.
|ProcessingTime||The measure the time (in ms) spent processing background tasks since the last restart of SonarQube. Its value will always increase and will be reset by a restart of SonarQube. This measure is very powerful when combined with SuccessCount and ErrorCount measures to get the average time to handle a Background Task, or when used to understand how much time the SonarQube Server is spending during a day handling Background Tasks. It gives you an indication of the load on your server.|
|ErrorCount||The number of background tasks that failed since the last restart of SonarQube.|
|PendingCount||The number of background tasksThe number waiting to be processed since the last restart of SonarQube. This measure is the same for all Compute Engine workers since Background Tasks are waiting in a common queue.|
|InProgressCount||The number of background tasks currently processing. Its value is either 1 or 0, since SonarQube can process only one task at a time.|
|SuccessCount||The number of background tasks successfully processed since the last restart of SonarQube.|
|WorkerCount||The number of background tasks that can be processed at the same time.|
|PendingTime||The amount of time (in ms) that the oldest background task has been waiting to be processed. This measure, together with PendingCount, helps you know if analyses are stacking and taking too long to start processing. This helps you evaluate if it might be worth configuring additional Compute Engine workers (Enterprise Edition) or additional nodes (Data Center Edition) to improve SonarQube performance.|
Note that the total number of background tasks handled since the last restart of SonarQube is equal to SuccessCount + ErrorCount. Also, all values will reset to their default values after restarting SonarQube.
|MigrationStatus||Possible values are: |
|PoolActiveConnections||Number of active database connections|
|PoolIdleConnections||Number of database connections waiting to be used|
|PoolInitialSize||Initial size of the database connections pool.|
|PoolMaxActiveConnections||Maximum number of active database connections|
|PoolMaxIdleConnections||Maximum number of database connections waiting to be used|
|PoolRemoveAbandoned||Possible values : |
|LogLevel||Log Level: INFO, DEBUG, TRACE|
|ServerId||SonarQube Server ID|
There is nothing to activate to view SonarQube MBeans if your tool is running on the same server as the SonarQube Server.
Here are examples of configurations to activate remote access to JMX MBeans.
For the WebServer:
For the ComputeEngine, there is no specific
javaAdditionalOpts entry, simply amend
Note: You should apply
chmod 600 or
400 on the file
jmxremote.password, for security reasons.
You can monitor your SonarQube instance using SonarQube's native integration with Prometheus. Through this integration, you can ensure your instance is running properly and know if you need to take action to prevent future issues.
Prometheus monitors your SonarQube instance by collecting metrics from the
/api/monitoring/metrics endpoint. Results are returned in OpenMetrics text format. See Prometheus' documentation on Exposition Formats for more information on the OpenMetrics text format.
Monitoring through this endpoint requires authentication. You can access the endpoint following ways:
Authorization:Bearer xxxxheader: You can use a bearer token during database upgrade and when SonarQube is fully operational. Define the bearer token in the
sonar.propertiesfile using the
X-Sonar-Passcode: xxxxxheader: You can use
X-Sonar-passcodeduring database upgrade and when SonarQube is fully operational. Define
sonar.propertiesfile using the
- username:password and JWT token: When SonarQube is fully operational, system admins logged in with local or delegated authentication can access the endpoint.
For more information on deploying SonarQube on Kubernetes:
© 2008-2023, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution-NonCommercial 3.0 United States License. SONARQUBE is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners.