Analyze performance issues with Checkmk profiling
Use profiling to identify performance bottlenecks when pages or views in the Checkmk user interface are slow to load.
LAST TESTED ON CHECKMK 2.5.0P1
GUI Profiling
You can profile the rendering of pages in the Checkmk user interface to determine which parts of a request consume the most processing time.
Enable profiling in Checkmk
Go to:
Setup → General → Global Settings → User Interface → Profile Request
Do not use Enable profiling for all requests. This option profiles requests indiscriminately and may not capture the request you actually want to investigate.
.
.
Modify the URL of the page you want to profile by adding &_profile=1, and then submit the request in your browser.
Example:
http://localhost/mysite/check_mk/view.py?view_name=allhosts&_profile=1
After the request has been processed, two files are created in $OMD_ROOT/var/check_mk/:
multisite.profilemultisite.py
Example:
root@mylinuxhost:/opt/omd/sites/mysite/var/check_mk~$ ls -lah |grep multisite
-rw-rw---- 1 mysite mysite 100246 Nov 6 13:35 multisite.profile
-rwxr-xr-x 1 mysite mysite 155 Nov 6 13:35 multisite.py*The profiling data for the processed page is stored in multisite.profile.
Analyze the profiling data with SnakeViz
SnakeViz is a browser-based viewer for Python profiling data.
The following examples use uv to run SnakeViz. uv is a Python package and tool manager that can run command-line tools in isolated environments. Other methods of installing and running Python tools can also be used.
If uv is not already installed, follow the official uv installation instructions. Depending on your operating system, uv may also be available through your distribution's package manager.
After installation, verify that uv is available:
linuxuser@mylinuxhost:~$ uv --version
To analyze multisite.profile, first copy it outside the Checkmk site, for example to /tmp, and change its ownership to your Linux user:
linuxuser@mylinuxhost:~$ sudo cp multisite.profile /tmp/
linuxuser@mylinuxhost:~$ sudo chown linuxuser:linuxuser /tmp/multisite.profile
Change to the directory containing the profile:
linuxuser@mylinuxhost:~$ cd /tmp
You can run SnakeViz once without installing it permanently:
linuxuser@mylinuxhost:~$ uvx snakeviz multisite.profileuvx runs the tool in an isolated environment without requiring a permanent installation.
If you use SnakeViz regularly, you can instead install it as a persistent tool:
linuxuser@mylinuxhost:~$ uv tool install snakeviz
Then run:
linuxuser@mylinuxhost:~$ snakeviz multisite.profileSnakeViz opens the profiling data in your browser, where you can analyze which parts of the request consume the most time.
Profiling via cli
The cmk commands have an option to enable profiling.
To display the profiling option:
OMD[mysite]:~$ cmk | grep profile
--profile Enable profiling mode
The profile files are created in the current directory. For example, change to the site's tmp directory and profile a cmk command:
OMD[mysite]:~$ cd tmp
OMD[mysite]:~/tmp$ cmk -Afv --profileNote: This command triggers agent baking via the CLI and is only an example. Profiling works with all cmk commands.
This creates two files:
OMD[mysite]:~/tmp$ ls | grep profile
profile.out
show_profile.py
Analyze the profiling data
To analyze the profiling data, copy profile.out outside the Checkmk site, for example to /tmp:
OMD[mysite]:~/tmp$ cp profile.out /tmp/
If necessary, change its ownership to your Linux user:
linuxuser@mylinuxhost:~$ sudo chown linuxuser:linuxuser /tmp/profile.out
Then change to /tmp:
linuxuser@mylinuxhost:~$ cd /tmp
Run SnakeViz without installing it permanently:
linuxuser@mylinuxhost:/tmp$ uvx snakeviz profile.out
If you installed SnakeViz permanently with uv tool install snakeviz, run:
linuxuser@mylinuxhost:/tmp$ snakeviz profile.out
Profile a Checkmk function
You can also profile an individual function in your custom Checkmk code, such as a plugin.
Example:
from cmk.utils.profile import profile_call
.....
@profile_call("/tmp/myprofile_dir")
def my_func_to_profile(self):
print("ding dong")The resulting profiling data can then be analyzed using the profiling tools described above.
Network analysis with the web browser
Start the Network Monitor by opening your browser's developer tools:
Ctrl + Shift + I
For browser-specific instructions, refer to:
For Firefox, follow this manual: Firefox Network Analyzer
For Google Chrome, follow this manual: Chrome Network Analyzer
Reload the slow or crashing view and save or export the network data as a .har file. Submit this file to Checkmk Support when requested.
Slow views
Note: This option is only available in Checkmk 2.2 or later.
Some built-in or custom views may take longer than expected. To detect slow views, set the log level to DEBUG at:
Setup > General > Global settings > User interface > Log levels > Slow views
Set a threshold in seconds at:
Setup > General > Global settings > User interface > Threshold for slow views
The logging is disabled by default. The default threshold is set to 60 seconds.
If enabled, one log entry per view rendering that exceeds the configured threshold is logged to:
~/var/log/web.log
A slow-view log entry contains information about the view and its rendering performance, including the time spent fetching, filtering, and rendering rows.
Example:
2023-10-05 14:01:02,467 [10] [cmk.web.slow-views 783147] View name: logfile, User: cmkadmin, Row limit: None, Limit type: none, URL variables: ['csrf_token=deaacdae-e2ad-47bb-a497-8a41c4f5e378',
'filled_in=filter', 'is_log_notification_phase=-1', 'limit=none', 'logclass0=on', 'logclass1=on', 'logclass2=on', 'logclass3=on', 'logclass5=on', 'logclass8=on', 'logst_h0=on', 'logst_h1=on',
'logst_h2=on', 'logst_s0=on', 'logst_s1=on', 'logst_s2=on', 'logst_s3=on', 'logtime_from=400', 'logtime_from_range=86400', 'logtime_until_range=3600', 'view_name=logfile', '_show_filter_form=1'],
View context: {'optservicegroup': {'optservice_group': '', 'neg_optservice_group': ''}, 'siteopt': {'site': ''}, 'log_class': {'logclass0': 'on', 'logclass1': 'on', 'logclass2': 'on', 'logclass3':
'on', 'logclass4': '', 'logclass5': 'on', 'logclass6': '', 'logclass8': 'on'}, 'log_notification_phase': {'is_log_notification_phase': '-1'}, 'hostregex': {'host_regex': ''}, 'serviceregex':
{'service_regex': ''}, 'opthostgroup': {'opthost_group': '', 'neg_opthost_group': ''}, 'logtime': {'logtime_from': '400', 'logtime_until': '', 'logtime_from_range': '86400', 'logtime_until_range': '3600'},
'log_state': {'logst_h0': 'on', 'logst_h1': 'on', 'logst_h2': 'on', 'logst_s0': 'on', 'logst_s1': 'on', 'logst_s2': 'on', 'logst_s3': 'on'}, 'wato_folder': {'wato_folder': ''}}, Unfiltered rows:
24783, Filtered rows: 24783, Rows after limit: 0, Duration fetching rows: 0.69s, Duration filtering rows: 0.00s, Duration rendering view: 18.44s, Rendering page exceeds 3s: 19.21s