主进程 (gwd) 通过 vc_process_monitor 监控其内存,从而确保它从不使用超过 75% 的可用内存。因此,总系统内存监控使用警告阈值 80% 和严重阈值 90%。
您可以使用阈值监控网关,这些阈值提供警告或严重状态,以便在潜在问题影响服务之前指示这些问题。下表列出了阈值和建议的措施。
阈值状态 | 阈值 | 建议的纠正措施 |
---|---|---|
警告 | 80% | 如果内存超过警告阈值:
继续主动监控并检查利用率是否增加。 |
严重 | 90% | 如果内存超过严重阈值:
如果再次观察到该问题:
注: 在重新均衡网关之前,请确认容量衡量指标在建议的限制内。有关容量衡量指标的更多信息,请参阅
网关组件的容量。
|
以下是用于监控内存使用情况的示例 Python 脚本:
注: 您还可以使用 Telegraf 监控内存使用情况。有关更多信息,请参阅
使用 Telegraf 监控网关。
#!/usr/bin/env python from optparse import OptionParser import sys # Parse commandline options: parser = OptionParser(usage="%prog -w <warning threshold>% -c <critical threshold>% [ -h ]") parser.add_option("-w", "--warning", action="store", type="string", dest="warn_threshold", help="Warning threshold in absolute(MB) or percentage") parser.add_option("-c", "--critical", action="store", type="string", dest="crit_threshold", help="Critical threshold in ansolute(MB) or percentage") (options, args) = parser.parse_args() def read_meminfo(): meminfo = {} for line in open('/proc/meminfo'): if not line: continue (name, value) = line.split()[0:2] meminfo[name.strip().rstrip(':')] = int(value) return meminfo if __name__ == '__main__': if not options.crit_threshold: print "UNKNOWN: Missing critical threshold value." sys.exit(3) if not options.warn_threshold: print "UNKNOWN: Missing warning threshold value." sys.exit(3) is_warn_pct = options.warn_threshold.endswith('%') if is_warn_pct: warn_threshold = int(options.warn_threshold[0:-1]) else: warn_threshold = int(options.warn_threshold) is_crit_pct = options.crit_threshold.endswith('%') if is_crit_pct: crit_threshold = int(options.crit_threshold[0:-1]) else: crit_threshold = int(options.crit_threshold) if crit_threshold >= warn_threshold: print "UNKNOWN: Critical percentage can't be equal to or bigger than warning percentage." sys.exit(3) meminfo = read_meminfo() memTotal = meminfo["MemTotal"] memFree = meminfo["MemFree"] + meminfo["Buffers"] + meminfo["Cached"] memFreePct = 100.0*memFree/memTotal if (is_crit_pct and memFreePct <= crit_threshold) or (not is_crit_pct and memFree/1024<=crit_threshold): print "CRITICAL: Free memory is at %2.0f %% ( %d MB free our of %d MB total)" % (memFreePct, memFree/1024, memTotal/1024) sys.exit(2) if (is_warn_pct and memFreePct <= warn_threshold) or (not is_warn_pct and memFree/1024<=warn_threshold): print "WARNING: Free memory is at %2.0f %% ( %d MB free our of %d MB total)" % (memFreePct, memFree/1024, memTotal/1024) sys.exit(1) else: print "OK: Free memory is at %2.0f %% ( %d MB free our of %d MB total)" % (memFreePct, memFree/1024, memTotal/1024) sys.exit(0)