[HOWTO] Graph displaying average of several other hosts

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

apex333
Posts: 9
Joined: Sat Jul 09, 2005 7:46 pm
Location: Chicago

[HOWTO] Graph displaying average of several other hosts

Post by apex333 »

All,
I am evaluating Cactii and find it to be a very good tool to review my infrastructure, however I have a question:

Is it possible to monitor the CPU util % of 8 hosts and create the 9th graph, which will display the average CPU util % of all 8 hosts?

On a second note -- are there any reporting capabilities with this tool? Executives/VP's typically love to see reports and statistics...

Thanks,
Richard
Signed;
jas0420
Cacti User
Posts: 91
Joined: Thu Jan 13, 2005 3:58 pm
Location: College Station, TX - USA

Post by jas0420 »

I'll bite since nobody has answered you yet...

To your first question, yes this is possible. Just 44 simple steps. ;) You would need to create a new CDEF to handle the math for you. The instructions below assume that you have already created graphs (or at the very least Data Sources) for the 8 individual CPU's. Please do that first if not.

1) In Cacti's menu bar on the left, click "Graph Management" and it will expand to show more options.
2) Click on "CDEFs".
3) Click "Add" to make a new CDEF. Call it something like "Combined CPU Average" so that you'll be able to find it again.
4) Click "Create"
5) On the CDEF Items table (currently blank) click "Add"
6) Change the CDEF Item type to Custom String
7) For the CDEF Item Value type in

Code: Select all

a,b,+,c,+,d,+,e,+,f,+,g,+,h,+,8,/
8) Click "Create" and you're done with the CDEFs

For #7 above, in theory you could replace the letters a through h with the special data type ALL_DATA_SOURCES_NO_DUPS. I've had bad luck with it with things I was trying to do, so this just manually does averaging. "a" though "h" represent variables that point to Data Sources that we'll add in a bit…

9) Now you need a graph template. Locate and select “Graph Templates” on the menu bar.
10) Create a new template by clicking “Add” in the upper right corner.
11) Give your graph template a meaningful name. “Combined CPU Average” should work again.
12) Give your graph a title. Again, just something meaningful to you.
13) Click “Create”
14) Skip over the “Graph Template Items” for now and go “Add” a “Graph Input Item” on the second section of the screen that you are now on.
15) In the “Name” field, type in “CPU 1”
16) Leave everything else as-is and click “Create”
17) Repeat steps 14 through 16 seven more times, incrementing your name each time “CPU 2”, “CPU 3”, etc. These actually can be named anything you like… You just need to be sure you have one per CPU and that they are uniquely named. So it could be “Server A CPU1”.
18) Now you need to go back to the “Graph Template Items” that we skipped a few steps back. “Add” a new one.
19) Leave the Data Source set to “None”
20) Leave the Color set to “None” (we don’t want to actually see this value being graphed, but we need to do this because it is the process that creates the a, b, c, etc. variables we used in our CDEF)
21) Change the Graph Item Type to “Area”
22) Change the Consolidation Function to “Last”
23) Leave the rest of the values at their default and click “Create”
24) Repeat steps 18 through 23 seven more times
25) Now we create the Graph Template Item that actually graphs the average for you. “Add” one more Graph Template Item
26) The Data Source is still “None” on this one
27) Change the color to whatever you want it to graph in
28) Change the Graph Item Type to however you want the graph displayed (line or area)
29) Change the Consolidation Function to “Last”
30) Now we use the CDEF that you created earlier. In the CDEF Function pull-down, locate and select the "Combined CPU Average" (or whatever you called it) CDEF.
31) Leave “Value” empty
32) Leave “GPRINT Type” at “Normal”
33) In “Text Format” enter whatever you want to see in the legend beside your graph color index. Again, probably something simple like “% Utilization” or something like that.
34) Click “Save”
35) Now the tricky part. Very very important! We have to tie the “Graph Template Items” to the “Graph Item Inputs”. You should be back at a screen to see them all. First, make note of the Item # of the last graph item you created (the one that has the color swab beside it. It should be Item #9, but in case you’ve added other things you’ll need to know it. I will use #9 in the rest of the explanation, so substitute accordingly).
36) Click on the top Graph Item Input (“CPU 1” if you followed my name suggestion above).
37) You should now see a list of all of your Graph Items. Currently none of them are selected. For this first one, select the first dummy graph item “Item #1:Area (Last)” AND also select the actual graph item… “Item #9:Area (Last)”. What that did was associate your “CPU 1” input item to two graph items… The placeholder that creates the variable but doesn’t chart, and the graph item that actually creates the chart.
38) You now need to cycle through the rest of your Graph Item Inputs (“CPU 2”, “CPU 3”, etc.). In each of them, you will again associate it to a “dummy” graph item, and the real “Item #9”. None of the “dummy” graph items will be selected twice, so you will increment through them as you increment through the Graph Item Inputs. Sooooo… “CPU 2” will be associated with Items #2 and #9. “CPU 3” will be associated with Items #3 and #9… and so on.
39) Once you have made all of the associations, save your Graph Template by clicking “Save” in the lower right corner.

