Pnp4nagios - Template
Aller à la navigation
Aller à la recherche
EN COURS
Le site suivant est une très bonne approche de création de templates : http://wiki.monitoring-fr.org/nagios/addons/pnp/creation-template-graph
affichage de graphs cpu, mémoire et nombre de process
L'exemple suivant correspond à un des exemples de scripts perls de ce wiki. Le script renvoie, pour trois processus, la consommation mémoire, cpu et le nombre de process trouvé. Voici un exemple de ce qui est renvoyé à nagios :
Status Ok|cpu_sasexe=11 mem_sasexe=5545918464 nb_proc_sasexe=40 cpu_sasauth=0 mem_sasauth=13516800 nb_proc_sasauth=3 cpu_elssrv=0 mem_elssrv=107380736 nb_proc_elssrv=37
Le template va afficher un graphe cpu, un mémoire et un nombre de process. Sur chaque graphe, on va afficher une ligne par process (screenshot à la fin).
<?php # # Plugin: check_sas # ### cpu activity $ds_name[1] = "sas processes cpu activity"; $opt[1] = "--vertical-label \"sas processes CPU Activity\" -l0 --title \"sas processes CPU activity on $hostname\" "; ### mem activity $ds_name[2] = "sas processes memory activity"; $opt[2] = "--vertical-label \"sas processes memory activity\" -l0 --title \"sas processes memory activity on $hostname\" "; ### processes number $ds_name[3] = "sas processes number"; $opt[3] = "--vertical-label \"sas processes number\" -l0 --title \"sas processes number on $hostname\" "; # Init des definitions $def[1] = ""; $def[2] = ""; $def[3] = ""; # Id des sources de données $source_id = array("cpu" => 1, "mem" => 2, "nb_proc" => 3); $source_label = array("cpu" => "CPU (%)", "mem" => "Memory", "nb_proc" => "Nombre de process"); # Parcours des données foreach ($this->DS as $KEY=>$VAL) { if(preg_match("/(cpu|mem|nb_proc)_(.*)/", $VAL['LABEL'], $tmp)) { # Récupération des labels, id etc. $source_type = $tmp[1]; $name = $tmp[2]; $id = $source_id [$source_type]; $label = $source_label[$source_type]; # Affichage $def[$id] .= rrd::def($name, $VAL['RRDFILE'], $VAL['DS']); $def[$id] .= rrd::line2($name, rrd::color($KEY), "$label $name"); $def[$id] .= rrd::gprint($name, "LAST", "%6.2lf"); $def[$id] .= rrd::gprint($name, "AVERAGE", "avg %6.2lf"); $def[$id] .= rrd::gprint($name, "MAX", "max %6.2lf\\n"); } } ?>
Screenshot :
En cours
<?php # # 2013-03-01 - Frederic Menard # Plugin: check_aix_cpu_vcpu # $trend_array = array( "one_month" => array(strtotime("-1 month", $this->TIMERANGE['end']), $this->TIMERANGE['end'], "1 month trend:dashes=10", "#FF007F", "line3"), "global_trend" => array($this->TIMERANGE['start'], $this->TIMERANGE['end'], "Global trend\\n:dashes=20", "#707070", "line2"), ); $trends_graphic = ""; ### standard cpu statistic $ds_name[1] = "AIX physc CPU activity"; $opt[1] = "--upper-limit 100 --vertical-label \"AIX CPU Activity\" -l0 --title \"AIX CPU activity on $hostname\" "; $def[1] = rrd::def("var1", $RRDFILE[1], $DS[1]); $def[1] .= rrd::def("var2", $RRDFILE[2], $DS[2]); $def[1] .= rrd::cdef("user", "var2,var1,+"); $def[1] .= rrd::def("var3", $RRDFILE[3], $DS[3]); $def[1] .= rrd::cdef("iowait", "var3,var2,+,var1,+"); $def[1] .= rrd::area("iowait", "#00FF00", "iowait"); $def[1] .= rrd::gprint("var3", "LAST", "%6.2lf"); $def[1] .= rrd::gprint("var3", "AVERAGE", "avg %6.2lf"); $def[1] .= rrd::gprint("var3", "MAX", "max %6.2lf\\n"); $def[1] .= rrd::area("user", "#005CFF", "user "); $def[1] .= rrd::gprint("var1", "LAST", "%6.2lf"); $def[1] .= rrd::gprint("var1", "AVERAGE", "avg %6.2lf"); $def[1] .= rrd::gprint("var1", "MAX", "max %6.2lf\\n"); $def[1] .= rrd::area("var2", "#FF5C00", "sys "); $def[1] .= rrd::gprint("var2", "LAST", "%6.2lf"); $def[1] .= rrd::gprint("var2", "AVERAGE", "avg %6.2lf"); $def[1] .= rrd::gprint("var2", "MAX", "max %6.2lf\\n"); $def[1] .= rrd::line1("iowait", "#000000"); $def[1] .= rrd::line1("user", "#000000", "Total"); $def[1] .= rrd::gprint("user", "LAST", " %6.2lf"); $def[1] .= rrd::gprint("user", "AVERAGE", "moy %6.2lf"); $def[1] .= rrd::gprint("user", "MAX", "max %6.2lf\\n"); $def[1] .= rrd::line1("var2", "#000000"); foreach(array_keys($trend_array) as $trend) { $def[1] .= rrd::def("var1$trend", $RRDFILE[1], $DS[1], "AVERAGE:start=".$trend_array[$trend][0]); $def[1] .= rrd::def("var2$trend", $RRDFILE[2], $DS[2], "AVERAGE:start=".$trend_array[$trend][0]); $def[1] .= rrd::cdef("user$trend", "var2$trend,var1$trend,+"); $def[1] .= rrd::vdef("dtrend$trend", "user$trend,LSLSLOPE"); $def[1] .= rrd::vdef("htrend$trend", "user$trend,LSLINT"); $def[1] .= rrd::cdef("curve_user$trend", "user$trend,POP,dtrend$trend,COUNT,*,htrend$trend,+"); $trends_graphic .= rrd::$trend_array[$trend][4]("curve_user$trend", $trend_array[$trend][3], $trend_array[$trend][2]); } $def[1] .= $trends_graphic; if ($WARN[1] != "") { $def[1] .= rrd::hrule($WARN[1], "#FFFF00"); } if ($CRIT[1] != "") { $def[1] .= rrd::hrule($CRIT[1], "#FF0000"); } ### physc, entitled_capacity $ds_name[2] = "AIX physc CPU activity"; $opt[2] = "--vertical-label \"AIX physc CPU activity\" -l0 --title \"AIX physc CPU activity on $hostname\" "; $def[2] = rrd::def("var1", $RRDFILE[5], $DS[5]); $def[2] .= rrd::area("var1", "#4D689F"); $def[2] .= rrd::gprint("var1", "LAST", "%6.2lf last"); $def[2] .= rrd::gprint("var1", "AVERAGE", "%6.2lf avg"); $def[2] .= rrd::gprint("var1", "MAX", "%6.2lf max"); $def[2] .= rrd::def("var2", $RRDFILE[6], $DS[6]); $def[2] .= rrd::line2("var2", "#F4C62D"); $def[2] .= rrd::gprint("var2", "LAST", "%6.2lf last"); $def[2] .= rrd::gprint("var2", "AVERAGE", "%6.2lf avg"); $def[2] .= rrd::gprint("var2", "MAX", "%6.2lf max"); ### online_vcpus, maximum_vcpus $ds_name[3] = "AIX VCPUs capacity"; $opt[3] = "--vertical-label \"AIX VCPUs capacity\" -l0 --title \"AIX VCPUs capacity on $hostname\" "; $def[3] = rrd::def("var1", $RRDFILE[7], $DS[7]); $def[3] .= rrd::line2("var1", "#F4C62D"); $def[3] .= rrd::gprint("var1", "LAST", "%6.2lf last"); $def[3] .= rrd::gprint("var1", "AVERAGE", "%6.2lf avg"); $def[3] .= rrd::gprint("var1", "MAX", "%6.2lf max"); $def[3] .= rrd::def("var2", $RRDFILE[8], $DS[8]); $def[3] .= rrd::line2("var2", "#BF2DF4"); $def[3] .= rrd::gprint("var2", "LAST", "%6.2lf last"); $def[3] .= rrd::gprint("var2", "AVERAGE", "%6.2lf avg"); $def[3] .= rrd::gprint("var2", "MAX", "%6.2lf max"); ### lbusy $ds_name[4] = "AIX CPU lbusy"; #$opt[4] = "--vertical-label \"AIX CPU lbusy\" -l0 --title \"AIX CPU lbusy $hostname\" --slope-mode"; $opt[4] = "--vertical-label \"AIX CPU lbusy\" -l0 --title \"AIX CPU lbusy $hostname\""; $def[4] = rrd::def("var1", $RRDFILE[9], $DS[9]); $def[4] .= rrd::gradient("var1", "#031810", "#169049", "$NAME[9]"); # projection $def[4] .= rrd::vdef("slope", "var1,LSLSLOPE"); $def[4] .= rrd::vdef("int", "var1,LSLINT"); $def[4] .= rrd::cdef("proj", "var1,POP,slope,COUNT,*,int,+"); $def[4] .= rrd::line2("proj", "#ff007f", "Projection:dashes=10"); $def[4] .= rrd::gprint("var1", "LAST", "%6.2lf last"); $def[4] .= rrd::gprint("var1", "AVERAGE", "%6.2lf avg"); $def[4] .= rrd::gprint("var1", "MAX", "%6.2lf max"); ?>
test