Monitoring Folder Size

Dear CheckMK Community,

I would like to monitor the size of a folder (NOT the files inside the folder).
The folder is a Cache-Folder for NGINX Imaginary.

I tried to achieve this with the rule Count, size and age of files - mk_filestat (Linux)

Rule Settings

Service output

As you can see, I do have a file group service showing me the largets, smallest, oldest and newest file.
These information are not what I needed, though.
Is there a way to monitor the size of a folder?
Am I missing a rule / did I use the wrong rule for this?

I tried using Output aggregation: single file (in Linux, everything is a file, right? So I thought the folder might be seen as a single file) but this does not work as the CheckMK Agent would complain about multiple files when using the “single file” setting.

Info about Setup
CheckMK Server: CheckMK CEE v2.0.0 on Ubuntu 20.04
Monitored Host: Ubuntu 20.04

Thank you for reading and helping :slight_smile:

Greetings,
pixelpoint

Hi,

i found this mkp dir-size on exchange.checkmk.com . It is pretty old but mentions that there is a new package here github.com HeinleinSupport

I installed dir_size-4.1.mkp.

This gives me a new agent plugin
image

I think this is what you are looking for?

best regards
Michael

This is exactly what I am looking for.
Thank you very much.

Though neither the plugin itself nor the configuration file are deployed
When deploying with Agent Bakery, the Bakery lists the Plugin for deployment.
Agent is signed, Hashes are the same (installed agent and agent in bakery).

After deploying the plugin, there is no dir_size Plugin in /usr/lib/check_mk_agent/plugins/
There is also no dir_size.cfg in /etc/check_mk/

Did I do something wrong while installing the plugin?
I downloaded the .MKP File and installed it via GUI.

Files seem to be installed correctly.

OMD[mysite]:~$ find -name "*dir_size*"
./var/check_mk/precompiled_checks/local/dir_size
./var/check_mk/packages/dir_size
./local/share/check_mk/web/plugins/wato/check_parameters_dir_size.py
./local/share/check_mk/web/plugins/wato/agent_bakery_dir_size.py
./local/share/check_mk/web/plugins/metrics/dir_size.py
./local/share/check_mk/agents/bakery/dir_size
./local/share/check_mk/agents/plugins/dir_size
./local/share/check_mk/checks/dir_size
./local/share/check_mk/checkman/dir_size
./tmp/check_mk/check_includes/local/dir_size
OMD[mysite]:~$ mkp list
dir_size
OMD[mysite]:~$ mkp show dir_size
Package file:                  /omd/sites/mysite/var/check_mk/packages/dir_size
Name:                          dir_size
Version:                       4.1
Packaged on Checkmk Version:   1.6.0p2
Required Checkmk Version:      1.6.0
Valid until Checkmk version:   No version limitation
Title:                         Directory size Monitor
Author:                        Robert Sander <r.sander@heinlein-support.de>
Download-URL:                  https://github.com/HeinleinSupport/check_mk/tree/master/dir_size
Files:                         agents(2) checkman(1) checks(1) web(3)
Description:
  Monitor directory sizes

based on dir_size by Bastian Kuhn

It refers CheckMK 1.6.0p2 and 1.6.0, though and the last Github Update seems to be from 2 years ago.

I guess it just doesn’t work with CheckMK 2.0 anymore?

I tried testing the plugin manually (moving dir_size to the server and creating dir_size.cfg)
The Plugin itself seems to work and returns the correct folder size.

The question is now:
Why does CheckMK not deploy the plugin even though everything seems to be fine?

After digging around a bit, I found the reason for the check not being distributed alongside the agent:

cmk --debug --force -v -A HOSTNAME

HOSTNAME...Found no Python 2 version for cmk_update_agent.py, deploying with Python 3 support only.linux_deb:baking...ERROR
Traceback (most recent call last):
  File "/omd/sites/mysite/bin/cmk", line 92, in <module>
    exit_status = modes.call(mode_name, mode_args, opts, args)
  File "/omd/sites/mysite/lib/python3/cmk/base/modes/__init__.py", line 69, in call
    return handler(*handler_args)
  File "/omd/sites/mysite/lib/python3/cmk/base/modes/cee.py", line 61, in mode_bake_agents
    agent_bakery.bake_agents_for_wato_mode(options, hostnames)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1701, in bake_agents_for_wato_mode
    _do_bake_agents(options=options, host_names=args)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1718, in _do_bake_agents
    AgentBakery(
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1292, in bake_agents
    self._bake_agents_for_host(hostname, bakelet_cache)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1426, in _bake_agents_for_host
    AgentBaker(warnings_buffer=self._warnings_buffer,
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1528, in bake
    self._bake_agent_for_platform(self._hostname, platform)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1553, in _bake_agent_for_platform
    self._update_package(hostname, agent_package_path, platform)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1602, in _update_package
    self._make_package_files(agent_package_path, platform)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1622, in _make_package_files
    self._execute_bake_function(platform, package_path)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 1651, in _execute_bake_function
    builder_lookup[platform](warnings_buffer=self._warnings_buffer,
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 371, in build
    files_root = self._ensure_files()
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 391, in _ensure_files
    self._place_files(files_root)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 451, in _place_files
    self._create_unix_agent_pre_17_plugin_files(files_root)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 475, in _create_unix_agent_pre_17_plugin_files
    self._create_pre_17_plugin_files(conf_dir, plugins_dir)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 407, in _create_pre_17_plugin_files
    self._execute_pre_17_bakery_plugin(name, conf_dir, plugins_dir)
  File "/omd/sites/mysite/lib/python3/cmk/base/cee/bakery/agent_bakery.py", line 426, in _execute_pre_17_bakery_plugin
    bake_func(**func_args)
  File "<string>", line 21, in bake_dir_size
NameError: name 'shutil' is not defined

I searched for the last mentioned file <string> but to no avail.

Does anybody know what’s wrong here?
NameError: name 'shutil' not defined sounds like CheckMK does not find shutil?
When I start a python3 shell with python3 and issue import shutil there is no error, so python3 knows about shutil but CheckMK doesn’t?

Or is something wrong with the check itself?

[EDIT]
Also, CheckMK Agent Bakery shows that something is wrong with the agent after baking.

Agent with dir_size
Screenshot_20210330_134132
(you can also see the Linux Agent DEB Package is missing here)

Agent without dir_size
Screenshot_20210330_134247

If you search inside you “~/local/” structure with a grep for “bake_dir_size” you should find a file with this bake function. This function uses the “shutil” but this must be included a different way as before or changed.

Thank you for replying.

After some testing, it seems like the Plugin is just not fit for Python3 anymore.

If I change the file to include import shutil that part works, but I get another error about something like “PosixPath and Strings cannot be concatenated”.
After fixing this by converting the PosixPath to a string, more and more errors pop up.

Thank very much you anyway.

PS:
Is there a way to edit my initial post to show [SOLVED]?
I cannot edit that post anymore :frowning:

PPS:
I can only mark 1 Post as SOLUTION, so I’d like to point out that

pointed me in the right direction.

Yes conversion from Python 2 to 3 can be a little bit more for the agent bakery parts.
The normal check itself is not so difficult.

I can edit the title but you can mark your post or any other post as solution then the thread is also marked as “solved” :wink:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.