douwei2966 2018-09-05 06:25
浏览 72

无法使用SNMP获取PHP中的实际当前使用情况和可用RAM

Im planning to fetch RAM usage on server,i tried SNMP in PHP on my own pc but when i wanna get the percentage usage of RAM,that return is not the real RAM usage compare with system monitor on my pc.

i have read this solution below but still i didnt get right value

(Used – buffers – cached) / Total * 100 = % memory used

So you could get the following (expressed as Perl code):

my $memRealTotalOID = '.1.3.6.1.4.1.2021.4.5.0';

my $memRealAvailOID = '.1.3.6.1.4.1.2021.4.6.0';

my $memRealBuffersOID = '.1.3.6.1.4.1.2021.4.14.0';

my $memRealCachedOID = '.1.3.6.1.4.1.2021.4.15.0';

Memory Calculations my $memRealUsed = $memRealTotal - $memRealAvail;

Then you can alert on % RAM used:

my $realPercent = (($memRealUsed - $memRealBuffers - $memRealCached )/ $memRealTotal) * 100;

Here is my code and the result:

snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
    $memRealTotalOID = snmpget("127.0.0.1", "public", ".1.3.6.1.4.1.2021.4.5.0");
    $memRealAvailOID = snmpget("127.0.0.1", "public", ".1.3.6.1.4.1.2021.4.6.0");
    $memRealBuffersOID = snmpget("127.0.0.1", "public",'.1.3.6.1.4.1.2021.4.14.0');
    $memRealCachedOID = snmpget("127.0.0.1", "public",'.1.3.6.1.4.1.2021.4.15.0');
    $memRealUsed = $memRealTotalOID - $memRealAvailOID;

    $realPercent = (($memRealUsed - $memRealBuffersOID - $memRealCachedOID) / $memRealTotalOID) * 100;
    print_r($realPercent);

the current result is = 82.55542380

meanwhile system monitor is showing (89%): enter image description here

Did i read wrong solution or wrong calculation?Any help pls

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序