Can CDEF be used to display percentages for graph points

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
pav
Posts: 6
Joined: Sat Jan 10, 2009 5:31 pm
Location: New Zealand

Can CDEF be used to display percentages for graph points

Post by pav »

Hi,

Can the CDEF's in cacti be used take say 5 values in a RRD file and graph the percentages that each value has based?

Eg:

data source a = 10
data source b = 25
data source c = 10
data source d = 50
data source e = 05

Using normal math the formula would be
a/(a+b+c+d+e)*100
b/(a+b+c+d+e)*100
c/(a+b+c+d+e)*100
d/(a+b+c+d+e)*100
e/(a+b+c+d+e)*100

I've tried the following in Cacti:

Item 1 Special Data Source: CURRENT_DATA_SOURCE
Item 2 Operator: /
Item 3 Special Data Source: ALL_DATA_SOURCES_NODUPS
Item 4 Operator: *
Item 5 Custom String: 100

And assigned this CDEF to all the data sources in a graph but the graph will not generate. I enabled debug and the output is below.

I tried the command and rrdtool reports:
ERROR: invalid rpn expression in: c,/,,*,100

I read up about the RPN format and it looks like there is a problem with Cacti substituting the all data_sources with a ',' comma instead of the rpn format a,b,+,c,+,d,+,e,+,a,/ is what I think it should be generating?

Any one using the "All Sources" data source in Cacti? I could try the custom string, will my formula work?

Thanks,


Antonio

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=0 \
--end=0 \
--title="Network Scores Percentage" \
--rigid \
--base=1000 \
--height=200 \
--width=600 \
--alt-autoscale-max \
--lower-limit=1 \
--units-exponent=0 \
--vertical-label="Scores" \
--font TITLE:11:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font AXIS:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font LEGEND:9:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font UNIT:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
DEF:a="/var/www/cacti/rra/dummy_host_683.rrd":mos5:LAST \
DEF:b="/var/www/cacti/rra/dummy_host_683.rrd":mos4:LAST \
DEF:c="/var/www/cacti/rra/dummy_host_683.rrd":mos3:LAST \
DEF:d="/var/www/cacti/rra/dummy_host_683.rrd":mos2:LAST \
DEF:e="/var/www/cacti/rra/dummy_host_683.rrd":mos1:LAST \
CDEF:cdefc=c,/,,*,100 \
CDEF:cdefe=d,/,,*,100 \
CDEF:cdefg=e,/,,*,100 \
GPRINT:a:LAST:"MOS5 =%8.0lf" \
GPRINT:b:LAST:"MOS 4 =%8.0lf" \
LINE1:cdefc#74C366FF:"MOS3" \
GPRINT:cdefc:LAST:"MOS3 =%8.0lf" \
LINE1:cdefe#FFAB00FF:"MOS2" \
GPRINT:cdefe:LAST:"MOS2 =%8.0lf" \
LINE1:cdefg#8D00BAFF:"MOS1" \
GPRINT:cdefg:LAST:"MOS 1 =%8.0lf"
pav
Posts: 6
Joined: Sat Jan 10, 2009 5:31 pm
Location: New Zealand

Also tried...

Post by pav »

FYI: I modified the CDEF to:

Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Operator: /
Item #3 Custom String: a,b,+,c,+,d,+,e,+
Item #4 Operator:
Item #5 Custom String: 100

RRDTool Command:

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=0 \
--end=0 \
--title="Network Percentage" \
--rigid \
--base=1000 \
--height=200 \
--width=600 \
--alt-autoscale-max \
--lower-limit=1 \
--units-exponent=0 \
--vertical-label="Scores" \
--font TITLE:11:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font AXIS:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font LEGEND:9:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
--font UNIT:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
DEF:a="/var/www/cacti/rra/dummy_host_4_683.rrd":5:LAST \
DEF:b="/var/www/cacti/rra/dummy_host_4_683.rrd":4:LAST \
DEF:c="/var/www/cacti/rra/dummy_host_4_683.rrd":3:LAST \
DEF:d="/var/www/cacti/rra/dummy_host_4_683.rrd":2:LAST \
DEF:e="/var/www/cacti/rra/dummy_host_4_683.rrd":1:LAST \
CDEF:cdefa=a,/,a,b,+,c,+,d,+,e,+,*,100 \
CDEF:cdefb=b,/,a,b,+,c,+,d,+,e,+,*,100 \
CDEF:cdefc=c,/,a,b,+,c,+,d,+,e,+,*,100 \
CDEF:cdefe=d,/,a,b,+,c,+,d,+,e,+,*,100 \
CDEF:cdefg=e,/,a,b,+,c,+,d,+,e,+,*,100 \
GPRINT:cdefa:LAST:"5 =%8.0lf" \
GPRINT:cdefb:LAST:" 4 =%8.0lf" \
LINE1:cdefc#74C366FF:"3" \
GPRINT:cdefc:LAST:"3 =%8.0lf" \
LINE1:cdefe#FFAB00FF:"2" \
GPRINT:cdefe:LAST:"2 =%8.0lf" \
LINE1:cdefg#8D00BAFF:"1" \
GPRINT:cdefg:LAST:" 1 =%8.0lf"

This also produces no graph? I previously had which for obvious reasons is wrong (I don't want to divide the total sum of all data sources by the current data source:
Item #1 Custom String: a,b,+,c,+,d,+,e,+
Item #2 Operator: /
Item #3 Special Data Source: CURRENT_DATA_SOURCE
Item #4 Operator:
Item #5 Custom String: 100

I got the graph attached!
Attachments
graph_image.png
graph_image.png (18 KiB) Viewed 8640 times
pav
Posts: 6
Joined: Sat Jan 10, 2009 5:31 pm
Location: New Zealand

Work around to using ALL_DATA_SOURCES CDEF function in Cacti

Post by pav »

FYI: The following worked.

Item #1 Special Data Source: CURRENT_DATA_SOURCE
Item #2 Custom String: a,b,c,d,e,+,+,+,+
Item #3 Operator: /
Item #4 Custom String: 100
Item #5 Operator: *

It appears that the Cacti CDEF option "ALL_DATA_SOURCES" does not work. Can someone advise otherwise?

If a coder can fix the Cacti code in the graph template generation to simply replace the ALL_DATA_SOURCES variable with a function that identifies the number of data sources and simply creates a string with the Data Sources starting with a, then b, ... and then appends pluses ",+'s" as many times as there is Data Sources, then that will work nicely.

This may help the next person trying to use CDEF's to convert graph points to a percentage for a percentage graph generation.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest