It’s always good to learn something new . Actually I did it because of three reasons:
Laziness: I currently also have another virtual instance running Observium, just to keep track of volumes, loads, suspicious traffic and port states. That’s another system to maintain and to look at. Now (or fully functioning in the future) I just use another dashboard in Grafana and send my alarms to my Telegram Bot.
Look: Grafana looks much better than these “old fashioned” CACTI graphs. Yes, they work and yes they are sometimes easier to implement. But there is only one way to display the data.
Daily Business: I’ve come along multiple Grafana installation during my work, always focussing on complete different data and then also differentiating between a technical view and a “management” view.
But yes as you said, it is currently a bit more configuration to be done. I think not every destination device needs the calculation, I was happy to get it working with that way for now. Maybe I find out the correct OID for throughput . But I think with a small script this “addSNMPItem”-process gets easy.
Openhab will help to watch my switchports(state), I saw someone adding printer ink level, so there is really a lot more to add, without using another different tool.
Regarding the Performance: I currently run 12 + 48 SNMP request every 60s, and it does nothing really noticable to my 1GB RAM VM:
Java openhab is taking ~50% all the time
Grafana takes ~3% every minute
influxdb takes ~8% every now and then (I guess if incoming data is processed)
I think, for a big installation just for collecting snmp from over 10.000+ sources openhab2 will not be in my consideration, but for a small “AllinOne”-solution it is really usefull.
Thanks for this, looks great. Using your Rules and Items I’m having an issue however. I get the error below, which I believe is something to do with persistence not working as I’d expect.
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Internet Traffic Out, calculate difference': 'previousStateValue' is not a member of 'org.eclipse.smarthome.core.library.items.NumberItem'; line 16, column 35, length 39
the error is related to the rule
did you modify anything versus what Maximo posted? (watch out: his second rule is cut off and he didn’t list all Items)
it should be:
rule "fw traffic dmz out updated, calculate difference"
when
Item fw_traffic_dmz_out received update
then
var float currentStateValue = (fw_traffic_dmz_out.state as DecimalType).floatValue
var float previousStateValue = (fw_traffic_dmz_out.previousState.state as DecimalType).floatValue
var float diff = (currentStateValue - previousStateValue)/8
fw_traffic_dmz_out_diff.postUpdate(diff)
end
you need to create the corresponding Items of course.
He gave some examples, not the complete list
rule "Internet Traffic In, calculate difference"
when
Item Internet_Traffic_In received update
then
var Number currentStateValue = (Internet_Traffic_In.state as DecimalType)
var Number previousStateValue = (Internet_Traffic_In.previousStateValue.state as DecimalType)
var Number diff = (currentStateValue - previousStateValue)/8
internet_in_diff.postUpdate(diff)
end
rule "Internet Traffic Out, calculate difference"
when
Item Internet_Traffic_Out received update
then
var Number currentStateValue = (Internet_Traffic_Out.state as DecimalType)
var Number previousStateValue = (Internet_Traffic_Out.previousStateValue.state as DecimalType)
var Number diff = (currentStateValue - previousStateValue)/8
internet_out_diff.postUpdate(diff)
end
if you recently deployed JDBC to make this work: try to troubleshoot it
post the services/jdbc.cfg and check the logs for related entries
check also the destination DB for entered data
Thanks @tmcgee I’ll give that a go and see what results I get.
I think I’ve got an issue with my persistence configuration and that’s why I’m getting the error. So I need to troubleshoot that and get it working. After doing a reboot of my server I found that all of my previous values and states were null. So it would suggest either I’ve changed something and got it wrong or because I’m using two different persistence databases I’ve caused an unusual scenario.
Maybe a good time to complete a refresh build of my server and update to the latest version of openHAB.
Once again, thanks for your help and to everyone else that has contributed to this thread.
I am trying to make your solution work, but I am a little confused.
I think the data might be incorrect this way as you are polling the difference on SNMP every 60 seconds, do you not need to divide it by 60 at some point to get a correct value?
I was loading my network down and the numbers I get does not seem right. maybe we need some more calculation to get the values to be correct?
By the way I am using the following script to change it to Mbps but it does also not take in the factor of the polling every 60 seconds
(function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
var byteUnits = [' kbps', ' Mbps', ' Gbps', ' Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
})(input)
I think the correct way might be? or am I wrong here
rule "WAN_IN, calculate difference"
when
Item WAN_IN received update
then
var float currentStateValue = (WAN_IN.state as DecimalType).floatValue
var float previousStateValue = (WAN_IN.historicState(now.minusSeconds(60)).state as DecimalType).floatValue
var float diff = (currentStateValue - previousStateValue)*8/60
WAN_IN_diff.postUpdate(diff)
end
My item file
Number WAN_IN_diff (Bandwith_Chart)
Number WAN_IN { snmp="<[192.168.1.1:public:.1.3.6.1.2.1.2.2.1.10.4:60000]" }
to be honest, I stopped investigating and changing my function, because I found a better (easier) way in grafana.
But I think you are right, I forgot the devision by the time between two values.
Does it work with the “now.minusSecond(60)”? Can’t it happen that you don’t get a value back? Because you only trigger the request every 60 seconds, it could be, that it take 1 second that the value is actually requested. And if the next value is requested on time you might don’t get a value back.