Merge pull request #379 from drwahl/master
openfiles: module to report open file handle count
This commit is contained in:
commit
2f5f3086d2
31
i3pystatus/openfiles.py
Normal file
31
i3pystatus/openfiles.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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')
|
||||||
|
openfiles, unused, maxfiles = cur_filenr.readlines()[0].split()
|
||||||
|
cur_filenr.close()
|
||||||
|
|
||||||
|
cdict = {'openfiles': openfiles,
|
||||||
|
'maxfiles': maxfiles}
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": self.format.format(**cdict),
|
||||||
|
"color": self.color
|
||||||
|
}
|
29
tests/test_openfiles.py
Normal file
29
tests/test_openfiles.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""
|
||||||
|
Basic test for the openfiles module
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
from shutil import copyfile
|
||||||
|
from i3pystatus import openfiles
|
||||||
|
|
||||||
|
|
||||||
|
class OpenfilesTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_openfiles(self):
|
||||||
|
"""
|
||||||
|
Test output of open files
|
||||||
|
"""
|
||||||
|
# copy file-nr so we have a known/unchanged source file
|
||||||
|
with TemporaryDirectory() as tmpdirname:
|
||||||
|
copyfile('/proc/sys/fs/file-nr', tmpdirname + '/file-nr')
|
||||||
|
cur_filenr = open(tmpdirname + '/file-nr', 'r')
|
||||||
|
openfilehandles, ununsed, maxfiles = cur_filenr.readlines()[0].split()
|
||||||
|
cur_filenr.close()
|
||||||
|
i3openfiles = openfiles.Openfiles(filenr_path=tmpdirname + '/file-nr')
|
||||||
|
i3openfiles.run()
|
||||||
|
self.assertTrue(i3openfiles.output['full_text'] == 'open/max: %s/%s' % (openfilehandles, maxfiles))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user