git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/check_mysql_health/check_mysql_health-2.2.2/contrib/check_mysql_health.php
blob: 8bcd516c17b14b0d3ba854e895f183209bfe829f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
#
# Copyright (c) 2009 Gerhard Lausser (gerhard.lausser@consol.de)
# Plugin: check_mysql_health (http://www.consol.com/opensource/nagios/check-mysql-health)
# Release 1.0 2009-03-02
#
# This is a template for the visualisation addon PNP (http://www.pnp4nagios.org)
#

$defcnt = 1;

$green = "33FF00E0";
$yellow = "FFFF00E0";
$red = "F83838E0";
$now = "FF00FF";
$ds_count = count($DS);

for ($i = 1; $i <= $ds_count; $i++) {
    $warning = ($WARN[$i] != "") ? $WARN[$i] : "";
    $warnmin = ($WARN_MIN[$i] != "") ? $WARN_MIN[$i] : "";
    $warnmax = ($WARN_MAX[$i] != "") ? $WARN_MAX[$i] : "";
    $critical = ($CRIT[$i] != "") ? $CRIT[$i] : "";
    $critmin = ($CRIT_MIN[$i] != "") ? $CRIT_MIN[$i] : "";
    $critmax = ($CRIT_MAX[$i] != "") ? $CRIT_MAX[$i] : "";
    $minimum = ($MIN[$i] != "") ? $MIN[$i] : "";
    $maximum = ($MAX[$i] != "") ? $MAX[$i] : "";

    if(preg_match('/^pct_open_files$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Open Files Usage";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Open files usage on $hostname\" --upper-limit 100 --lower-limit 0";
        $def[$defcnt] = ""; 
        $def[$defcnt] .= "DEF:openfiles_pct=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:openfiles_pct#111111:\" \" ";
        $def[$defcnt] .= "VDEF:vopenfiles=openfiles_pct,LAST " ;
        $def[$defcnt] .= "GPRINT:vopenfiles:\"Open files usage is %3.2lf percent\\n\" " ;
        $defcnt++;
    }   
    if(preg_match('/^connects_aborted_per_sec$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Aborted connections per second";
        $opt[$defcnt] = "--vertical-label \"Seconds\" --title \"Aborted connections per second on $hostname\" ";
        $def[$defcnt] = ""; 
        $def[$defcnt] .= "DEF:aborted_conn=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:aborted_conn#444444:\" \" ";
        $def[$defcnt] .= "VDEF:vaborted_conn=aborted_conn,LAST " ;
        $def[$defcnt] .= "GPRINT:vaborted_conn:\"Aborted connections per sec is %3.2lf \\n\" " ;
        $defcnt++;
    }
    if(preg_match('/^connection_time$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Time to connect";
        $opt[$defcnt] = "--vertical-label \"Seconds\" --title \"Time to establish a connection to $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:connectiontime=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:connectiontime#111111 ";
        $def[$defcnt] .= "VDEF:vconnetiontime=connectiontime,LAST " ;
        $def[$defcnt] .= "GPRINT:vconnetiontime:\"is %3.2lf Seconds \" " ;
        $defcnt++;
    }
    if(preg_match('/^uptime$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Uptime";
        $opt[$defcnt] = "--vertical-label \"Seconds\" --title \"Uptime of the database at $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:uptime=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:uptime#111111 ";
        $def[$defcnt] .= "CDEF:uptimed=uptime,86400,/ " ;
        $def[$defcnt] .= "CDEF:uptimew=uptimed,7,/ " ;
        $def[$defcnt] .= "VDEF:vuptime=uptime,LAST " ;
        $def[$defcnt] .= "VDEF:vuptimed=uptimed,LAST " ;
        $def[$defcnt] .= "VDEF:vuptimew=uptimew,LAST " ;
        $def[$defcnt] .= "GPRINT:vuptime:\"%.0lf Seconds \" " ;
        $def[$defcnt] .= "GPRINT:vuptimed:\"%.0lf Days \" " ;
        $def[$defcnt] .= "GPRINT:vuptimew:\"%.0lf Weeks \" " ;
        $defcnt++;
    }
    if(preg_match('/^index_usage_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Index usage";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Index usage $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^index_usage$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:indexusage=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=indexusage,$CRIT_MIN[$ii],LE,indexusage,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,indexusage,0,IF ";
            $def[$defcnt] .= "CDEF:ay=indexusage,$WARN_MIN[$ii],LE,indexusage,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,indexusage,0,IF ";
            $def[$defcnt] .= "CDEF:ag=indexusage,100,LE,indexusage,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,indexusage,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE:indexusage#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vindexusage=indexusage,LAST " ;
            $def[$defcnt] .= "GPRINT:vindexusage:\"Index usage (since epoch) is %3.2lf percent\\n\" " ;
          }
          if(preg_match('/^index_usage_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:indexusagenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:indexusagenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vindexusagenow=indexusagenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vindexusagenow:\"Index usage (current) is %3.2lf percent\\n\" ";
          }
        }
        $defcnt++;
    }
    if(preg_match('/^bufferpool_hitrate_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Innodb buffer pool hitrate";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Innodb buffer pool hitrate on $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^bufferpool_hitrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitrate=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=hitrate,$CRIT_MIN[$ii],LE,hitrate,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ay=hitrate,$WARN_MIN[$ii],LE,hitrate,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ag=hitrate,100,LE,hitrate,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE1.5:hitrate#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vhitrate=hitrate,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitrate:\"Hitratio (since epoch) is %3.2lf percent \\n\" ";
          }
          if(preg_match('/^bufferpool_hitrate_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitratenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:hitratenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vhitratenow=hitratenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitratenow:\"Hitratio (current) is %3.2lf percent \\n\" ";
          }
        }
        $defcnt++;
    }
    if(preg_match('/^bufferpool_free_waits_rate$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Innodb buffer pool waits rate";
        $opt[$defcnt] = "--vertical-label \"Waits/sec\" --title \"Innodb buffer pool waits on $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:logwait=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:logwait#111111 ";
        $def[$defcnt] .= "VDEF:vlogwait=logwait,LAST " ;
        $def[$defcnt] .= "GPRINT:vlogwait:\"Rate is %3.2lf Waits / Second \" " ;
        $defcnt++;
    }
    if(preg_match('/^innodb_log_waits_rate$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Innodb log buffer waits rate";
        $opt[$defcnt] = "--vertical-label \"Waits/sec\" --title \"Innodb waits for log buffer $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:logwait=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:logwait#111111 ";
        $def[$defcnt] .= "VDEF:vlogwait=logwait,LAST " ;
        $def[$defcnt] .= "GPRINT:vlogwait:\"Rate is %3.2lf Waits / Second \" " ;
        $defcnt++;
    }
    if(preg_match('/^long_running_procs$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Long running processes";
        $opt[$defcnt] = "--vertical-label \"Processes\" --title \"Long running processes (>60s) on $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:longrun=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:longrun#111111 ";
        $def[$defcnt] .= "VDEF:vlongrun=longrun,LAST " ;
        $def[$defcnt] .= "GPRINT:vlongrun:\"%.0lf long running processes \" " ;
        $defcnt++;
    }
    if(preg_match('/^keycache_hitrate_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "MyISAM key cache hitrate";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"MyISAM key cache hitrate on $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^keycache_hitrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitrate=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=hitrate,$CRIT_MIN[$ii],LE,hitrate,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ay=hitrate,$WARN_MIN[$ii],LE,hitrate,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ag=hitrate,100,LE,hitrate,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE1.5:hitrate#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vhitrate=hitrate,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitrate:\"Hitratio (since epoch) is %3.2lf percent \\n\" ";
          }
          if(preg_match('/^keycache_hitrate_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitratenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:hitratenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vhitratenow=hitratenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitratenow:\"Hitratio (current) is %3.2lf percent \\n\" ";
          }
        }
        $defcnt++;
    }
    if(preg_match('/^qcache_hitrate_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Query cache hitrate";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Query cache hitrate on $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = ""; 
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^qcache_hitrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitrate=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=hitrate,$CRIT_MIN[$ii],LE,hitrate,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ay=hitrate,$WARN_MIN[$ii],LE,hitrate,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ag=hitrate,100,LE,hitrate,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE1.5:hitrate#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vhitrate=hitrate,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitrate:\"Hitratio (since epoch) is %3.2lf percent \\n\" ";
          }   
          if(preg_match('/^qcache_hitrate_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitratenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:hitratenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vhitratenow=hitratenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitratenow:\"Hitratio (current) is %3.2lf percent \\n\" ";
          }   
        }   
        $defcnt++;
        $ds_name[$defcnt] = "Selects per second";
        $opt[$defcnt] = "--vertical-label \"Selects / sec\" --title \"Selects per second on $hostname\" ";
        $def[$defcnt] = ""; 
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^selects_per_sec$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:sps=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "AREA:sps#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vsps=sps,LAST " ;
            $def[$defcnt] .= "GPRINT:vsps:\"%3.2lf Selects per second \\n\" ";
          }   
        }
        $defcnt++;
    }   
    if(preg_match('/^qcache_lowmem_prunes_rate$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Query cache low memory prunes";
        $opt[$defcnt] = "--vertical-label \"Prunes / sec\" --title \"Query cache low mem prunes on $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:prunes=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:prunes#111111 ";
        $def[$defcnt] .= "VDEF:vprunes=prunes,LAST " ;
        $def[$defcnt] .= "GPRINT:vprunes:\"Rate is %3.2lf Prunes / Second \" " ;
        $defcnt++;
    }
    if(preg_match('/^slow_queries_rate$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Slow query rate";
        $opt[$defcnt] = "--vertical-label \"Slow queries / sec\" --title \"Slow queries on $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:prunes=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:prunes#111111 ";
        $def[$defcnt] .= "VDEF:vprunes=prunes,LAST " ;
        $def[$defcnt] .= "GPRINT:vprunes:\"%3.2lf Slow queries / Second \" " ;
        $defcnt++;
    }
    if(preg_match('/^tablelock_contention_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Table lock contention";
        # set upper limit to 10, because 3 means an already dead database
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Table lock contention on $hostname\" --upper-limit 10 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^tablelock_contention$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:tbllckcont=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ag=tbllckcont,$WARN[$ii],LE,tbllckcont,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,tbllckcont,0,IF ";
            $def[$defcnt] .= "CDEF:ay=tbllckcont,$CRIT[$ii],LE,tbllckcont,$WARN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,tbllckcont,0,IF ";
            $def[$defcnt] .= "CDEF:ar=tbllckcont,100,LE,tbllckcont,$CRIT[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,tbllckcont,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE:tbllckcont#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vtbllckcont=tbllckcont,LAST " ;
            $def[$defcnt] .= "GPRINT:vtbllckcont:\"Lock contention (since epoch) is %3.2lf%%\\n\" " ;
          }
          if(preg_match('/^tablelock_contention_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:tbllckcontnow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:tbllckcontnow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vtbllckcontnow=tbllckcontnow,LAST " ;
            $def[$defcnt] .= "GPRINT:vtbllckcontnow:\"Lock contention (current) is %3.2lf%%\" ";
          }   
        }
        $defcnt++;
    }
    if(preg_match('/^tablecache_fillrate$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Table cache hitrate";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Table cache hitrate on $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^tablecache_hitrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitrate=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=hitrate,$CRIT_MIN[$ii],LE,hitrate,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ay=hitrate,$WARN_MIN[$ii],LE,hitrate,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ag=hitrate,100,LE,hitrate,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE:hitrate#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vhitrate=hitrate,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitrate:\"Hitratio is %3.2lf percent \\n\" ";
          }
          if(preg_match('/^tablecache_fillrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitratenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:hitratenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vhitratenow=hitratenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitratenow:\"%3.2lf%% of the cache is filled \\n\" ";
          }
        }
        $defcnt++;
    }
    if(preg_match('/^pct_tmp_table_on_disk_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Temporary tables created on disk ";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Temporary tables created on disk on $hostname\" --upper-limit 10 --lower-limit 0 ";
        $def[$defcnt] = "";
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^pct_tmp_table_on_disk$/', $NAME[$ii])) {

            $def[$defcnt] .= "DEF:tmptbldsk=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ag=tmptbldsk,$WARN[$ii],LE,tmptbldsk,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,tmptbldsk,0,IF ";
            $def[$defcnt] .= "CDEF:ay=tmptbldsk,$CRIT[$ii],LE,tmptbldsk,$WARN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,tmptbldsk,0,IF ";
            $def[$defcnt] .= "CDEF:ar=tmptbldsk,100,LE,tmptbldsk,$CRIT[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,tmptbldsk,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE:tmptbldsk#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vtmptbldsk=tmptbldsk,LAST " ;
            $def[$defcnt] .= "GPRINT:vtmptbldsk:\"%3.2lf percent of temp tables were created on disk (since epoch)\\n\" " ;
          }
          if(preg_match('/^pct_tmp_table_on_disk_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:tmptbldsknow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:tmptbldsknow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vtmptbldsknow=tmptbldsknow,LAST " ;
            $def[$defcnt] .= "GPRINT:vtmptbldsknow:\"%3.2lf percent of temp tables were created on disk (recently)\\n\" " ;
          }   
        }
        $defcnt++;
    }
    if(preg_match('/^thread_cache_hitrate_now$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Thread cache hitrate";
        $opt[$defcnt] = "--vertical-label \"Percent\" --title \"Thread cache hitrate on $hostname\" --upper-limit 100 --lower-limit 0 ";
        $def[$defcnt] = ""; 
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^thread_cache_hitrate$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitrate=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "CDEF:ar=hitrate,$CRIT_MIN[$ii],LE,hitrate,0,GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ay=hitrate,$WARN_MIN[$ii],LE,hitrate,$CRIT_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "CDEF:ag=hitrate,100,LE,hitrate,$WARN_MIN[$ii],GT,INF,UNKN,IF,UNKN,IF,ISINF,hitrate,0,IF ";
            $def[$defcnt] .= "AREA:ag#$green: " ;
            $def[$defcnt] .= "AREA:ay#$yellow: " ;
            $def[$defcnt] .= "AREA:ar#$red: " ;
            $def[$defcnt] .= "LINE:hitrate#111111:\" \" ";
            $def[$defcnt] .= "VDEF:vhitrate=hitrate,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitrate:\"Hitratio (since epoch) is %3.2lf percent \\n\" ";
          }   
          if(preg_match('/^thread_cache_hitrate_now$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:hitratenow=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "LINE1.5:hitratenow#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vhitratenow=hitratenow,LAST " ;
            $def[$defcnt] .= "GPRINT:vhitratenow:\"Hitratio (current) is %3.2lf percent \\n\" ";
          }   
        }   
        $defcnt++;
        $ds_name[$defcnt] = "Connects per second";
        $opt[$defcnt] = "--vertical-label \"Conects / sec\" --title \"Connects per second on $hostname\" ";
        $def[$defcnt] = ""; 
	for ($ii = 1; $ii <= $ds_count; $ii++) {
          if(preg_match('/^connections_per_sec$/', $NAME[$ii])) {
            $def[$defcnt] .= "DEF:sps=$RRDFILE[$ii]:$DS[$ii]:AVERAGE:reduce=LAST " ;
            $def[$defcnt] .= "AREA:sps#$now:\" \" ";
            $def[$defcnt] .= "VDEF:vsps=sps,LAST " ;
            $def[$defcnt] .= "GPRINT:vsps:\"%3.2lf Connects per second \\n\" ";
          }   
        }
        $defcnt++;
    }   
    if(preg_match('/^threads_connected$/', $NAME[$i])) {
        $ds_name[$defcnt] = "Connection threads";
        $opt[$defcnt] = "--vertical-label \"Threads\" --title \"Connection threads on $hostname\" ";
        $def[$defcnt] = "";
        $def[$defcnt] .= "DEF:threads=$RRDFILE[$i]:$DS[$i]:AVERAGE:reduce=LAST " ;
        $def[$defcnt] .= "AREA:threads#111111 ";
        $def[$defcnt] .= "VDEF:vthreads=threads,LAST " ;
        $def[$defcnt] .= "GPRINT:vthreads:\"%.0lf Connection threads \" " ;
        $defcnt++;
    }
}
?>