check_naf.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. #
  3. # Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org)
  4. # Default Template used if no other template is found.
  5. #
  6. ### Helper functions
  7. #
  8. function wc($VAL) {
  9. $wcout = "";
  10. if ($VAL['WARN'] != "") {
  11. $wcout .= rrd::hrule($VAL['WARN'], "#FFFF00", "Warning " . $VAL['WARN'] . "\\n");
  12. }
  13. if ($VAL['WARN_MIN'] != "") {
  14. $wcout .= rrd::hrule($VAL['WARN_MIN'], "#FFFF00", "Warning (min) " . $VAL['WARN_MIN'] . "\\n");
  15. }
  16. if ($VAL['WARN_MAX'] != "") {
  17. $wcout .= rrd::hrule($VAL['WARN_MAX'], "#FFFF00", "Warning (max) " . $VAL['WARN_MAX'] . "\\n");
  18. }
  19. if ($VAL['CRIT'] != "") {
  20. $wcout .= rrd::hrule($VAL['CRIT'], "#FF0000", "Critical " . $VAL['CRIT'] . "\\n");
  21. }
  22. if ($VAL['CRIT_MIN'] != "") {
  23. $wcout .= rrd::hrule($VAL['CRIT_MIN'], "#FF0000", "Critical (min) " . $VAL['CRIT_MIN'] . "\\n");
  24. }
  25. if ($VAL['CRIT_MAX'] != "") {
  26. $wcout .= rrd::hrule($VAL['CRIT_MAX'], "#FF0000", "Critical (max) " . $VAL['CRIT_MAX'] . "\\n");
  27. }
  28. return $wcout;
  29. }
  30. #
  31. ### Main loop
  32. #
  33. $graphs = 0;
  34. ##foreach ($this->DS as $KEY=>$VAL) {
  35. while( count($this->DS) > 0 ) {
  36. $VAL = array_shift($this->DS);
  37. if ($VAL['NAME'] == 'nacache_usage') {
  38. $opt[$graphs] = "--vertical-label \"PAM usage\" -l 0 -r --title \"PAM cache usage on ";
  39. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  40. $ds_name[$graphs] = "PAM cache usage";
  41. $def[$graphs] = "";
  42. $def[$graphs] .= rrd::def ("usage", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
  43. $def[$graphs] .= rrd::line2 ("usage", "#00CCCC", "PAM cache usage\:");
  44. $def[$graphs] .= rrd::gprint ("usage", array("LAST","MAX","AVERAGE"), "%5.2lf%S".$VAL['UNIT']);
  45. } elseif (substr($VAL['NAME'], 0, 8) == 'nacache_') {
  46. $o_hits = $VAL;
  47. $o_miss = array_shift($this->DS);
  48. $o_evict = array_shift($this->DS);
  49. $o_inval = array_shift($this->DS);
  50. $o_insert = array_shift($this->DS);
  51. $opt[$graphs] = "--vertical-label \"PAM ops/s\" --title \"PAM ops/s on ";
  52. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  53. $ds_name[$graphs] = "PAM ops/s";
  54. $def[$graphs] = "";
  55. $def[$graphs] .= rrd::def ("hits", $o_hits['RRDFILE'], $o_hits['DS'], "AVERAGE");
  56. $def[$graphs] .= rrd::def ("miss", $o_miss['RRDFILE'], $o_miss['DS'], "AVERAGE");
  57. $def[$graphs] .= rrd::def ("evict", $o_evict['RRDFILE'], $o_evict['DS'], "AVERAGE");
  58. $def[$graphs] .= rrd::def ("inval", $o_inval['RRDFILE'], $o_inval['DS'], "AVERAGE");
  59. $def[$graphs] .= rrd::def ("insert", $o_insert['RRDFILE'], $o_insert['DS'], "AVERAGE");
  60. $def[$graphs] .= rrd::line1 ("hits", "#00CC00", "Hits\: ");
  61. $def[$graphs] .= rrd::gprint ("hits", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  62. $def[$graphs] .= rrd::line1 ("miss", "#CC0000", "Misses\: ", "STACK");
  63. $def[$graphs] .= rrd::gprint ("miss", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  64. $def[$graphs] .= rrd::line1 ("evict", "#CCCC00", "Evicts\: ", "STACK");
  65. $def[$graphs] .= rrd::gprint ("evict", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  66. $def[$graphs] .= rrd::line1 ("inval", "#660000", "Invalids\: ", "STACK");
  67. $def[$graphs] .= rrd::gprint ("inval", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  68. $def[$graphs] .= rrd::line1 ("insert", "#0000FF", "Inserts\: ", "STACK");
  69. $def[$graphs] .= rrd::gprint ("insert", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  70. } elseif ($VAL['NAME'] == 'nacpu') {
  71. $opt[$graphs] = "--vertical-label % -l 0 -r --title \"CPU usage on ";
  72. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  73. $ds_name[$graphs] = $VAL['LABEL'];
  74. $def[$graphs] = "";
  75. $def[$graphs] .= rrd::def ("cpu_avg", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
  76. $def[$graphs] .= rrd::def ("cpu_min", $VAL['RRDFILE'], $VAL['DS'], "MIN");
  77. $def[$graphs] .= rrd::def ("cpu_max", $VAL['RRDFILE'], $VAL['DS'], "MAX");
  78. $def[$graphs] .= rrd::area ("cpu_max", "#6666FFCC");
  79. $def[$graphs] .= rrd::area ("cpu_min", "#FFFFFF");
  80. $def[$graphs] .= rrd::line1 ("cpu_avg", "#0000FF", "CPU usage:");
  81. $def[$graphs] .= wc($VAL);
  82. $def[$graphs] .= rrd::gprint ("cpu_avg", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
  83. } elseif ($VAL['NAME'] == 'nacs') {
  84. $opt[$graphs] = "--vertical-label \"Context Switches\" -l 0 -r --title \"Context switches on ";
  85. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  86. $ds_name[$graphs] = $VAL['LABEL'];
  87. $def[$graphs] = "";
  88. $def[$graphs] .= rrd::def ("cs_avg", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
  89. $def[$graphs] .= rrd::def ("cs_min", $VAL['RRDFILE'], $VAL['DS'], "MIN");
  90. $def[$graphs] .= rrd::def ("cs_max", $VAL['RRDFILE'], $VAL['DS'], "MAX");
  91. $def[$graphs] .= rrd::area ("cs_max", "#FF6666CC");
  92. $def[$graphs] .= rrd::area ("cs_min", "#FFFFFF");
  93. $def[$graphs] .= rrd::line1 ("cs_avg", "#FF0000", "Context switches:");
  94. $def[$graphs] .= wc($VAL);
  95. $def[$graphs] .= rrd::gprint ("cs_avg", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
  96. } elseif ($VAL['NAME'] == 'nadisk_total') {
  97. $d_t = $VAL;
  98. $d_a = array_shift($this->DS);
  99. $d_s = array_shift($this->DS);
  100. $d_f = array_shift($this->DS);
  101. $opt[$graphs] = "--vertical-label \"Disks\" -l 0 -r --title \"Disks on ";
  102. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  103. $ds_name[$graphs] = "Disks";
  104. $def[$graphs] = "";
  105. $def[$graphs] .= rrd::def ("total", $d_t['RRDFILE'], $d_t['DS'], "MAX");
  106. $def[$graphs] .= rrd::def ("active", $d_a['RRDFILE'], $d_a['DS'], "MIN");
  107. $def[$graphs] .= rrd::def ("spare", $d_s['RRDFILE'], $d_s['DS'], "MIN");
  108. $def[$graphs] .= rrd::def ("failed", $d_f['RRDFILE'], $d_f['DS'], "MAX");
  109. $def[$graphs] .= rrd::line1 ("total", "#000000", "Disks total\: ");
  110. $def[$graphs] .= rrd::gprint ("total", "LAST", "%3.0lf %S\\n".$d_t['UNIT']);
  111. $def[$graphs] .= rrd::area ("active", "#0000FFEE", "Disks active\:");
  112. $def[$graphs] .= rrd::gprint ("active", "LAST", "%3.0lf %S\\n".$d_a['UNIT']);
  113. $def[$graphs] .= rrd::area ("spare", "#77FF77CC", "Disks spare\: ", "STACK");
  114. $def[$graphs] .= rrd::gprint ("spare", "LAST", "%3.0lf %S\\n".$d_s['UNIT']);
  115. $def[$graphs] .= rrd::area ("failed", "#FF3333", "Disks failed\:", "STACK");
  116. $def[$graphs] .= rrd::gprint ("failed", "LAST", "%3.0lf %S\\n".$d_s['UNIT']);
  117. } elseif (substr($VAL['NAME'], 0, 5) == 'naio_') {
  118. $io1 = $VAL;
  119. $io2 = array_shift($this->DS);
  120. $type = substr($io1['NAME'], 5, 3);
  121. $name = 'UNKN';
  122. $desc_r = 'Read ';
  123. $desc_w = 'Write';
  124. if ($type == 'net') {
  125. $name = 'Net';
  126. $desc_r = 'In ';
  127. $desc_w = 'Out';
  128. } elseif ($type == 'dis') {
  129. $name = 'Disk';
  130. } elseif ($type == 'tap') {
  131. $name = 'Tape';
  132. } elseif ($type == 'fcp') {
  133. $name = 'Fibre channel';
  134. } elseif ($type == 'isc') {
  135. $name = 'iSCSI';
  136. }
  137. $opt[$graphs] = "--vertical-label \"Bytes/s\" --title \"" . $name . " I/O on ";
  138. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  139. $ds_name[$graphs] = $io1['NAME'] . " + " . $io2['NAME'];
  140. $def[$graphs] = "";
  141. $def[$graphs] .= rrd::def ("ior", $io1['RRDFILE'], $io1['DS'], "AVERAGE");
  142. $def[$graphs] .= rrd::def ("iow", $io2['RRDFILE'], $io2['DS'], "AVERAGE");
  143. $def[$graphs] .= rrd::area ("ior", "#00FF00", "FIXME In/Read\: ");
  144. $def[$graphs] .= rrd::gprint ("ior", array("LAST","MAX","AVERAGE"), "%7.2lf %SB/s");
  145. $def[$graphs] .= rrd::line2 ("iow", "#0000FF", "FIXME Out/Write\: ");
  146. $def[$graphs] .= rrd::gprint ("iow", array("LAST","MAX","AVERAGE"), "%7.2lf %SB/s");
  147. } elseif (substr($VAL['NAME'], 0, 6) == 'naops_') {
  148. $o_nfs = $VAL;
  149. $o_cifs = array_shift($this->DS);
  150. $o_http = array_shift($this->DS);
  151. $o_fcp = array_shift($this->DS);
  152. $o_iscsi = array_shift($this->DS);
  153. $opt[$graphs] = "--vertical-label \"Ops/s\" -l 0 -r --title \"Ops/s on ";
  154. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  155. $ds_name[$graphs] = "Ops/s";
  156. $def[$graphs] = "";
  157. $def[$graphs] .= rrd::def ("nfs", $o_nfs['RRDFILE'], $o_nfs['DS'], "AVERAGE");
  158. $def[$graphs] .= rrd::def ("cifs", $o_cifs['RRDFILE'], $o_cifs['DS'], "AVERAGE");
  159. $def[$graphs] .= rrd::def ("http", $o_http['RRDFILE'], $o_http['DS'], "AVERAGE");
  160. $def[$graphs] .= rrd::def ("fcp", $o_fcp['RRDFILE'], $o_fcp['DS'], "AVERAGE");
  161. $def[$graphs] .= rrd::def ("iscsi", $o_iscsi['RRDFILE'], $o_iscsi['DS'], "AVERAGE");
  162. $def[$graphs] .= rrd::line1 ("nfs", "#000000", "NFS ops/s\: ");
  163. $def[$graphs] .= rrd::gprint ("nfs", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  164. $def[$graphs] .= rrd::line1 ("cifs", "#00FFFF", "CIFS ops/s\: ");
  165. $def[$graphs] .= rrd::gprint ("cifs", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  166. $def[$graphs] .= rrd::line1 ("http", "#7F0000", "HTTP ops/s\: ");
  167. $def[$graphs] .= rrd::gprint ("http", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  168. $def[$graphs] .= rrd::line1 ("fcp", "#00FF00", "FCP ops/s\: ");
  169. $def[$graphs] .= rrd::gprint ("fcp", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  170. $def[$graphs] .= rrd::line1 ("iscsi", "#0000FF", "iSCSI ops/s\: ");
  171. $def[$graphs] .= rrd::gprint ("iscsi", array("LAST","MAX","AVERAGE"), "%7.2lf%Sops/s");
  172. } elseif (substr($VAL['NAME'], 0, 6) == 'navdu_') {
  173. $v_du = $VAL;
  174. $v_dt = array_shift($this->DS);
  175. $v_su = array_shift($this->DS);
  176. $v_st = array_shift($this->DS);
  177. $opt[$graphs] = "--vertical-label \"Bytes\" -l 0 -r --title \"" . substr($VAL['NAME'], 6);
  178. $opt[$graphs] .= " on ". $this->MACRO['DISP_HOSTNAME'] . "\"";
  179. $ds_name[$graphs] = "Volume " . substr($VAL['NAME'], 6);
  180. $def[$graphs] = "";
  181. $def[$graphs] .= rrd::def ("du", $v_du['RRDFILE'], $v_du['DS'], "AVERAGE");
  182. $def[$graphs] .= rrd::def ("dt", $v_dt['RRDFILE'], $v_dt['DS'], "AVERAGE");
  183. $def[$graphs] .= rrd::def ("supo", $v_su['RRDFILE'], $v_su['DS'], "AVERAGE");
  184. $def[$graphs] .= rrd::def ("st", $v_st['RRDFILE'], $v_st['DS'], "AVERAGE");
  185. $def[$graphs] .= rrd::cdef ("vt", "dt,st,+");
  186. $def[$graphs] .= rrd::cdef ("sf", "supo,st,LE,st,supo,-,0,IF");
  187. $def[$graphs] .= rrd::cdef ("su", "supo,st,GT,st,supo,IF");
  188. $def[$graphs] .= rrd::cdef ("so", "supo,st,GT,supo,st,-,0,IF");
  189. $def[$graphs] .= rrd::cdef ("df", "dt,du,-,so,-");
  190. $def[$graphs] .= rrd::line1 ("vt", "#000000", "Whole Volume ");
  191. $def[$graphs] .= rrd::gprint ("vt", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  192. $def[$graphs] .= rrd::area ("du", "#AAAAAA", "Data\: used space ");
  193. $def[$graphs] .= rrd::gprint ("du", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  194. $def[$graphs] .= rrd::area ("df", "#00FF00", "Data\: free space ", "STACK");
  195. $def[$graphs] .= rrd::gprint ("df", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  196. $def[$graphs] .= rrd::area ("so", "#AA0000", "Snap\: over resv. ", "STACK");
  197. $def[$graphs] .= rrd::gprint ("so", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  198. $def[$graphs] .= rrd::area ("sf", "#00FFFF", "Snap\: free space ", "STACK");
  199. $def[$graphs] .= rrd::gprint ("sf", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  200. $def[$graphs] .= rrd::area ("su", "#0000CC", "Snap\: used space ", "STACK");
  201. $def[$graphs] .= rrd::gprint ("su", array("LAST","MAX","AVERAGE"), "%6.2lf%S", "\\n");
  202. } elseif (substr($VAL['NAME'], 0, 6) == 'naviu_') {
  203. $v_iu = $VAL;
  204. $v_it = array_shift($this->DS);
  205. $opt[$graphs] = "--vertical-label \"INodes\" -l 0 -r --title \"INode usage on ";
  206. $opt[$graphs] .= $this->MACRO['DISP_HOSTNAME'] . "\"";
  207. $ds_name[$graphs] = "INode usage on " . substr($VAL['NAME'], 6);
  208. $def[$graphs] = "";
  209. $def[$graphs] .= rrd::def ("iu", $v_iu['RRDFILE'], $v_iu['DS'], "AVERAGE");
  210. $def[$graphs] .= rrd::def ("it", $v_it['RRDFILE'], $v_it['DS'], "AVERAGE");
  211. $def[$graphs] .= rrd::area ("it", "#00FF00");
  212. $def[$graphs] .= rrd::line1 ("it", "#000000");
  213. $def[$graphs] .= rrd::area ("iu", "#0000FF", "INodes used\: ");
  214. $def[$graphs] .= rrd::gprint ("iu", array("LAST","MAX","AVERAGE"), "%7.2lf%S");
  215. $def[$graphs] .= wc($v_iu);
  216. } else {
  217. $vlabel = "";
  218. $lower = "";
  219. $upper = "";
  220. if ($VAL['MIN'] != "") {
  221. $lower = " --lower=" . $VAL['MIN'];
  222. }
  223. if ($VAL['UNIT'] == "%%") {
  224. $vlabel = "%";
  225. $upper = " --upper=101 ";
  226. $lower = " --lower=0 ";
  227. }
  228. else {
  229. $vlabel = $VAL['UNIT'];
  230. }
  231. $opt[$graphs] = '--vertical-label "' . $vlabel . '" --title "' . $this->MACRO['DISP_HOSTNAME'] . ' / ' . $this->MACRO['DISP_SERVICEDESC'] . '"' . $upper . $lower;
  232. $ds_name[$graphs] = $VAL['LABEL'];
  233. $def[$graphs] = rrd::def ("var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
  234. $def[$graphs] .= rrd::gradient("var1", "BDC6DE", "3152A5", rrd::cut($VAL['NAME'],16), 20);
  235. $def[$graphs] .= rrd::line1 ("var1", "#000000" );
  236. $def[$graphs] .= rrd::gprint ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
  237. $def[$graphs] .= wc($VAL);
  238. $def[$graphs] .= rrd::comment("Command " . $VAL['TEMPLATE'] . " - " . $VAL['NAME'] . "\\r");
  239. } // default
  240. $graphs++;
  241. }
  242. ?>