Page 1 of 1

check_mem issues with graph

Posted: Mon May 12, 2014 3:25 pm
by brandon.pal
I have started to use a custom check_mem for monitoring memory & swap usage on my linux hosts. I'm working off of https://github.com/whereisaaron/linux-c ... ios-plugin which is based on http://exchange.nagios.org/directory/Pl ... sh/details. I've added a little bit to include swap usage.

I am having an issue with the graph as it's just showing up as a dead image. The plugin includes a custom graph template which I have installed but it does not seem to be working. I've made sure it's not my additions that broke the graph as it did not work before I started to massage the code.

I also know it's not the name of the graph template as if I put in the default template code into the file it creates the default pnp4nagios graph.
The graph template looks like this:

Code: Select all

<?php

	$ds_name[1] = "sysinfo";

	$opt[1] = "--vertical-label \"Bytes\" -l0 --title \"Memory usage for $hostname / $servicedesc\" ";

	# Total Memory
	$def[1] = "DEF:mem_total=$RRDFILE[1]:$DS[1]:AVERAGE " ;
	# Used Memory
	$def[1] .= "DEF:mem_used=$RRDFILE[1]:$DS[2]:AVERAGE " ;
	# Cache
	$def[1] .= "DEF:mem_cache=$RRDFILE[1]:$DS[3]:AVERAGE " ;
	# Buffer
	$def[1] .= "DEF:mem_buffer=$RRDFILE[1]:$DS[4]:AVERAGE " ;

	# Memory Cache
	$def[1] .= rrd::cdef("mem_cache_tmp", "mem_cache,mem_buffer,+,mem_used,+");
	$def[1] .= rrd::area("mem_cache_tmp", "#DCDDD5", "Disk Cache");

	$def[1] .= "GPRINT:mem_cache:LAST:\"%3.2lf %sB Last \" ";
        $def[1] .= "GPRINT:mem_cache:MAX:\"%3.2lf %sB Max \" ";
        $def[1] .= "GPRINT:mem_cache" . ':AVERAGE:"%3.2lf %sB Average \j" ';

	# Memory Buffer
	$def[1] .= rrd::cdef("mem_buffer_tmp", "mem_buffer,mem_used,+");
	$def[1]	.= rrd::area("mem_buffer_tmp", "#3E606F", "I/O Buffers");

	$def[1] .= "GPRINT:mem_buffer:LAST:\"%3.2lf %sB Last \" ";
        $def[1] .= "GPRINT:mem_buffer:MAX:\"%3.2lf %sB Max \" ";
        $def[1] .= "GPRINT:mem_buffer" . ':AVERAGE:"%3.2lf %sB Average \j" ';

	# Memory Used
	$def[1]	.= rrd::area("mem_used", "#193441", "Processes");

	$def[1] .= "GPRINT:mem_used:LAST:\"%3.2lf %sB Last \" ";
	$def[1] .= "GPRINT:mem_used:MAX:\"%3.2lf %sB Max \" ";
	$def[1] .= "GPRINT:mem_used" . ':AVERAGE:"%3.2lf %sB Average \j" ';

	# Memory Total
	$def[1] .= rrd::line1("mem_total", "#000000", "Total");

	$def[1] .= "GPRINT:mem_total:LAST:\"%3.2lf %sB Last \" ";
        $def[1] .= "GPRINT:mem_total:MAX:\"%3.2lf %sB Max \" ";
        $def[1] .= "GPRINT:mem_total" . ':AVERAGE:"%3.2lf %sB Average \j" ';

	if ($WARN[2] != "") {
        	$def[1] .= "HRULE:$WARN[2]#ffff00:\"Warning threshold for Processes\j\" ";
	}
	if ($CRIT[2] != "") {
        	$def[1] .= "HRULE:$CRIT[2]#ff0000:\"Critical threshold for Processes\" ";
	}
?>

Re: check_mem issues with graph

Posted: Mon May 12, 2014 4:27 pm
by Box293
Can you please post the output from the command (executed at the CLI) so we can compare the performance data against the graph code.

