########################################
rec_start()
{
rm -f /var/run/acs.* >/dev/null 2>&1
touch /var/run/acs.start
service jboss start >/dev/null 2>&1
}
rec_stop()
{
touch /var/run/acs.stop
service jboss stop >/dev/null 2>&1
}
get_asg_uptime()
{
if ! pgrep -x run.sh >/dev/null 2>&1
then
restart_day=-1;
restart_hour=-1;
asg_uptime_str="ASG NOT RUNNING"
else
if [ -r /var/run/acs.pid ]
then
asg_starttime=`ls -l --time-style=+%s /var/run/acs.pid | awk '{ print $6 }'`
current_time=`date +%s`
asg_up_sec=$(( current_time - asg_starttime ))
asg_uptime_str=`format_uptime $asg_up_sec`
else
asg_uptime_str=""
fi
fi
echo -n "$asg_uptime_str"
}
########################################
# /etc/inittab
# acs:345:respawn:/opt/alarmserver/bin/ACSMon
# init q
while [ 1 = 1 ]
do
if [ ! -e "/var/run/acs.stop" ]; then
#monitor jboss
if ! ps -ef | grep run.sh | grep -v grep &>/dev/null
then
/etc/init.d/jboss start &>/dev/null
fi
fi
# Pid file
if ps -ef | grep run.sh | grep -v grep &>/dev/null
then
if [ ! -e "/var/run/acs.pid" ] ; then
PID=$(ps -ef | grep 'bin/run.sh' | grep -v grep | awk '{print $2}')
echo $PID > /var/run/acs.pid
fi
else
if [ -e "/var/run/acs.pid" ] ; then
rm -rf /var/run/acs.pid
fi
fi
done
########################################
get_mem_total()
{
rc=`cat /proc/meminfo | grep "MemTotal" | sed 's/^[^0-9]*//'`
echo -n "$rc"
}
get_mem_free()
{
rc=`free | grep "buffers/cache" | awk '{ printf("%d kB", $4); }'`
echo -n "$rc"
}
get_mem_usage()
{
free | awk 'BEGIN{
mem_pi = 0.8;
swap_pi = 1 - mem_pi;
}
{
if ($0 ~ /Mem:/)
{
mem_total = $2;
}
if ($0 ~ /buffers\/cache/)
{
mem_used = $3;
}
if ($0 ~ /Swap:/)
{
swap_total = $2;
swap_used = $3;
}
}
END{
mem_portion = (mem_used/mem_total*mem_pi) + (swap_used/swap_total*swap_pi)
printf ("%5.1f%", mem_portion*100);
}'
}
get_cpu_load()
{
(cat /proc/stat | head -n1; usleep 500000; cat /proc/stat | head -n1) | awk '{
#cpu 309042 338 3383064 23545489
if (NR == 1)
{
user1 = $2;
nice1 = $3;
sys1 = $4;
idle1 = $5;
total1 = user1 + nice1 + sys1 + idle1;
}
else if (NR == 2)
{
user2 = $2;
nice2 = $3;
sys2 = $4;
idle2 = $5;
total2 = user2 + nice2 + sys2 + idle2;
}
}
END{
usage = ((user2 + sys2)-(user1 + sys1))/(total2 - total1)*100;
if (usage >= 100)
{
printf("100%");
}
else
{
printf("%3.1f%", usage);
}
}'
}
get_cpu_info()
{
model=`cat /proc/cpuinfo | grep 'model name' | cut -d: -f2`
model=${model# }
model=${model%CPU*}
hz=`cat /proc/cpuinfo | grep 'cpu MHz' | cut -d: -f2`
hz=${hz%.*}
rc="${model} ${hz}MHz"
echo -n "$rc"
}
format_uptime()
{
upsec=$1
up_str=""
day=$(( upsec / (3600*24) ))
if [ $day -gt 0 ]
then
upsec=$(( upsec % (3600*24) ))
if [ $day -eq 1 ]
then
up_str="$day day"
else
up_str="$day days"
fi
fi
hour=$(( upsec / 3600 ))
if [ $hour -gt 0 ]
then
upsec=$(( upsec % 3600 ))
if [ $hour -eq 1 ]
then
up_str="$up_str $hour hour"
else
up_str="$up_str $hour hours"
fi
fi
min=$(( upsec / 60 ))
if [ $min -gt 0 ]
then
upsec=$(( upsec % 60 ))
if [ $min -eq 1 ]
then
up_str="$up_str $min min"
else
up_str="$up_str $min mins"
fi
else
up_str="$up_str $min min"
fi
echo -n "$up_str"
}
get_sys_uptime()
{
rc=`cat /proc/uptime | awk '{ print $1 }'`
upsec=${rc%%.*}
up_str=`format_uptime $upsec`
echo -n "$up_str"
}
########################################
process monitor
最新推荐文章于 2025-01-18 13:34:10 发布