다음 스크립트를 확인하십시오.
시스템 메모리가 부족할 때 응용 프로그램 / 스크립트 경고가 필요합니다
#!/bin/bash
#Minimum available memory limit, MB
THRESHOLD=400
#Check time interval, sec
INTERVAL=30
while :
do
free=$(free -m|awk '/^Mem:/{print $4}')
buffers=$(free -m|awk '/^Mem:/{print $6}')
cached=$(free -m|awk '/^Mem:/{print $7}')
available=$(free -m | awk '/^-\/+/{print $4}')
message="Free $free""MB"", buffers $buffers""MB"", cached $cached""MB"", available $available""MB"""
if [ $available -lt $THRESHOLD ]
then
notify-send "Memory is running out!" "$message"
fi
echo $message
sleep $INTERVAL
done
PHP :
#!/usr/bin/php
<?php
$alert_percent=($argc>1)?(int)$argv[1]:90;
//$interval=($argc>2):(int)$argv[2]:25;
//while(true)
//{
exec("free",$free);
$free=implode(' ',$free);
preg_match_all("/(?<=\s)\d+/",$free,$match);
list($total_mem,$used_mem,$free_mem,$shared_mem,$buffered_mem,$cached_mem)=$match[0];
$used_mem-=($buffered_mem+$cached_mem);
$percent_used=(int)(($used_mem*100)/$total_mem);
if($percent_used>$alert_percent)
exec("notify-send 'Low Memory: $percent_used% used'");
//sleep($interval);
//}
exit();
?>
free -m
것이 좋은 방법 인 것 같습니다 .