algorithm - How should graphing tool behave in case SNMP counter has smaller value than previous reading? -


i'm building small monitoring solution , understand correct/best behavior in situation previous reading larger current reading. example ifhcoutoctets snmp object counts bytes transmitted interface in cisco router. how should graphing application behave if counter resets 0 example because of router reboot? in option following algorithm correct behavior:

if [ ! $prev_val ];   # reading used set baseline value "prev_val" variable   # if "prev_val" not exist.   prev_val="$cur_val" elif (( prev_val > cur_val ));   # counter value has set zero.   # use "cur_val" variable.   echo "$cur_val"   prev_val="$cur_val" else   # in case "cur_val" higher or equal "prev_val",   # use "cur_val"-"prev_val"   echo $(( cur_val - prev_val ))   prev_val="$cur_val" fi 

i made small example graph based on algorithm above:

bandwidth graph based on algorithm

traffic graph built based on this:

reading 1: cur_val=0, prev_val 0 reading 2: 0-0=0(0 mbps), cur_val=0, prev_val 0 reading 3: 20-0=20(160 mbps), cur_val=20, prev_val 20 reading 4: 20-20=0(0 mbps), cur_val=20, prev_val 20 reading 5: 50-20=30(240 mbps), cur_val=50, prev_val 50 reading 6: 40(320mbps), cur_val=40, prev_val 40 reading 7: 70-40=30(240 mbps), cur_val=70, prev_val 70 reading 8: no data snmp agent reading 9: 90-70=20(160 mbps), cur_val=90, prev_val 90 

to me looks small algorithm works correctly.

please let me know if unclear i'll improve question.

the problem can see echoing in case of normal operation change of counter. after router reboot, show absolute value. there way compare these 2. if want show delta of 2 reading suggest:

if [ ! $prev_val ];   # reading used set baseline value "prev_val" variable   # if "prev_val" not exist.   prev_val="$cur_val" elif (( prev_val > cur_val ));   # counter value has set zero.   # use "cur_val" variable.   echo "router/counter restarted"   # restart counter   prev_val="$cur_val" else # in case "cur_val" higher or equal "prev_val", # use "cur_val"-"prev_val"   echo $((cur_val-prev_val)) fi 

you can remove elif part , print negative value indicate restart of counter/router


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -