[checkmk-commits] Check_MK Git: check_mk: memory.include: Now the function actually works

Konstantin Büttner kb at mathias-kettner.de
Fri Feb 27 12:54:27 CET 2015


Module: check_mk
Branch: master
Commit: c4887d10aa7148aaaff62374314e64a231d45c61
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c4887d10aa7148aaaff62374314e64a231d45c61

Author: Konstantin Büttner <kb at mathias-kettner.de>
Date:   Fri Feb 27 12:52:14 2015 +0100

memory.include: Now the function actually works

---

 checks/memory.include |   70 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/checks/memory.include b/checks/memory.include
new file mode 100644
index 0000000..252cb47
--- /dev/null
+++ b/checks/memory.include
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# |             ____ _               _        __  __ _  __           |
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
+# |                                                                  |
+# | Copyright Mathias Kettner 2015             mk at mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software;  you can redistribute it and/or modify it
+# under the  terms of the  GNU General Public License  as published by
+# the Free Software Foundation in version 2.  check_mk is  distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
+# ails.  You should have  received  a copy of the  GNU  General Public
+# License along with GNU Make; see the file  COPYING.  If  not,  write
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+def check_memory(used, total, params):
+
+    if params:
+        if type(params) == tuple:
+            params = { "levels" : ("perc_used", params) }
+    else:
+        params = { "levels" : ("ignore") }
+
+    perc_used = (float(used) / total) * 100
+    infotext = "Memory usage: %s (Used: %s, Total: %s)" % (
+                                            get_percent_human_readable(perc_used),
+                                            get_bytes_human_readable(used),
+                                            get_bytes_human_readable(total))
+
+    levelstext = ""
+    if params["levels"][0] == "ignore":
+        warn_abs, crit_abs = None, None
+        status = 0
+
+    elif params["levels"][0] == "perc_used":
+        warn_rel, crit_rel = params["levels"][1]
+        warn_abs, crit_abs = (warn_rel/100.0) * total, (crit_rel/100.0) * total
+        levelstext = " (warn/crit at %s/%s used)" % (get_percent_human_readable(warn_rel),
+                                                get_percent_human_readable(crit_rel))
+    elif params["levels"][0] == "abs_free":
+        warn_abs_free, crit_abs_free = params["levels"][1]
+        warn_abs, crit_abs = total - warn_abs_free, total - crit_abs_free
+        levelstext = " (warn/crit below %s/%s free)" % (
+                                            get_bytes_human_readable(warn_abs_free),
+                                            get_bytes_human_readable(crit_abs_free))
+
+    if warn_abs and crit_abs:
+        if used >= crit_abs:
+            status = 2
+        elif used >= warn_abs:
+            status = 1
+        else:
+            status = 0
+
+    if status:
+        infotext += levelstext
+
+    perfdata = [ ("memory_used", used, warn_abs, crit_abs, 0, total) ]
+    return status, infotext, perfdata



More information about the checkmk-commits mailing list