[mrtg] maths in mrtg

Steve Shipway s.shipway at auckland.ac.nz
Tue Oct 20 22:46:24 CEST 2015

While it is easy to do this with RRDTool, to do it in MRTG is a little more


Lets's assume that the OIDs are OID1 (for kVA) and OID2 (for kVAR).


You could use this:


Target[xxxx]: OID1&OID2:community at device

Option[xxxx]: gauge


This would collect the two values into the two metrics of the RRD for
graphing separately.  You would then need to use something like rrdcgi to
construct a custom graphing function to build a graph with a third line,
calculated by the RPN expression:  



Note that we divide by 1000 to get the value in W rather than kW so that the
automatic labels work better.  However, this requires you to create a fairly
complex rrdcgi page with a custom graph, and it may not work well with your
chosen web interface.  Note that, if you are using Routers as your MRTG/RRD
frontend, you can use the routers.cgi*Extension API to embed the output of
another script (such as rrdcgi) within the framework.


Another way to do it would be to have a really complex Target line, so that
the w value is calculated and stored at polling time:


Target[xxxx]: ( sqrt ( ( OID1&pseudoZero:community at device *
OID1&pseudoZero:community at device ) \

     - ( OID2&pseudoZero:community at device * OID2&pseudoZero:community at device
) )  ) \

     / 1000


This will cause things to crash if kVAR > kVA of course, and will not store
the source values (though a separate Target can collect these if you wish).
Note that the spaces around the operators are all significant.


You cannot do it with a postprocessing function, as these only take a single
metric as a parameter.


Probably the best way to do it would be with a custom collection script, but
this would be non-trivial as it would need to take the community and device
name parameters and perform the SNMP lookup itself.  Whether or not you can
do this will depend on your coding ability.




Steve Shipway

T: +64 9 3737 599 ext 86487

E:  <mailto:s.shipway at auckland.ac.nz> s.shipway at auckland.ac.nz

(GNU Terry Pratchett)


From: mrtg [mailto:mrtg-bounces+s.shipway=auckland.ac.nz at lists.oetiker.ch]
On Behalf Of Nick price
Sent: Wednesday, 21 October 2015 2:58 a.m.
To: mrtg at lists.oetiker.ch
Subject: [mrtg] maths in mrtg


For my incoming mains power supply I have a monitor box that gives me kVA
and kVAR values via SNMP  I need to get kW into a graph.


I need to do the following maths  kW=(kVA^2-kVAR^2)^0.5 how do I get mrtg to
do this


Many thanks in advance



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.oetiker.ch/pipermail/mrtg/attachments/20151020/9ef89fc5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5334 bytes
Desc: not available
URL: <http://lists.oetiker.ch/pipermail/mrtg/attachments/20151020/9ef89fc5/attachment.bin>

More information about the mrtg mailing list