So everything up to this point created the back-end shell to place your actual data into. Again, assuming you are already charting your CPU usage individually in 8 other graphs, we will now plug that data into this shell.

40) Click on "Graph Management" again.
41) Click on "Add" in the upper right corner.
42) Locate and select your “Combined CPU Average” Graph Template
43) Leave "Host" set to "None" and click the "Create" button.
44) Up until this point there was probably a lot of this that didn’t make sense, but the screen that comes up now should make it all come together for you. You now should see a “Supplemental Graph Template Data” section where you have 8 pull-down menus that are named “CPU 1”, “CPU 2”, etc (or whatever you called them). Each has a pull-down menu beside it. In the pull-down, you will see a list of alllllllllll of your Data Sources from the graphs you are already creating. In each pull-down, select the Data Source that is tied to one of your CPU’s that you are already graphing. Once you have all of these mapped out on a 1:1 basis, click “Save”.

That’s it! You should now have a graph under Graph Management that is named whatever you called it back in step 12. You can now add this to your Graph Tree.

As for the question on reporting… Personally, I view all of Cacti as a reporting tool. I try to arrange the Graph Tree in a way that lets folks get 1-stop shopping for a group of items that make sense together. The higher-ups that need data can just have a Favorites added in their web browser that gets them to the things they want to see. But in direct answer to your question, no… There is no function native to Cacti that will assemble data/charts and actively email them out to a distribution list or anything. Might poke around here and see if there are any add-ons that someone’s written that would do this.

Hope this helped,
Jason
Last edited by jas0420 on Mon Jul 18, 2005 7:21 pm, edited 2 times in total.
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

I have thought of writing a "Reporting" plugin for Cacti, but am really unsure of what everyone would want. For my purposes, I wouldn't mind seeing a list of every server with Used HD % or top ten closest to being full (its the main issue we deal with). It should be easy enough to assemble, but to take it further than that, I would need know what other types of reports that people would be interested in. Bandwidth used? I could see this getting fairly complex very quickly if it was to allow completely custom reports, but doing a top ten "max" or "average" would be simplistic enough to start out with.

I have already written an add-on that will take a hosts graphs, and email in an embedded HTML message with a little note attached. It would be simple enough to add the graph of the host that had problems, with a note underneat that states the issue found.
apex333
Posts: 9
Joined: Sat Jul 09, 2005 7:46 pm
Location: Chicago

Post by apex333 »

Jason,
This is a very good, comprehensive "how-to" for graphing multiple sources into a single graph. It worked on the first try!!! Very nice.
See sample graph


I figured out a way to graph differently, using "graph management" and manually adding "items" and stacking them with a "cdef of current data source / 8". The only problem is that if I use a "line" to graph (I prefer lines over areas), and the "last item/server" is offline for some-odd reason, it will not draw, hence its unavailability. (attached graph)
Note that I also used multiple data sources; for instance I map "1 Min CPU", "5 Min CPU" and "30 Min CPU".

I would be interested to map multiple data sources to the same graph, (i.e. 1 min cpu, 5 min cpu, 30 min cpu) therefore I will start experimenting with the current template. I am, however open to suggestions.

In regards to CDEF: how do you come up with code/formulas to plug in to CDEF? Is there a guide to the syntax used?

Sincerely,
Richard
Attachments
This graph is generaged from Jason's directions in this post, utilizing the 1 minute cpu data source, only.
This graph is generaged from Jason's directions in this post, utilizing the 1 minute cpu data source, only.
average1.GIF (12.84 KiB) Viewed 72388 times
This graph is generated by dividing the current datasouce by 8 (since I have 8 servers) and stacking them up. Note when server 8 was off-line, it did not draw (right gap). The gap in the middle was switching from cmp.php to cactid.
This graph is generated by dividing the current datasouce by 8 (since I have 8 servers) and stacking them up. Note when server 8 was off-line, it did not draw (right gap). The gap in the middle was switching from cmp.php to cactid.
average2.GIF (11.75 KiB) Viewed 72388 times
Signed;
apex333
Posts: 9
Joined: Sat Jul 09, 2005 7:46 pm
Location: Chicago

