SNMP 输出或八位字节(网络流量)

SNMP out or in octets (Network Traffic)

我正在用 C# 编写软件,通过 SNMP 测量或使用八位字节(字节)。我需要在 1000 秒内传递多少字节?

根据我的研究,它的值有时会超时或重置,因为某些结果会给出负值。

.1.3.6.1.2.1.2.2.1.10 用于 .139

中的输入流

在 1024 秒内它给出了 -2,1 MBytes 的结果。

如何准确测量流量(进出)?

编辑:此代码用于计算。它每时每刻都有价值并得到结果。

private void timer1_Tick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            SnmpObject objSnmpObject, objSnmpIfSpeed;

            objSnmpObject = (SnmpObject)objSnmpManager.Get(".1.3.6.1.2.1.2.2.1.16.139");
            objSnmpIfSpeed = (SnmpObject)objSnmpManager.Get(".1.3.6.1.2.1.2.2.1.5.139");

            if (GetResult() == 0)
            {
                float value = Int64.Parse(objSnmpObject.Value);
                float ifSpeed = Int64.Parse(objSnmpIfSpeed.Value);

                float Bytes = (value * 8 * 100 / ifSpeed);
               // float megaBytes = Bytes / 1024;
                sum += Bytes;
                tb_calc.Text = (sum.ToString() + " Bytes");
            }
            _gv_timeSec++;
            lb_timer.Text = _gv_timeSec.ToString();

            Cursor.Current = Cursors.Default;

        }

1.3.6.1.2.1.2.2.1.10IF-MIB::ifInOctets 的 OID,MIB described 作为 Counter32 的 OID,上限为 2^32 -1(十进制为 4294967295)。

"The total number of octets received on the interface, including framing characters.

Discontinuities in the value of this counter can occur at re-initialization of the management system, and at other times as indicated by the value of ifCounterDiscontinuityTime."

引用 this SO answer :

a Counter32 has no defined initial value, so a single reading of Counter32 has no information content. This is why you have to take two (or more) readings to make sense of it. An example of this would be the number of packets received on an ethernet interface. If you take a reading and get back 4 million packets, you haven't learned anything: the wire could have been pulled out of the interface for the past year, or it could be passing millions of packets per second. You have to take multiple readings to know anything.

我推荐 ifHCInOctets .1.3.6.1.2.1.31.1.1.1.6 and ifHCOutOctets .1.3.6.1.2.1.31.1.1.1.10 这是 @k1eran

提到的 OID 的 64 位版本

那些计数器在处理更高速度时不会旋转得那么快。