This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 097e279bd6af30b88b3069734e0a810b725bacd2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 10:24:27 2015 +0100 disk space monitoring added --- app/modules/monitoring_modules/unix/__init__.py | 5 +++-- app/modules/monitoring_modules/unix/disk.py | 30 +++++++++++++++++++++++++ app/modules/monitoring_modules/unix/memory.py | 8 ++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/modules/monitoring_modules/unix/__init__.py b/app/modules/monitoring_modules/unix/__init__.py index 8efe043..0554872 100644 --- a/app/modules/monitoring_modules/unix/__init__.py +++ b/app/modules/monitoring_modules/unix/__init__.py @@ -1,6 +1,7 @@ __author__ = 'aguilbaud' -__all__=['updated_packages', 'memory'] +__all__=['updated_packages', 'memory', 'disk'] info_mod = { 'updated_packages': {'block': 'software', 'unit': 'bool'}, - 'memory': {'block': 'hardware', 'unit': 'kB'} + 'memory': {'block': 'hardware', 'unit': '%'}, + 'disk': {'block' : 'hardware', 'unit': '%'} } \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/disk.py b/app/modules/monitoring_modules/unix/disk.py new file mode 100644 index 0000000..48586cc --- /dev/null +++ b/app/modules/monitoring_modules/unix/disk.py @@ -0,0 +1,30 @@ +__author__ = 'aguilbaud' + +import json +import re + +""" +Check and returns the percentage of disk used ( = percentage of use of the partition mounted on /) +""" + + +class disk: + def __init__(self, conn, db): + self.conn = conn + self.db = db + + def check(self): + cmd = "df -h" + stdout = self.conn.exec_command(cmd) + disk_used = 0 + ignore = True + for line in stdout.splitlines(): + # we ignore the first line which contains no value + if ignore: + ignore = False + else: + values = line.split() + if values[len(values)-1] == "/": + disk_used = re.sub("[^0-9]", "", values[len(values)-2]) + res_check = json.dumps({"disk": int(disk_used)}) + self.db.add_check(self.conn.get_addr_host(), "disk", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/memory.py b/app/modules/monitoring_modules/unix/memory.py index 2b36cf5..c58cdcb 100644 --- a/app/modules/monitoring_modules/unix/memory.py +++ b/app/modules/monitoring_modules/unix/memory.py @@ -2,6 +2,10 @@ __author__ = 'aguilbaud' import json import re +""" +Check and returns the percentage of total memory used of the machine +""" + class memory: def __init__(self, conn, db): self.conn = conn @@ -18,5 +22,7 @@ class memory: memtotal = re.sub("[^0-9]", "", tab_res[1]) elif(tab_res[0]) == 'MemFree': memfree = re.sub("[^0-9]", "", tab_res[1]) - res_check = json.dumps({"memory": (int(memfree) * 100) / int(memtotal)}) + #TODO si memfree ou memtotal = 0, retourner une exception comme quoi le module n'est pas compatible avec l'hote + memused = int(memtotal) - int(memfree) + res_check = json.dumps({"memory": memused * 100 / int(memtotal)}) self.db.add_check(self.conn.get_addr_host(), "memory", res_check) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.