Page 1 of 1

changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 7:31 am
by gambolputty
Greetings,

I've been asked to provide reports showing how much a group of OS X computers are being used. Aside from debating how to actually measure such things, the requestor agreed that simple CPU usage broken down into user and system percentages would be acceptable. I worked my way through weirdness in the XI agent install for OS X (unpredictable nrpe daemon ownership through launchd), and the bug in the check_cpu_stats* (wrote my own python script to parse the output of a 'top' command). Now I have a need to change the charts shown when looking at the history of CPU percentages reported.

By default, Nagios XI is showing a layered area chart for user and system CPU usage percentages, but that really doesn't make sense for a CPU usage chart. Can I change these charts to be a stacked area chart? Here is a Wikipedia page showing the difference (http://en.wikipedia.org/wiki/Area_chart).

Thanks in advance.




* The bug is acknowledged here- http://tracker.nagios.com/view.php?id=307

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 8:05 am
by scottwilkerson
I'm not sure if this is available through pnp (that XI uses) but the docs for creating custom chart templates are located at
http://docs.pnp4nagios.org/pnp-0.4/tpl_custom

they would be uploaded through Admin -> Graph Templates


Would you be willing to share the plugin you made for OS X here or on the Exchange?

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 8:20 am
by gambolputty
Thanks Scott, that pnp document link looks promising. Another thing that I didn't mention is that I'd like to explore setting the y axis scale (%CPU) to a constant 100%. I suspect I may run into problems because I think some multi-core systems will report >100% usage when the sum of the CPU% usage for the total cores exceeds 100%.

I'm more than happy to share my script. It's small, and crude, but it's effective. I may remove the idle% reporting and just stick with sys and user in the near future.

Code: Select all

#!/sw/bin/python
# This is a small CPU checker, nothing more.

from subprocess import Popen, PIPE

try:
    proc = Popen(['/usr/bin/top', '-l', '1', '-n' '5'], shell=False, stdout=PIPE)
    proc_comm = proc.communicate()[0]
    top_out = proc_comm.splitlines()[3][11:]
    user = top_out.split()[0]
    system = top_out.split()[2]
    idle = top_out.split()[4]
    print "CPU STATISTICS OK: user=%s system=%s idle=%s | user=%s system=%s idle=%s"% (user,system,idle,user,system,idle)
except:
    print "CPU STATISTICS UNKNOWN: the stsci_check_cpu script encountered an error."
I also wanted to say that I was only interested in reporting, as we have no need for alerts based on warning or critical thresholds for these systems.

I'd be happy to hear feedback on the script too (edge cases I'm not properly accounting for, improvements, etc.)

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 9:01 am
by slansing
Ah excellent, thank you for sharing it! Would you be interested in uploading it to the exchange site for a wider sample base?

http://exchange.nagios.org/

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 9:28 am
by gambolputty
I will share my humble script on the Exchange.

I've been using Nagios Core for a while (7-ish years), and this is my first foray into the world of XI. So I'm having a bit of trouble discerning what's the same, and what's different between the two. Is there any XI documentation in general that addresses admins like me migrating from Core? It was mentioned that XI uses pnp already, so I just need to figure out the templating and then upload it. I'll try it.

Thanks again for your help.

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 9:36 am
by slansing
Awesome, well welcome to the XI community!

We have a few documents located here:

http://assets.nagios.com/downloads/nagi ... ios_XI.pdf

http://assets.nagios.com/downloads/nagi ... p_Tool.pdf

http://assets.nagios.com/downloads/nagi ... nto_XI.pdf

Though they mainly cover the actual "migrating" process of moving one's environment from Core to XI.

We also have a features PDF here:

http://assets.nagios.com/datasheets/nag ... atures.pdf

Let us know what else you would like to know or see :)

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 10:12 am
by gambolputty
Thanks all for the help so far, I'll take a look at those links. It's going to take me a little bit to start looking within the GUI to make changes like this when I've been doing so much from the command line in Core for so long. :D

I have a question on graphing templates. How can I tell what graphing template a particular service is using (in this case, my custom cpu checker)? I'd like to make a copy of that template, make changes, upload it, then apply it to the performance graphs for those services.

Re: changing the area chart for CPU usage

Posted: Fri Apr 05, 2013 4:10 pm
by abrist
Custom templates are possible, see the following link:
http://docs.pnp4nagios.org/pnp-0.4/tpl_custom

Re: changing the area chart for CPU usage

Posted: Tue Apr 09, 2013 7:37 am
by gambolputty
Thanks again for the quick responses from you and your team. I've looked over the link at http://docs.pnp4nagios.org/pnp-0.4/tpl_custom (scottwilkerson linked it a few days earlier too), and checked out the various templates under the Admin -> Graph Templates link. I still would like to know:

1) How can I determine which graph template is applied to a particular service?

2) How do I set a service to use a different template?

I'm getting good data back from my python CPU checker plugin, but this default graph with layered user /system data is not what my management is looking for. Of course I can look at it and see that 45% user and 45% system makes for a busy CPU, but they [understandably so] would like to see those two data sets stacked on top of one another in the same plane. It just makes more sense for this data.

Re: changing the area chart for CPU usage

Posted: Tue Apr 09, 2013 12:58 pm
by abrist
1. You can check the folder:

Code: Select all

ls /usr/local/nagios/share/pnp/templates.dist/
For .php files named after their service, although most of the graphs use the default.php
2. You may be able to add one to this directory.