[HOWTO] Use VDEF items

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

Post Reply
JasperJ
Posts: 3
Joined: Sat Aug 16, 2008 3:39 pm

[HOWTO] Use VDEF items

Post by JasperJ »

Hi,

I've figured out something that I consider fairly cool.

When you graph something like fan speeds, you'll often find that the values of each fan will stay within a very narrow band, but they won't necessarily be terribly close together, so you can't simply use an appropriately set scale to see everything usefully, and the graph will not be terribly informative:

http://www.insaneoc.com/graphs/graph_370.html

To solve this, I decided that I wanted to graph the *difference* between the given data point and the average value of the sensor over time. In other words, how much more or less is it now than it usually is?

Here's the result, and this is how I accomplished it.

http://www.insaneoc.com/graphs/graph_413.html

With some help from a friend, I figured out that what I wanted from RRDtool was VDEF:average_datasource=datasource,AVERAGE. VDEFs are like CDEFs, except they work on the entire dataset, rather than just each value individually. In the case of the VDEF above, it first puts the entire datasource (probably just the portion that coincides with the graph you're making. I think) on the stack, and then AVERAGE, obviously, takes that and returns a single value representing the average of the datasource. Note that VDEFs exist from RRDtool 1.2 onward only.

Now, cacti does not support VDEFs in any direct way, so this was a bit tricky. I figured out that when you make a cacti CDEF, the strings in that CDEF get passed pretty much verbatim to RRDtool, though. So what I ended up doing in order to draw a LINE2 respresenting the difference between the average of the dataset as a whole and the current value was the following:

First, insert one graph item with type COMMENT, and apply the CDEF "Make average, stick in avgCURRENT_DATA_SOURCE". This CDEF consists solely of a single Custom String: CURRENT_DATA_SOURCE VDEF:avgCURRENT_DATA_SOURCE=CURRENT_DATA_SOURCE,AVERAGE

Assuming for the moment that the current data source is named 'a' by cacti, this translates into a piece of RRDtool commandline like:

CDEF:cdefa=a VDEF:avga=avg,AVERAGE

Because the item is a COMMENT, the cdefa that is produced is not used in the rest of the graph definition, but we *have* defined a variable "avga".

The next step is simple: Add a LINE2 and apply the CDEF "graph diff with avgCURRENT_DATA_SOURCE", which consists of CURRENT_DATA_SOURCE,avgCURRENT_DATA_SOURCE,- .

Because cacti uses the same data source identifier for both the COMMENT and LINE2 items, avgCURRENT_DATA_SOURCE will work across the two items.

Other graphs that use this trick:

http://www.insaneoc.com/graphs/graph_414.html
http://www.insaneoc.com/graphs/graph_415.html
Attachments
Fan speeds - Deviation from average.
Fan speeds - Deviation from average.
graph_413_2.png (49.19 KiB) Viewed 17501 times
Graph template
Graph template
cacti1.png (27.77 KiB) Viewed 17501 times
CDEF 1
CDEF 1
cacti-cdef1.png (7.49 KiB) Viewed 17501 times
CDEF 2
CDEF 2
cacti-cdef2.png (8.72 KiB) Viewed 17501 times
Fan speeds
Fan speeds
agraph_370_2.png (31 KiB) Viewed 17501 times
Last edited by JasperJ on Wed Aug 20, 2008 3:22 am, edited 1 time in total.
mgb
Cacti User
Posts: 124
Joined: Mon Jun 21, 2004 4:06 am
Location: North of the Netherlands

Post by mgb »

Very impessive,

I'm going to try this out on some of my temp graphs i have. This will be more useful than the current graphs we are seeing.

Thanx
koe
Posts: 6
Joined: Thu Oct 11, 2007 9:03 am

HOW TO VDEF total

Post by koe »

Hi JasperJ

Thanks for your tips with VDEF.

I'm trying to use the VDEF TOTAL in the graph template to obtain the total data accumulated for a determinated time range ( the area of the graph! ) but I can not do it !

Could you help me? How can I build a graph template with VDEF TOTAL?

Thanks.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Wow, that's indeed cool. It's like a "rrdtool graph injection" vulnerability :lol:
We should fix this security issue asap :o
But it does not really replace a full VDEF support. This is still to come :cry:
Reinhard
hurgh
Posts: 13
Joined: Wed Oct 11, 2006 2:40 am
Contact:

Re: [HOWTO] Use VDEF items

Post by hurgh »

Hi All,

I know this is an old post, but I just wanted to let you know that I ended up using this method to create a 95th percentile line (HRULE) along a graph.

I didnt use the other 95th percentile method (through cacti) due to the fact that I wanted the 95th percentile for a counter that was not bandwidth related (not bits or bytes).

My graph was plotting request time for a HTTP GET and I wanted to get the 95th percentile for the request time.

It would be great if Cacti could have a VDEF function just like the CDEF area, that way a "hack" like this would not be required.

Thanks

Allan
TheDreamer
Posts: 2
Joined: Fri Jun 22, 2012 9:51 pm

Re: [HOWTO] Use VDEF items

Post by TheDreamer »

I found myself wanting to do something like this, but alas, I'm on 0.88a and can't do this.

Because, quotes are added around the custom string which prevents the hack from working.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: [HOWTO] Use VDEF items

Post by gandalf »

As said, we had to prevent injection attacks. VDEF support is part of 089 which awaits testing phase
R.
Velociraptor
Posts: 2
Joined: Tue Jan 07, 2014 11:42 am
Location: Friedrichshafen, Germany

Re: [HOWTO] Use VDEF items

Post by Velociraptor »

Hi gandalf,

I am desperately waiting for VDEF TOTAL to be usable in Cacti so I can graph things like power consumption properly. Is this feature still planned for 0.8.9?

Regards
Velociraptor
jaslavko
Posts: 4
Joined: Tue Jun 02, 2015 11:32 am

Re: [HOWTO] Use VDEF items

Post by jaslavko »

Need to say, if someone else will tray it, that this is not working now (Cacti 8.8c), because the CDEF definition is quoted (a fix of injection, mentioned by gandalf early?) and it ends with Segmentation fail in my environment with RRDTool 1.5.31.5.3. This Segmentation fail is not reported by Cacti and the output of Cacti Graph debug is simple empty - no graph, no result from RRDTool.

regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest