Debian Codegraph @

check_redis/check_redis.php

raw
1 <?php
2 # ================================ SUMMARY ====================================
3 #
4 # File : check_redis.php
5 # Version : 0.1
6 # Date : June 01, 2012
7 # Author : William Leibzon - [email protected]
8 # Summary : PNP4Nagios template for check_memcached.pl
9 # Licence : GPL - summary below, full text at http://www.fsf.org/licenses/gpl.txt
10 #
11 # This is considered a supplemental file to check_redis.pl plugin and though
12 # not distributed in unified package it is distributed under the same licencing
13 # terms (GNU 2.0 license). Any redisribution of this file in modified form must
14 # reproduce this summary (modified if appropriate) and must either include
15 # entire GNU license in a package or list URL where it can be found if
16 # distributed as a single file.
17 #
18 # ===================== INFORMATION ABOUT THIS TEMPLATE =======================
19 #
20 # This is a pnp4nagios template for redis database check done with check_redis.pl
21 # that would graph some status variables returned by this plugin.
22 #
23 # Unlike most templates this does not care which order variables are returned in
24 # and will automatically pick the right ones, so you can just use '-A' option
25 # from the plugin to return all performance variables (though in that case
26 # your rrd file will lager and contain extra datat that would not be graphed).
27 #
28 # Here is an example of nagios command config:
29 #
30 # define command {
31 # command_name check_redis_new
32 # command_line $USER1$/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -T $ARG2$ -R -A -M $_HOSTSYSTEM_MEMORY$ -m $ARG3$ -a $ARG4$ -w $ARG5$ -c $ARG6$ -f -P "$SERVICEPERFDATA$"
33 # }
34 #
35 # Arguments and thresholds are:
36 # $ARG1 : Port
37 # $ARG2 : response time thresholds
38 # $ARG3 : memory utilization thresholds
39 # $ARG4 : additional variables to be checked
40 # $ARG5 : warning thresholds for those variables
41 # $ARG6 : critical thresholds for those variables
42 #
43 # define service {
44 # use prod-service
45 # hostgroups redishosts
46 # service_description Redis
47 # check_command check_redis_new!6379!"1,2"!"80,90"!blocked_clients,connected_clients!50,~!100,~
48 # }
49 #
50 # define host {
51 # use prod-server
52 # host_name redis.mynetwork
53 # address redis.mynetwork
54 # alias Redis Stat Server
55 # hostgroups linux,redishosts
56 # _SYSTEM_MEMORY '8G'
57 # }
58 #
59 # ========================= VERSION HISTORY and TODO ==========================
60 #
61 # v0.1 - 05/31/2012 : Initial version of the template created. Includes the following:
62 # 1. Response Times Graph
63 # 2. Client Connections Graph
64 # 3. Hits and Misses
65 # 4. Keys Graph
66 # 5. Memory Graph
67 # 6. CPU Usage (this maybe wrong, showing too high)
68 #
69 # =============================== END OF HEADER ===============================
70
71 $VAR = array( 'total_connections_received' => -1, # Connections Graph: connections/sec
72 'used_memory_rss' => -1, # Memory Graph: Current memory RSS
73 'used_cpu_sys' => -1, # CPU Load Graph: System, Main Thread
74 'connected_clients' => -1, # Connections Graph: connections now
75 'keyspace_hits' => -1, # Hits and Misses Graph: hits
76 'used_cpu_user_children' => -1, # CPU Load Graph: User, Child Threads
77 'keyspace_misses' => -1, # Hits and Misses graph: misses
78 'used_cpu_user' => -1, # CPU Load Graph: User, Main Thread
79 'total_commands_processed' => -1, # Commands Processed Graph ?
80 'mem_fragmentation_ratio' => -1, # Memory Fragmentation Graph ?
81 'used_memory' => -1, # Memory Graph: Used Memory
82 'blocked_clients' => -1, # Connections Graph: blocked clients
83 'expired_keys' => -1, # Keys Graph: expired keys
84 'used_memory_peak' => -1, # Memory Graph: Memory Peak
85 'used_cpu_sys_children' => -1, # CPU Load Graph: System, Child Threads
86 'evicted_keys' => -1, # Keys Graphs: evicted keys
87 'response_time' => -1, # Respose Time Graph
88 'total_keys' => -1, # Keys Graph: total Keys
89 'total_expires' => -1, # Keys Graph: total_expires
90 'memory_utilization' => -1 # Memory Graph: %mem_use
91 );
92
93 foreach ($this->DS as $KEY=>$VAL) {
94 if (isset($VAR[$VAL['LABEL']])) {
95 $VAR[$VAL['LABEL']] = $VAL['DS'];
96 }
97 }
98
99 $gindex=0;
100
101 if ($VAR['response_time'] != -1) {
102 $vindex=$VAR['response_time'];
103 $unit=$UNIT[$vindex];
104 $ds_name[$gindex] = "Redis Response Time";
105 $opt[$gindex] = "--vertical-label \"$unit\" --title \"$servicedesc Response Time on $hostname \" --slope-mode --color=BACK#000000 --color=FONT#F7F7F7 --color=SHADEA#ffffff --color=SHADEB#ffffff --color=CANVAS#000000 --color=GRID#00991A --color=MGRID#00991A --color=ARROW#FF0000 ";
106 $def[$gindex] = rrd::def("var1", $RRDFILE[$vindex], $DS[$vindex], "AVERAGE");
107 $def[$gindex] .= "VDEF:slope=var1,LSLSLOPE " ;
108 $def[$gindex] .= "VDEF:int=var1,LSLINT " ;
109 $def[$gindex] .= "CDEF:proj=var1,POP,slope,COUNT,*,int,+ " ;
110 $def[$gindex] .= "LINE2:proj#ff00ff:\"Projection \" " ;
111 $def[$gindex] .= "GPRINT:var1:LAST:\"%6.2lf$unit last\" " ;
112 $def[$gindex] .= "GPRINT:var1:AVERAGE:\"%6.2lf$unit avg\" " ;
113 $def[$gindex] .= "GPRINT:var1:MAX:\"%6.2lf$unit max\\n\" ";
114 $def[$gindex] .= "CDEF:sp1=var1,100,/,10,* " ;
115 $def[$gindex] .= "CDEF:sp2=var1,100,/,20,* " ;
116 $def[$gindex] .= "CDEF:sp3=var1,100,/,30,* " ;
117 $def[$gindex] .= "CDEF:sp4=var1,100,/,40,* " ;
118 $def[$gindex] .= "CDEF:sp5=var1,100,/,50,* " ;
119 $def[$gindex] .= "CDEF:sp6=var1,100,/,60,* " ;
120 $def[$gindex] .= "CDEF:sp7=var1,100,/,70,* " ;
121 $def[$gindex] .= "CDEF:sp8=var1,100,/,80,* " ;
122 $def[$gindex] .= "CDEF:sp9=var1,100,/,90,* " ;
123 $def[$gindex] .= "AREA:var1#0000A0:\"Response Time \" " ;
124 $def[$gindex] .= "AREA:sp9#0000A0: " ;
125 $def[$gindex] .= "AREA:sp8#0000C0: " ;
126 $def[$gindex] .= "AREA:sp7#0010F0: " ;
127 $def[$gindex] .= "AREA:sp6#0040F0: " ;
128 $def[$gindex] .= "AREA:sp5#0070F0: " ;
129 $def[$gindex] .= "AREA:sp4#00A0F0: " ;
130 $def[$gindex] .= "AREA:sp3#00D0F0: " ;
131 $def[$gindex] .= "AREA:sp2#A0F0F0: " ;
132 $def[$gindex] .= "AREA:sp1#F0F0F0: " ;
133 $gindex++;
134 }
135
136 if ($VAR['total_connections_received'] != -1 ||
137 $VAR['connected_clients'] != -1 ||
138 $VAR['blocked_clients'] != -1) {
139 $vindex_totalconnections=$VAR['total_connections_received'];
140 $vindex_connectedclients=$VAR['connected_clients'];
141 $vindex_blockedclients=$VAR['blocked_clients'];
142 $ds_name[$gindex] = "Redis Client Connections";
143 $opt[$gindex] = "--lower-limit=0 --vertical-label \"connections\" --title \"$servicedesc Connections to $hostname\" ";
144 $def[$gindex] = "";
145 if ($vindex_connectedclients!=-1) {
146 $def[$gindex] .= rrd::def("curr_conn", $RRDFILE[$vindex_connectedclients], $DS[$vindex_connectedclients], "AVERAGE");
147 $def[$gindex] .= rrd::area("curr_conn", "#00FF00", "Current Number of Connections");
148 $def[$gindex] .= rrd::gprint("curr_conn", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
149 }
150 if ($vindex_totalconnections!=-1) {
151 $def[$gindex] .= rrd::def("conn_rate", $RRDFILE[$vindex_totalconnections], $DS[$vindex_totalconnections], "AVERAGE");
152 $def[$gindex] .= rrd::line1("conn_rate", "#0000FF", "New Connnections Per Second ");
153 $def[$gindex] .= rrd::gprint("conn_rate", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
154 }
155 if ($vindex_blockedclients!=-1) {
156 $def[$gindex] .= rrd::def("blocked_clients", $RRDFILE[$vindex_blockedclients], $DS[$vindex_blockedclients], "AVERAGE");
157 $def[$gindex] .= rrd::line1("blocked_clients", "#FF0000", "Blocked Client Connections ");
158 $def[$gindex] .= rrd::gprint("blocked_clients", array("LAST","MAX","AVERAGE"), "%3.0lf ");
159 }
160 $gindex++;
161 }
162
163 if ($VAR['keyspace_hits'] != -1 && $VAR['keyspace_misses'] != -1) {
164 $vindex_hits=$VAR['keyspace_hits'];
165 $vindex_misses=$VAR['keyspace_misses'];
166 $ds_name[$gindex] = "Redis Hits and Misses";
167 $opt[$gindex] = "--lower-limit=0 --vertical-label \"hits and misses\" --title \"$servicedesc Hits and Misses on $hostname\" ";
168 $def[$gindex] = rrd::def("get_hits", $RRDFILE[$vindex_hits], $DS[$vindex_hits], "AVERAGE");
169 $def[$gindex] .= rrd::def("get_misses", $RRDFILE[$vindex_misses], $DS[$vindex_misses], "AVERAGE");
170 $def[$gindex] .= rrd::area("get_hits", "#00FF00", "Hits ");
171 $def[$gindex] .= rrd::gprint("get_hits", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
172 $def[$gindex] .= rrd::area("get_misses", "#FF0000", "Misses ", "STACK");
173 $def[$gindex] .= rrd::gprint("get_misses", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
174 $def[$gindex] .= rrd::cdef("hitrate", "get_hits,get_hits,get_misses,+,/,100,*");
175 $def[$gindex] .= rrd::comment("- Hit Rate ");
176 $def[$gindex] .= rrd::gprint("hitrate", array("LAST", "MAX", "AVERAGE"), "%.2lf%% ");
177 $gindex++;
178 }
179
180 if ($VAR['total_keys'] != -1 && $VAR['total_expires'] != -1) {
181 $vindex_expiredkeys=$VAR['expired_keys'];
182 $vindex_evictedkeys=$VAR['evicted_keys'];
183 $vindex_totalkeys=$VAR['total_keys'];
184 $vindex_totalexpires=$VAR['total_expires'];
185 $ds_name[$gindex] = "Redis Keys Store";
186 $opt[$gindex] = "--lower-limit=0 --vertical-label \"keys\" --title \"$servicedesc Keys on $hostname\" ";
187 $def[$gindex] = rrd::def("total_keys", $RRDFILE[$vindex_totalkeys], $DS[$vindex_totalkeys], "AVERAGE");
188 $def[$gindex] .= rrd::def("total_expires", $RRDFILE[$vindex_totalexpires], $DS[$vindex_totalexpires], "AVERAGE");
189 $def[$gindex] .= rrd::area("total_keys", "#6495ED", "Total Keys ");
190 $def[$gindex] .= rrd::gprint("total_keys", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
191 $def[$gindex] .= rrd::area("total_expires", "#00FFFF", "Will Expire", "");
192 $def[$gindex] .= rrd::gprint("total_expires", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
193 if ($vindex_expiredkeys!=-1) {
194 $def[$gindex] .= rrd::def("expired_keys", $RRDFILE[$vindex_expiredkeys], $DS[$vindex_expiredkeys], "AVERAGE");
195 $def[$gindex] .= rrd::line1("expired_keys", "#00FF00", "Expired ", "");
196 $def[$gindex] .= rrd::gprint("expired_keys", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
197 }
198 if ($vindex_evictedkeys!=-1) {
199 $def[$gindex] .= rrd::def("evicted_keys", $RRDFILE[$vindex_evictedkeys], $DS[$vindex_evictedkeys], "AVERAGE");
200 $def[$gindex] .= rrd::line1("evicted_keys", "#FF0000", "Evicted ", "");
201 $def[$gindex] .= rrd::gprint("evicted_keys", array("LAST", "MAX", "AVERAGE"), "%3.0lf ");
202 }
203 $gindex++;
204 }
205
206 if ($VAR['used_memory'] != -1 && $VAR['used_memory_peak']) {
207 $vindex_usedmemory=$VAR['used_memory'];
208 $vindex_memorypeak=$VAR['used_memory_peak'];
209 $vindex_memoryrss=$VAR['used_memory_rss'];
210 $vindex_fragmentation=$VAR['mem_fragmentation_ratio'];
211 $vindex_utilization=$VAR['memory_utilization'];
212 $ds_name[$gindex] = "Redis Memory";
213 $opt[$gindex] = "--lower-limit=0 --vertical-label \"MB\" --title \"$servicedesc Memory Use on $hostname\" ";
214 $def[$gindex] = rrd::def("bytes", $RRDFILE[$vindex_usedmemory], $DS[$vindex_usedmemory], "AVERAGE");
215 $def[$gindex] .= rrd::def("maxbytes", $RRDFILE[$vindex_memorypeak], $DS[$vindex_memorypeak], "AVERAGE");
216 $def[$gindex] .= rrd::cdef("use_mb", "bytes,1024,/,1024,/");
217 $def[$gindex] .= rrd::cdef("maxuse_mb", "maxbytes,1024,/,1024,/");
218 $def[$gindex] .= rrd::cdef("mfree_mb", "maxbytes,bytes,-,1024,/,1024,/");
219 $def[$gindex] .= rrd::area("use_mb", "#00FFFF", "Used Memory ");
220 $def[$gindex] .= "GPRINT:use_mb:LAST:\"%6.1lfMB Last \" " ;
221 $def[$gindex] .= "GPRINT:use_mb:MAX:\"%6.1lfMB Max \" " ;
222 $def[$gindex] .= "GPRINT:use_mb:AVERAGE:\"%6.1lfMB Avg \\n\" " ;
223 $def[$gindex] .= rrd::line1("maxuse_mb", "#0000FF", "Max Used Memory ");
224 $def[$gindex] .= "GPRINT:maxuse_mb:LAST:\"%6.1lfMB Last \" " ;
225 $def[$gindex] .= "GPRINT:maxuse_mb:MAX:\"%6.1lfMB Max \" " ;
226 $def[$gindex] .= "GPRINT:maxuse_mb:AVERAGE:\"%6.1lfMB Avg \\n\" " ;
227 if ($vindex_memoryrss!=-1) {
228 $def[$gindex] .= rrd::def("memoryrss", $RRDFILE[$vindex_memoryrss], $DS[$vindex_memoryrss], "AVERAGE");
229 $def[$gindex] .= rrd::cdef("memrss_mb", "memoryrss,1024,/,1024,/");
230 $def[$gindex] .= rrd::cdef("fragmented_mb", "memrss_mb,use_mb,-");
231 $def[$gindex] .= rrd::area("fragmented_mb", "#FFD700", "Allocated Memory", "STACK");
232 if ($vindex_utilization!=-1) {
233 $def[$gindex] .= rrd::def("use_perc", $RRDFILE[$vindex_utilization], $DS[$vindex_utilization], "AVERAGE");
234 $def[$gindex] .= rrd::cdef("free_perc", "100,use_perc,-");
235 $def[$gindex] .= rrd::cdef("total_mb", "memrss_mb,use_perc,/,100,*");
236 $def[$gindex] .= rrd::cdef("free_mb", "total_mb,memrss_mb,-");
237 $def[$gindex] .= "GPRINT:memrss_mb:LAST:\"%6.1lfMB \g\" " ;
238 $def[$gindex] .= "GPRINT:use_perc:LAST:\" (%2.1lf%%) Last\" " ;
239 $def[$gindex] .= "GPRINT:memrss_mb:MAX:\"%6.1lfMB \g\" " ;
240 $def[$gindex] .= "GPRINT:use_perc:MAX:\" (%2.1lf%%) Max\" " ;
241 $def[$gindex] .= "GPRINT:memrss_mb:AVERAGE:\"%6.1lfMB \g\" " ;
242 $def[$gindex] .= "GPRINT:use_perc:AVERAGE:\" (%2.1lf%%) Avg\\n\" " ;
243 $def[$gindex] .= rrd::cdef("fragmentation_calc", "memrss_mb,use_mb,/");
244 $def[$gindex] .= rrd::comment("* Fragmentation Ratio (Allocated/Used) is \g");
245 if ($vindex_fragmentation!=-1) {
246 $def[$gindex] .= rrd::def("fragmentation_data", $RRDFILE[$vindex_fragmentation], $DS[$vindex_fragmentation], "AVERAGE");
247 $def[$gindex] .= "GPRINT:fragmentation_calc:LAST:\" %2.2lf \g\" ";
248 $def[$gindex] .= "GPRINT:fragmentation_data:LAST:\" (actual %2.2lf)\\n\" ";
249 }
250 else {
251 $def[$gindex] .= "GPRINT:fragmentation_calc:LAST:\"%2.2lf\\n\" ";
252 }
253 $def[$gindex] .= rrd::area("free_mb", "#00FF00", "Free Memory ", "STACK");
254 $def[$gindex] .= "GPRINT:free_mb:LAST:\"%6.1lfMB \g\" " ;
255 $def[$gindex] .= "GPRINT:free_perc:LAST:\" (%2.1lf%%) Last\" " ;
256 $def[$gindex] .= "GPRINT:free_mb:MAX:\"%6.1lfMB \g\" " ;
257 $def[$gindex] .= "GPRINT:free_perc:MAX:\" (%2.1lf%%) Max\" " ;
258 $def[$gindex] .= "GPRINT:free_mb:AVERAGE:\"%6.1lfMB \g\" " ;
259 $def[$gindex] .= "GPRINT:free_perc:AVERAGE:\" (%2.1lf%%) Avg\\n\" " ;
260 $def[$gindex] .= rrd::comment("= Total Memory");
261 $def[$gindex] .= "GPRINT:total_mb:LAST:\"%6.1lfMB\\n\" ";
262 }
263 else {
264 $def[$gindex] .= "GPRINT:memrss_mb:LAST:\"%6.1lfMB Last \" " ;
265 $def[$gindex] .= "GPRINT:memrss_mb:MAX:\"%6.1lfMB Max \" " ;
266 $def[$gindex] .= "GPRINT:memrss_mb:AVERAGE:\"%6.1lfMB Avg \\n\" " ;
267 }
268 }
269 $gindex++;
270 }
271
272 if ($VAR['used_cpu_sys'] != -1) {
273 $vindex_cpumain_sys=$VAR['used_cpu_sys'];
274 $vindex_cpumain_user=$VAR['used_cpu_user'];
275 $vindex_cpuchild_sys=$VAR['used_cpu_sys_children'];
276 $vindex_cpuchild_user=$VAR['used_cpu_user_children'];
277 $ds_name[$gindex] ="CPU Use";
278 $opt[$gindex] = "--vertical-label \"cpu time in msec\" --title \"$servicedesc CPU Use on $hostname\" ";
279 $def[$gindex] = rrd::def("cpu_main_sys", $RRDFILE[$vindex_cpumain_sys], $DS[$vindex_cpumain_sys], "AVERAGE");
280 $def[$gindex] .= rrd::area("cpu_main_sys", "#FF6103", "System CPU - Main Thread");
281 $def[$gindex] .= rrd::gprint("cpu_main_sys", array("LAST","MAX","AVERAGE"), "%6.2lf ");
282 if ($vindex_cpuchild_sys!=-1) {
283 $def[$gindex] .= rrd::def("cpu_child_sys", $RRDFILE[$vindex_cpuchild_sys], $DS[$vindex_cpuchild_sys], "AVERAGE");
284 $def[$gindex] .= rrd::area("cpu_child_sys", "#FFD700", "System CPU - Children ", "STACK");
285 $def[$gindex] .= rrd::gprint("cpu_child_sys", array("LAST","MAX","AVERAGE"), "%6.2lf ");
286 }
287 if ($vindex_cpumain_user!=-1) {
288 $def[$gindex] .= rrd::def("cpu_main_user", $RRDFILE[$vindex_cpumain_user], $DS[$vindex_cpumain_user], "AVERAGE");
289 $def[$gindex] .= rrd::area("cpu_main_user", "#008000", "User CPU - Main Thread", "STACK");
290 $def[$gindex] .= rrd::gprint("cpu_main_user", array("LAST","MAX","AVERAGE"), "%6.2lf ");
291 }
292 if ($vindex_cpuchild_user!=-1) {
293 $def[$gindex] .= rrd::def("cpu_child_user", $RRDFILE[$vindex_cpuchild_user], $DS[$vindex_cpuchild_user], "AVERAGE");
294 $def[$gindex] .= rrd::area("cpu_child_user", "#00FF00", "User CPU - Children ", "STACK");
295 $def[$gindex] .= rrd::gprint("cpu_child_user", array("LAST","MAX","AVERAGE"), "%6.2lf ");
296 }
297 $gindex++;
298 }
299
300 ?>