gpt4 book ai didi

algorithm - 如果 SNMP 计数器的值小于以前的读数,绘图工具应该如何表现?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:43:39 26 4
gpt4 key购买 nike

我正在构建一个小型监控解决方案,想了解在以前的读数大于当前读数的情况下什么是正确/最佳行为。例如 ifHCOutOctets SNMP 对象计算从 Cisco 路由器接口(interface)传输的字节数。如果此计数器重置为 0(例如由于路由器重启),绘图应用程序应如何运行?在我的选项中,以下算法是正确的行为:

if [ ! $prev_val ]; then
# This reading will be used to set the baseline value for "prev_val" variable
# if "prev_val" does not already exist.
prev_val="$cur_val"
elif (( prev_val > cur_val )); then
# Counter value has set to zero.
# Use the "cur_val" variable.
echo "$cur_val"
prev_val="$cur_val"
else
# In case "cur_val" is higher than or equal to "prev_val",
# use the "cur_val"-"prev_val"
echo $(( cur_val - prev_val ))
prev_val="$cur_val"
fi

我还根据上面的算法做了一个小示例图:

bandwidth graph based on algorithm

流量图是基于此构建的:

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

对我来说,这个小算法看起来工作正常。

如果有任何不清楚的地方,请告诉我,我会改进我的问题。

最佳答案

我可以看到你所回应的问题是,在正常操作的情况下是计数器的变化。路由器重启后,它会显示一些绝对值。现在有比较这 2 个的方法。如果你想显示 2 个读数的增量,我建议:

if [ ! $prev_val ]; then
# This reading will be used to set the baseline value for "prev_val" variable
# if "prev_val" does not already exist.
prev_val="$cur_val"
elif (( prev_val > cur_val )); then
# Counter value has set to zero.
# Use the "cur_val" variable.
echo "Router/counter restarted"
# restart the counter as well
prev_val="$cur_val"
else
# In case "cur_val" is higher than or equal to "prev_val",
# use the "cur_val"-"prev_val"
echo $((cur_val-prev_val))
fi

你也可以删除elif部分,只打印负值来指示计数器/路由器的重启

关于algorithm - 如果 SNMP 计数器的值小于以前的读数,绘图工具应该如何表现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30532752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com