Skip to content

Commit 4cb49cd

Browse files
committed
refactor(fs-inodes): improve code
1 parent 4ffb0ac commit 4cb49cd

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Build, CI/CD:
3838
Monitoring Plugins:
3939

4040
* fail2ban: be a bit more verbose in case everything is ok
41+
* fs-inodes: improve code
42+
* icinga-topflap-services: increase default warning level from 5 to 7
4143
* php-status: bz2 and curl are no default modules
4244

4345

check-plugins/fs-inodes/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Check fs-inodes
44
Overview
55
--------
66

7-
Checks the percentage of inode space used. To do this, this plugin fetches a list of local devices that are in use and have a filesystem on them. Filesystems that do not report inode usage are skipped.
7+
Checks the percentage of inode space used. To do this, this plugin fetches a list of local devices that are in use and have a filesystem on them. Filesystems that do not report inode usage (e.g. btrfs) are skipped.
88

9-
If you get an alert, use `find $MOUNT -xdev -printf '%h\n\' | sort | uniq -c | sort -k 1 -n | tail -n 10` to find where inodes are being used. This prints a top 10 list of directories prefixed with the number of files (and subdirectories).
9+
If you get an alert, use `find $MOUNT -xdev -printf '%h\n' | sort | uniq --count | sort --key=1 --numeric-sort --reverse | head -n 10` to find where inodes are being used. This finds the 10 directories under $MOUNT that have the most files inside them.
1010

1111

1212
Fact Sheet

check-plugins/fs-inodes/fs-inodes

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def parse_args():
4040
parser.add_argument(
4141
'-V', '--version',
4242
action='version',
43-
version='{0}: v{1} by {2}'.format('%(prog)s', __version__, __author__)
43+
version=f'%(prog)s: v{__version__} by {__author__}'
4444
)
4545

4646
parser.add_argument(
@@ -89,10 +89,12 @@ def main():
8989
except SystemExit:
9090
sys.exit(STATE_UNKNOWN)
9191

92-
msg = ''
92+
# init some vars
93+
msg = []
9394
perfdata = ''
9495
state = STATE_OK
9596

97+
# analyze data
9698
real_disks = lib.disk.get_real_disks()
9799
for disk in real_disks:
98100
mount = disk['mp'].split(' ')[0]
@@ -104,20 +106,18 @@ def main():
104106
inodes_free = float(st.f_ffree)
105107
inodes_used = round((inodes_total - inodes_free) / inodes_total * 100, 1)
106108

107-
msg += '{} {}%, '.format(mount, inodes_used)
108-
perfdata += lib.base.get_perfdata(mount, inodes_used, '%', args.WARN, args.CRIT, 0, 100)
109+
local_state = lib.base.get_state(inodes_used, args.WARN, args.CRIT)
110+
state = lib.base.get_worst(local_state, state)
109111

110-
if inodes_used >= args.CRIT:
111-
state = lib.base.get_worst(state, STATE_CRIT)
112-
msg = msg[:-2] + ' (CRIT), '
113-
elif inodes_used >= args.WARN:
114-
state = lib.base.get_worst(state, STATE_WARN)
115-
msg = msg[:-2] + ' (WARN), '
112+
msg.append(f'{mount} {inodes_used}%{lib.base.state2str(local_state, prefix=" ")}')
113+
perfdata += lib.base.get_perfdata(mount, inodes_used, '%', args.WARN, args.CRIT, 0, 100)
116114
except Exception:
117115
lib.base.cu('Something seems to be wrong with the input parameter')
116+
117+
# build the message
118118
if not msg:
119119
lib.base.oao('Everything is ok (although nothing checked).', state)
120-
msg = msg[:-2]
120+
msg = ', '.join(msg)
121121
if state != STATE_OK:
122122
msg += '. Have a look at the README on how to find where inodes are being used.'
123123

0 commit comments

Comments
 (0)