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 6f723c7080e2b98374036cda9ee7d43e874a88cb Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Apr 3 17:07:25 2015 +0200 cpu module added --- app/modules/monitoring_modules/cpu.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/modules/monitoring_modules/cpu.py b/app/modules/monitoring_modules/cpu.py new file mode 100644 index 0000000..61c1b30 --- /dev/null +++ b/app/modules/monitoring_modules/cpu.py @@ -0,0 +1,31 @@ +# -*- coding: utf8 -*- +__author__ = 'aguilbaud' + +compatible_os = ['linux', 'unix'] +block = "hardware" +unit = "%" + + +def check(conn, db, mnce): + """ + Returns the greatest between the user and system CPU charge + """ + cmd = "top -b -n 1" + stdout = conn.exec_command(cmd) + user_cpu_charge = 0.0 + system_cpu_charge = 0.0 + for line in stdout.splitlines(): + fields = line.split() + if not fields == []: + if fields[0] == '%Cpu(s):': + for i in range(len(fields)): + if fields[i] == 'us,': + field_usr = fields[i-1] + field_usr = field_usr.replace(',', '.') + user_cpu_charge = float(field_usr) + elif fields[i] == 'sy,': + field_sys = fields[i-1] + field_sys = field_sys.replace(',', '.') + system_cpu_charge = float(field_sys) + res_cpu = max(user_cpu_charge, system_cpu_charge) + return db.add_check(conn.get_addr_host(), 'cpu', res_cpu) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.