[HOWTO] Use VDEF items
Moderators: Developers, Moderators
[HOWTO] Use VDEF items
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
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.
- graph_413_2.png (49.19 KiB) Viewed 17447 times
-
- Graph template
- cacti1.png (27.77 KiB) Viewed 17447 times
-
- CDEF 1
- cacti-cdef1.png (7.49 KiB) Viewed 17447 times
-
- CDEF 2
- cacti-cdef2.png (8.72 KiB) Viewed 17447 times
-
- Fan speeds
- agraph_370_2.png (31 KiB) Viewed 17447 times
Last edited by JasperJ on Wed Aug 20, 2008 3:22 am, edited 1 time in total.
HOW TO VDEF total
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.
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.
Re: [HOWTO] Use VDEF items
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
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
-
- Posts: 2
- Joined: Fri Jun 22, 2012 9:51 pm
Re: [HOWTO] Use VDEF items
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.
Because, quotes are added around the custom string which prevents the hack from working.
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Re: [HOWTO] Use VDEF items
As said, we had to prevent injection attacks. VDEF support is part of 089 which awaits testing phase
R.
R.
-
- Posts: 2
- Joined: Tue Jan 07, 2014 11:42 am
- Location: Friedrichshafen, Germany
Re: [HOWTO] Use VDEF items
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
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
Re: [HOWTO] Use VDEF items
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
regards
Who is online
Users browsing this forum: No registered users and 0 guests