check_naf.php 12 KB

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