Post by apex333 »

In regards to Reporting, there are many nice features which could be reported:
- % availability,
- averages of utilization
- bandwidth total throughput
- etc.

Even setting up email templates to mail out statistics in text format on a daily/weekly/monthly/yearly (for those who don't care :wink: ) basis would be a great idea!!!

I would be open to looking at anything available; my managers love to see weekly statistics in an email...

Richard
Signed;
jas0420
Cacti User
Posts: 91
Joined: Thu Jan 13, 2005 3:58 pm
Location: College Station, TX - USA

Post by jas0420 »

Heh... Literally 4 hours after I wrote what I did about Availability, our IT Director looked at what I was shaping my Cacti website into and asked for Availability reports. So I retract what I said. ;)

As for the gap when the server is offline... Interesting. I can't think of a reason off-hand why it would do that. If server 8 isn't something you can just go power off on a whim, you might try adding a ninth dummy CPU that Cacti couldn't reach. If the gap comes back then, you could catch the graph "in action" and take a look at the graph debug to see if any "oh yeah's" pop out. To get there, when you're viewing the graph under the "Graphs" tab if you click on the magnifying glass in the upper right corner it will take you to a page with only that graph. The magnifying glass will be replaced with a little wrench. Click that and it will detail all of the steps it went through to turn your .rra data into a chart. Migth catch a break and find a clue there.

CDEF's are explained in the docs at the main RRD site: http://www.rrdtool.org

But basically, it is just RPN. If you've ever used an HP calculator (1 ENTER 2 ENTER PLUS) just replace the "ENTERS" with a comma and you have your CDEF string.

Jason
alvaro
Posts: 39
Joined: Wed Mar 23, 2005 8:18 am

Post by alvaro »

Hello All,

I have tried, but RRD returns this:

"ERROR: RPN stack underflow"

Someone can help me ?

Thanks,

Alvaro
jas0420
Cacti User
Posts: 91
Joined: Thu Jan 13, 2005 3:58 pm
Location: College Station, TX - USA

Post by jas0420 »

Can you provide more details about what you tried?
jas
alvaro
Posts: 39
Joined: Wed Mar 23, 2005 8:18 am

Post by alvaro »

I have followed your steps. But, rrd tool/cacti return this error.

Below the configuration's screenshot.

ps: my apologizes for my bad english.


Alvaro
Attachments
cacti1.JPG
cacti1.JPG (114.61 KiB) Viewed 72242 times
cacti2.JPG
cacti2.JPG (68.12 KiB) Viewed 72242 times
cacti3.jpg
cacti3.jpg (94.41 KiB) Viewed 72242 times
jas0420
Cacti User
Posts: 91
Joined: Thu Jan 13, 2005 3:58 pm
Location: College Station, TX - USA

Post by jas0420 »

You seem to have only three unique CPU's that you're adding data sources for. Do you really need all 8? Would imagine that the graph should have still printed, but it is going to be a wrong number since one of them is added in 5 times too many.

Again though, it still should have graphed from what I see...

On your Item #9 details page, you have pointed it to use your "Combined CPU Average" CDEF, correct?

Could you post the debug of your graph?

Jason
apex333
Posts: 9
Joined: Sat Jul 09, 2005 7:46 pm
Location: Chicago

Post by apex333 »

Your CDEF Code is bad. it sould be,
a,b,+,c,+,d,+,e,+,f,+,g,+,h,+,8,/

Richard
Signed;
jas0420
Cacti User
Posts: 91
Joined: Thu Jan 13, 2005 3:58 pm
Location: College Station, TX - USA

Post by jas0420 »

oops. good catch.

Jason
alvaro
Posts: 39
Joined: Wed Mar 23, 2005 8:18 am

Post by alvaro »

Thank you all !!! works very well.

Alvaro
alvaro
Posts: 39
Joined: Wed Mar 23, 2005 8:18 am

Post by alvaro »

Hello All,

How to block my graph scale from 0 to 100. ?

Thank you.

Alvaro
apex333
Posts: 9
Joined: Sat Jul 09, 2005 7:46 pm
Location: Chicago

Post by apex333 »

check the "autoscale" checkbox.

Richard
Signed;
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest