I use Cacti and rrdxport to get the sum of 2 Graphs and it is working fine.
rrdtool xport --start now-5min --end now-5min DEF:out1=sbc1_fs_call_five_min_do_137.rrd:fs_call_five_min_do:LAST DEF:out2=sbc2_fs_call_five_min_do_147.rrd:fs_call_five_min_do:LAST CDEF:sum=out1,out2,+ XPORT:sum:"output sum"
Output:
<xport>
<meta>
<start>1524226500</start>
<step>300</step>
<end>1524226500</end>
<rows>1</rows>
<columns>1</columns>
<legend>
<entry>output sum</entry>
</legend>
</meta>
<data>
<row><t>1524226500</t><v>7.1630000000e+02</v></row>
</data>
</xport>
Now I want to add 4 graphs but I always get the error RPN final stack size != 1.
rrdtool xport --start now-5min --end now-5min DEF:out1=sbc1_fs_call_five_min_do_137.rrd:fs_call_five_min_do:LAST DEF:out2=sbc1_berlin_fs_call_five_min_do_1176.rrd:fs_call_five_min_do:LAST DEF:out3=sbc2_fs_call_five_min_do_147.rrd:fs_call_five_min_do:LAST DEF:out4=sbc2_berlin_fs_call_five_min_do_1187.rrd:fs_call_five_min_do:LAST CDEF:sum=out1,out2,out3,out4,+ XPORT:sum:"output sum" ERROR: RPN final stack size != 1
Why does it work with 2 graphs but not with 4?
thanks for help!
You are incorrectly specifying your RPN function, and have more than one item left in the stack.
This function works as expected:
CDEF:sum=out1,out2,+
This is because the sequence of RPN commands says:
out1
on the stack,out2
on the stack,This results in the stack holding a single item, with a value (out1+out2).
However, your second attempt does this:
CDEF:sum=out1,out2,out3,out4,+
This means:
out1
on the stack,out2
on the stack,out3
on the stack,out4
on the stack,As a result, the stack now holds three things -- out1, out2, and (out3+out4). RRDTool checks the stack size to catch any RPN errors, and errors because it sees more than one item left in the stack.
What you should do is to add two more addition operations to your definition:
CDEF:sum=out1,out2,out3,out4,+,+,+
This adds two more steps to the RPN, to add in the remaining two items on the stack and obtain the result you want.
I suggest you work through the RPN tutorial to gain a better understanding of how to specify RPN.