【OPM】服务器内存利用率取值、计算规则

【OPM】服务器内存利用率取值、计算规则

对于服务器内存利用率取值和计算方式:
一.通过 SNMP 计算内存利用率(Windows\Linux 通用)
通过 SNMP 计算内存利用率有两种方式(自动优先使用方式 1)
方式 1.如果 hrStorageType OID (.1.3.6.1.2.1.25.2.3.1.2)返回一个包含 hrStorageRam 的值:
(1)注意 hrStorageType OID (.1.3.6.1.2.1.25.2.3.1.2) 的实例,其中包含 hrStorageRam 作为值。

(2)内存总使用量计算:
通过 hrStorageUsed OID (.1.3.6.1.2.1.25.2.3.1.6)  及 hrStorageAllocationUnits OID(.1.3.6.1.2.1.25.2.3.1.4) 对应(1)中 hrStorageRam 实例索引取值并相乘,得到的结果单位为字节,除以1048576得到单位为 MB 的值。
计算公式:
总内存使用(单位 MB) = [hrStorageUsed 的实例值 (.1.3.6.1.2.1.25.2.3.1.6) * hrStorageAllocationUnits 的实例值 (.1.3.6.1.2.1.25.2.3.1.4)] / 1048576

(3)总内存大小
通过下方查询语句查询内存总大小:

总内存大小  = 语句的输出 [Select RAMSIZE from opmanagerobject where name ='<Replace the Device MO name here>';](单位 MB)
<Replace the Device MO name here>替换为设备监视名,在 OPM 中,选中具体设备,在设备的概览界面上方 URL 最后的一段,可能为机器名或 IP,企业版还会包含探针标记。可参考下图位置获取:


同时,通过 hrMemorySize OID (.1.3.6.1.2.1.25.2.2) 获取的值除以1024也可以得到相同大小、单位为 MB 的值。

(4)内存利用率 = 总内存使用量/总内存大小*100% (单位%)

示例:
通过对一台 Windows 2016 服务器按步骤执行上述操作:
(1)hrStorageType OID (.1.3.6.1.2.1.25.2.3.1.2)

hrStorageType.4:-->.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTypes.hrStorageRam
hrStorageType.3:-->.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTypes.hrStorageVirtualMemory
hrStorageType.2:-->.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTypes.hrStorageCompactDisc
hrStorageType.1:-->.iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTypes.hrStorageFixedDisk

其中,取到的实例 4 包含“hrStorageRam”作为值

(2)hrStorageUsed OID (.1.3.6.1.2.1.25.2.3.1.6)  & hrStorageAllocationUnits OID(.1.3.6.1.2.1.25.2.3.1.4) 取对应.4的值。

hrStorageUsed.4:-->96811
hrStorageUsed.3:-->106977
hrStorageUsed.2:-->2343303
hrStorageUsed.1:-->12479655

hrStorageAllocationUnits.4:-->65536
hrStorageAllocationUnits.3:-->65536
hrStorageAllocationUnits.2:-->2048
hrStorageAllocationUnits.1:-->4096

总内存使用 = 96811*65536/1048576 = 6050.688(MB)

(3)总内存大小

hrMemorySize.0:-->8289780

总内存大小 = 8289780/1024 = 8095.48828 (MB)

(4)内存利用率

内存利用率 = 6050.688/8095.48828*100% = 74.74%,产品中显示为 74%

方式 2.如果 hrStorageType OID (.1.3.6.1.2.1.25.2.3.1.2)返回一个 包含 hrStorageRam 的值:
通过 hrSWRunPerfMem OID (.1.3.6.1.2.1.25.5.1.1.2) 获取所有实例值总和,再除以 1024 得到总内存使用(MB)
hrSWRunPerfMem OID (.1.3.6.1.2.1.25.5.1.1.2)取的是所有进程占用的内存数值(单位 KB)
再除以总内存大小,得到内存利用率。
公式:
内存利用率 = [ hrSWRunPerfMem OID (.1.3.6.1.2.1.25.5.1.1.2) 的所有实例值的总和] / 1024] / 总内存大小 *100%

二.对于 Linux 服务器通过 CLI 取值命令:

/usr/bin/free -b | awk '/Mem:|cache:/ {print $2,$3}' | sed 'N;s/\n/ /' | awk '{if($4!=""){print ($4*100)/$1}else{print ($2*100)/$1}}'

自动返回一个百分比值。

APM通过 SNMP 协议对 Windows/Linux 服务器取值、计算规则参考下方链接:
https://support.manageengine.cn/portal/zh/kb/articles/apm-%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%86%85%E5%AD%98%E5%88%A9%E7%94%A8%E7%8E%87%E8%AE%A1%E7%AE%97%E8%A7%84%E5%88%99-snmp