Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / pnp-templates / check_mk-mem.linux.php
blob17e0e834a144c76b98cf48b896bf408c271d72ab
1 <?php
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 $defopt = "--vertical-label 'Bytes' -l0 -b 1024 ".
27 "--color MGRID\"#cccccc\" --color GRID\"#dddddd\" ";
29 # Work with names rather then numbers.
30 global $mem_defines;
31 $mem_defines = array();
32 foreach ($NAME as $i => $n) {
33 $mem_defines[$n] = "DEF:$n=$RRDFILE[$i]:$DS[$i]:MAX ";
36 # avoid redeclaration errors if this file is include multiple times (e.g. by basket)
37 if (!function_exists('mem_area')) {
38 function mem_area($varname, $color, $title, $stacked)
40 return mem_curve("AREA", $varname, $color, $title, $stacked);
43 function mem_line($varname, $color, $title, $stacked)
45 return mem_curve("LINE1", $varname, $color, $title, $stacked);
48 function mem_curve($how, $varname, $color, $title, $stacked)
50 global $mem_defines;
51 $tit = sprintf("%-30s", $title);
52 if (isset($mem_defines[$varname])) {
53 $x = $mem_defines[$varname] . "$how:$varname#$color:\"$tit\"";
54 if ($stacked)
55 $x .= ":STACK";
56 $x .= " ";
57 $x .= "CDEF:${varname}_gb=$varname,1073741824,/ ";
58 $x .= "GPRINT:${varname}_gb:LAST:\"%6.1lf GB last\" ";
59 $x .= "GPRINT:${varname}_gb:AVERAGE:\"%6.1lf GB avg\" ";
60 $x .= "GPRINT:${varname}_gb:MAX:\"%6.1lf GB max\\n\" ";
61 return $x;
63 else {
64 return "";
69 # 1. Overview
70 $opt[] = $defopt . "--title \"RAM + Swap overview\"";
71 $def[] = ""
72 . mem_area("mem_total", "f0f0f0", "RAM installed", FALSE)
73 . mem_area("swap_total", "e0e0e0", "Swap installed", TRUE)
74 . mem_area("mem_used", "80ff40", "RAM used", FALSE)
75 . mem_area("swap_used", "408f20", "Swap used", TRUE)
78 # 2. Swap
79 $opt[] = $defopt . "--title \"Swap\"";
80 $def[] = ""
81 . mem_area("swap_total", "e0e0e0", "Swap installed", FALSE)
82 . mem_area("swap_used", "408f20", "Swap used", FALSE)
83 . mem_area("swap_cached", "5bebc9", "Swap cached", TRUE)
86 # 3. Caches
87 $opt[] = $defopt . "--title \"Caches\"";
88 $def[] = ""
89 . mem_area("cached", "91cceb", "File contents", FALSE)
90 . mem_area("buffers", "5bb9eb", "Filesystem structure", TRUE)
91 . mem_area("swap_cached", "5bebc9", "Swap cached", TRUE)
92 . mem_area("slab", "af91eb", "Slab (Various smaller caches)", TRUE)
95 # 4. Active & Inactive
96 $opt[] = $defopt . "--title \"Active and Inactive Memory\"";
97 if (isset($mem_defines["active_anon"])) {
98 $def[] = ""
99 . mem_area("active_anon", "ff4040", "Active (anonymous)", FALSE)
100 . mem_area("active_file", "ff8080", "Active (files)", TRUE)
101 . mem_area("inactive_anon", "377cab", "Inactive (anonymous)", TRUE)
102 . mem_area("inactive_file", "4eb0f2", "Inactive (files)", TRUE)
105 else {
106 $def[] = ""
107 . mem_area("active", "ff4040", "Active", FALSE)
108 . mem_area("inactive", "4040ff", "Inactive", FALSE)
112 # 5. Dirty
113 $opt[] = $defopt . "--title \"Filesystem Writeback\"";
114 $def[] = ""
115 . mem_area("dirty", "f2904e", "Dirty disk blocks", FALSE)
116 . mem_area("writeback", "f2df40", "Currently being written", TRUE)
117 . mem_area("nfs_unstable", "c6f24e", "Modified NFS data", TRUE)
118 . mem_area("bounce", "4ef26c", "Bounce buffers", TRUE)
119 . mem_area("writeback_tmp", "4eeaf2", "Dirty FUSE data", TRUE)
122 # 6. Committing
123 if (isset($mem_defines["commit_limit"])) {
124 $opt[] = $defopt . "--title \"Memory committing\"";
125 $def[] = ""
126 . mem_area("total_total", "f0f0f0", "Total virtual memory", FALSE)
127 . mem_area("committed_as", "40a080", "Committed memory", FALSE)
128 . mem_area("commit_limit", "e0e0e0", "Commit limit", TRUE)
132 # 7. Shared memory
133 if (isset($mem_defines["shmem"])) {
134 $opt[] = $defopt . "--title \"Shared memory\"";
135 $def[] = ""
136 . mem_area("shmem", "bf9111", "Shared memory", FALSE)
140 # 8. Unswappable memory
141 $opt[] = $defopt . "--title \"Memory that cannot be swapped out\"";
142 $def[] = ""
143 . mem_area("kernel_stack", "7192ad", "Kernel stack", FALSE)
144 . mem_area("page_tables", "71ad9f", "Page tables", TRUE)
145 . mem_area("mlocked", "a671ad", "Locked mmap() data", TRUE)
148 # 9. Huge Pages
149 if (isset($mem_defines["huge_pages_total"])) {
150 $opt[] = $defopt . "--title \"Huge Pages\"";
151 $def[] = ""
152 . mem_area("huge_pages_total", "f0f0f0", "Total", FALSE)
153 . mem_area("huge_pages_free", "f0a0f0", "Free", FALSE)
154 . mem_area("huge_pages_rsvd", "40f0f0", "Reserved part of Free", FALSE)
155 . mem_line("huge_pages_surp", "90f0b0", "Surplus", TRUE)
159 # 10. VMalloc
160 if (isset($mem_defines["vmalloc_total"])) {
161 $opt[] = $defopt . "--title \"VMalloc Address Space\"";
162 $def[] = ""
163 . mem_area("vmalloc_total", "f0f0f0", "Total address space", FALSE)
164 . mem_area("vmalloc_used", "aaf76f", "Allocated space", FALSE)
165 . mem_area("vmalloc_chunk", "c6f7e9", "Largest free chunk", TRUE)