码迷,mamicode.com
首页 > 其他好文 > 详细

监控生产服务器内存使用前十

时间:2017-07-26 21:48:42      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:保存   array   top   blog   awk   date   选项   log   pre   

#!/usr/bin/env bash 
#date 20170726 
#destination: 
st_file="/root/list.txt"
log_file="/root/mem_monitor.txt"
log_report="/root/java_mem_use.txt"
###########################top 在centos7.2 中,不能使用-a 选项,则先更改top的配置,再保存,则能很好处理脚本问题;
top -a -b -n 1 > ${st_file}
#sleep 1 
pid_10=$(head -n 17 ${st_file} | tail -n 10 | awk {print $1})
mem_10=$(head -n 17 ${st_file} | tail -n 10 | awk {print $10})
pid_array=(${pid_10})
mem_array=(${mem_10})
echo "$(date +%F-%H:%m:%S)>>>>>>>>>>>>>>>>>>>>>>>>>>>" >>${log_report}
for index in $(seq 10)
do
    program=$(ps -elf | grep ${pid_array[(($index-1))]} | grep -v grep | awk {print $15,$16,$17})
    #echo "-------------PID-----------------------"
    echo "占用内存第${index}的PID:   ${pid_array[(($index-1))]} " >> ${log_report}
    echo "此PID的程序为:  ${program} " >> ${log_report}
    echo "此进程占用的内存为:   ${mem_array[(($index-1))]} " >>${log_report}
    echo "=======================================" >>${log_report}
done

 

监控生产服务器内存使用前十

标签:保存   array   top   blog   awk   date   选项   log   pre   

原文地址:http://www.cnblogs.com/Mail-maomao/p/7241634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!