我的处理器是双核的,现在根据OID已经把两个单核处理的占有率读出来了(双核就是两个单核),现在想请问下大家我怎么把整个CPU的占有率读取出来,谢谢。愿者探讨SNMP者请加QQ:171514596
以下就是我获得两个单核CPU的占有率代码:
protected void Button1_Click(object sender, EventArgs e) { SimpleSnmp snmp = new SimpleSnmp("127.0.0.1", "WWW"); if (!snmp.Valid) { this.TextBox1.Text = "SNMP agent host name/ip address is invalid."; return; } Dictionary<Oid, AsnType> result = snmp.Walk(SnmpVersion.Ver2, "1.3.6.1.2.1.25.3.3.1.2"); //Dictionary<Oid, AsnType> result = snmp.Walk(SnmpVersion.Ver2, "1.3.6.1.4.1.25506.2.6.1.1.1.1.6"); if (result == null) { this.TextBox1.Text = "No results received."; return; } foreach (KeyValuePair<Oid, AsnType> kvp in result) { this.TextBox1.Text += string.Format("CPU使用率为:{0} {1} {2}", kvp.Key.ToString(), SnmpConstants.GetTypeName(kvp.Value.Type), kvp.Value.ToString() + "%" + "\r\n"); } }
解决了,最后两个单核的百分比相加除以二就好了。
要不对应的算一下平均值