Re: check_mem issues with graph

Posted: Mon May 12, 2014 5:37 pm
by brandon.pal

Code: Select all

[root@dc01-app-03 plugins]# ./check_mem -w 20 -c 10
MEMORY OK - Total: 5852 MB - Used: 456 MB - 7% used|TOTAL=6136987648;;;0;6136987648 USED=477102080;1227397529;613698764;0;6136987648 CACHE=973672448;;;0;6136987648 BUFFER=215703552;;;0;6136987648
<pre>
Memory    Used  Total  Percentage
Physical  456   5852   7%
Swap      0     7999   0%
</pre>

Re: check_mem issues with graph

Posted: Mon May 12, 2014 6:17 pm
by brandon.pal
I altered the output to match the var names in the template

Code: Select all

[root@dc01-app-03 plugins]# ./check_mem -w 50 -c 60
MEMORY OK - Total: 5852 MB - Used: 453 MB - 7% used|mem_total=6136987648;;;0;6136987648 mem_used=473468928;3068493824;3682192588;0;6136987648 mem_cache=973852672;;;0;6136987648 mem_buffer=215703552;;;0;6136987648
<pre>
Memory    Used  Total  Percentage
Physical  453   5852   7%
Swap      0     7999   0%
</pre>
Still not working though.

Re: check_mem issues with graph

Posted: Mon May 12, 2014 8:26 pm
by Box293
Perhaps change $RRDFILE to $rrdfile (there are four of these in the code).

Also, when I compare this one to another template (check-host-alive.php), there are some differences.

For example:
Your template has:

Code: Select all

# Memory Cache
$def[1] .= rrd::cdef("mem_cache_tmp", "mem_cache,mem_buffer,+,mem_used,+");
$def[1] .= rrd::area("mem_cache_tmp", "#DCDDD5", "Disk Cache");
Whereas in check-host-alive.php the same thing is done slightly differently:

Code: Select all

$def[2] .=  "CDEF:sp1=var1,100,/,12,* " ;
Perhaps alter your code to see if that helps.

I find that when playing with templates, simplify it and see what could be causing the problem. For example to start off with, just focus on Total Memory and remove all code related to the three other data sources and see if it at least displays. Even take out the warn and crit IF statements. Then add in the next datasouce and test.

Let us know if that helps.

Re: check_mem issues with graph

Posted: Fri May 16, 2014 9:28 am
by brandon.pal
I've got the template working. My code is:

Code: Select all

<?php

$opt[1] = "--vertical-label \"% Used\" -l0 --title \"Memory usage  for $hostname / $servicedesc\" ";

# Memory Used
$def[1] = "DEF:mem_used=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "LINE1:mem_used#0984B5:\"\"Actual " ;
$def[1] .= "GPRINT:mem_used:LAST:\"%3.2lf %sB CUR \" ";
$def[1] .= "GPRINT:mem_used:MAX:\"%3.2lf %sB MAX \" ";
$def[1] .= "GPRINT:mem_used" . ':AVERAGE:"%3.2lf %sB AVG \j" ';

# Swap
$def[1] .= "DEF:swap=$rrdfile:$DS[2]:AVERAGE " ;
$def[1] .= "LINE2:swap#2D7500:\"\"Swap " ;
$def[1] .= "GPRINT:swap:LAST:\"%3.2lf %sB CUR \" ";
$def[1] .= "GPRINT:swap:MAX:\"%3.2lf %sB MAX \" ";
$def[1] .= "GPRINT:swap" . ':AVERAGE:"%3.2lf %sB AVG \j" ';

?>
I've taken a whole bunch of items out as I'm not quite sure what they do so I've yet to add them back.

Re: check_mem issues with graph

Posted: Fri May 16, 2014 1:00 pm
by slansing
Excellent! Yeah these templates can be very strict on what is required to graph your data sources.

Re: check_mem issues with graph

Posted: Fri May 16, 2014 4:45 pm
by Box293
Great stuff!

PNP templates can be a little frustrating to say the least :lol: