Struggling with filestats monitoring

I am trying to setup some filemonitoring for our stats server, to see what it can do.
We have different pollers that each generate rrd files in a directory under /prod/stats/data/rrd

Aim is to have a filegroup for each directory so you can for each filegroup say that the newest file in the dir is not older then let’s say an hour. I would prefer to generate my filegroups dynamically so if a new poller is setup, this part is not forgotten. It seems that mk_filestats is the better suited for this, so using that one.

According to the inline help, you can use %s as the group name for individual files, and also if the file is a dir it is processed recursively. From the configured rules I get the following filestats.cfg:

[DEFAULT]
subgroups_delimiter: @

[rrd %s]
input_patterns: /prod/stats/data/rrd/*
filter_regex: .*\.rrd
filter_regex_inverse: .*OLD

However, if I run a service discovery the %s seems to be ignored and I only get a service literally called ‘rrd %s’. Am I missing something in my config?

I understand what you are trying to achieve and it makes totally sense.
One file group per folder.
Dynamic, new folder should create a new filegroup on next service discovery.

I assumed that this must be possible with mk_filestate, but until now I was not able to get it working.
I am also interested in a solution, I keep you updated once I find one.

1 Like

reading this gave me a faint memory of something I had built a few years ago.
Note: this has very little documentation and I currently don’t have the time to support further changes but maybe it’s an inspiration for you :slight_smile:

I added a grouping feature for one customer project in version 2.1 that has since been unused.

Example config file with extra grouping
filestats.cfg.txt (877 Bytes)

patched mk_filestats, use at your own risk :slight_smile:
mk_filestats_custom_grouping.py.txt (25.9 KB)
which was derived from checkmk/agents/plugins/mk_filestats.py at v2.1.0p15 · Checkmk/checkmk · GitHub

1 Like

@mschlenker
I think CheckMK needs to improve the description of the ‘File Grouping’ option to help users understand how it can be used correctly.

1 Like

:eyes: @sebkir

Your turf.

2 Likes

@gstolz, thanks for sharing your patched version.
I compared it with the latest 2.4 and the code is still very much the same.

@akoopal, I just reviewed this issue and I now think the easiest would be to
just create the /etc/check_mk/filestats.cfg from time to time by cron.

Assume, you have a folder and file structure like this:

root@72dd784540ca:~# tree /folder/
/folder/
|-- A
|   |-- 1
|   |-- 2
|   `-- 3
|-- B
|   |-- 1
|   |-- 2
|   `-- 3
`-- C
    |-- 1
    |-- 2
    `-- 3

A,B,C are folder and 1,2,3 are files.

Now, with a script like this:

root@72dd784540ca:~# cat make-filestats-cfg.sh 
#!/usr/bin/env bash


find /folder/* -type d | sort \
| while read dir
do

cat<<EOT
[extremes of ${dir}]
input_patterns: ${dir}/*
output: extremes_only

EOT

done

you can create your “dynamic” /etc/check_mk/filestats.cfg

root@72dd784540ca:~# ./make-filestats-cfg.sh > /etc/check_mk/filestats.cfg

The resulting agent output is then:

root@72dd784540ca:~# /opt/omd/sites/mysite24/share/check_mk/agents/plugins/mk_filestats.py -c /etc/check_mk/filestats.cfg 


<<<filestats:sep(0)>>>
[[[extremes_only extremes of /folder/A]]]
{'type': 'file', 'path': '/folder/A/1', 'stat_status': 'ok', 'size': 4096, 'age': 797, 'mtime': 1754485116}
{'type': 'file', 'path': '/folder/A/2', 'stat_status': 'ok', 'size': 40960, 'age': 774, 'mtime': 1754485139}
{'type': 'file', 'path': '/folder/A/3', 'stat_status': 'ok', 'size': 409600, 'age': 781, 'mtime': 1754485132}
{'type': 'summary', 'count': 3}
[[[extremes_only extremes of /folder/B]]]
{'type': 'file', 'path': '/folder/B/2', 'stat_status': 'ok', 'size': 40960, 'age': 765, 'mtime': 1754485148}
{'type': 'file', 'path': '/folder/B/3', 'stat_status': 'ok', 'size': 409600, 'age': 765, 'mtime': 1754485148}
{'type': 'file', 'path': '/folder/B/1', 'stat_status': 'ok', 'size': 4096, 'age': 765, 'mtime': 1754485148}
{'type': 'summary', 'count': 3}
[[[extremes_only extremes of /folder/C]]]
{'type': 'file', 'path': '/folder/C/2', 'stat_status': 'ok', 'size': 40960, 'age': 763, 'mtime': 1754485150}
{'type': 'file', 'path': '/folder/C/3', 'stat_status': 'ok', 'size': 409600, 'age': 763, 'mtime': 1754485150}
{'type': 'file', 'path': '/folder/C/1', 'stat_status': 'ok', 'size': 4096, 'age': 763, 'mtime': 1754485150}
{'type': 'summary', 'count': 3}

KR mimimi

1 Like

@mimimi interesting approach. It would mean that I have to deploy the plugin without configuration from the bakery but that can be ok. I will look into this. The extremes_only is also handy.

That’s some heavy meta level here. :exploding_head: Totally love this approach, although it shows that we probably have to escalate filestats stuff to product management for the road maps of the next two years. :+1:

2 Likes

JFYI, I believe this is related filestats // Allow Adding dynamic subgroups based on regex-pattern by vafgoettlich · Pull Request #856 · Checkmk/checkmk · GitHub