From d1de6c5fa3bf7406ff78457b740040d1aeb93109 Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Fri, 6 May 2016 08:45:34 -0700 Subject: [PATCH] openfiles: module to report open file handle count This module will display the current open file handles and the kernel setting for max open file handles. This is particularly useful when running applications that like to grab a lot of file handles to help monitor if/when your system may run out of available file handles. --- i3pystatus/openfiles.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 i3pystatus/openfiles.py diff --git a/i3pystatus/openfiles.py b/i3pystatus/openfiles.py new file mode 100644 index 0000000..0afb43e --- /dev/null +++ b/i3pystatus/openfiles.py @@ -0,0 +1,30 @@ +from i3pystatus import IntervalModule + + +class Openfiles(IntervalModule): + """ + Displays the current/max open files. + """ + + settings = ( + ("filenr_path", "Location to file-nr (usually /proc/sys/fs/file-nr"), + "color", + "format" + ) + color = 'FFFFFF' + interval = 30 + filenr_path = '/proc/sys/fs/file-nr' + format = "open/max: {openfiles}/{maxfiles}" + + def run(self): + + cur_filenr = open(self.filenr_path, 'r').readlines() + openfiles, unused, maxfiles = cur_filenr[0].split() + + cdict = {'openfiles': openfiles, + 'maxfiles': maxfiles} + + self.output = { + "full_text": self.format.format(**cdict), + "color": self.color + }