#! /bin/bash read -p "please input the thread name you want to monitor: " threadname echo "name is $threadname" read -p "please input the second you monitor: " second filename=`date +%F`"log.txt"; echo "filename $filename" #死循环 while true do #获得时间 MyTime=`date +%F%r` #获得内存 MemInfo=`free -m|grep Mem|awk '{print " total: " $2,"use: " $3,"free: " $4}'` MemInfo=${MyTime}${MemInfo} echo $MemInfo >> $filename #获得top命令监控信息 TopInfo=`top -b -n 1 |grep -w $threadname|awk '{print "\n"," cpu :",$9," mem: ",$10,$11,$12,"\n"}'` echo $TopInfo >> $filename #睡眠时间 sleep $second done
shell 监控指定程序占用系统内存和CPU情况
原创文章标签 shell 系统监控 文章分类 后端开发
©著作权归作者所有:来自51CTO博客作者584851044的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:大数相乘
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
centos7通过shell脚本监控服务器cpu、内存和磁盘
本文简单介绍了在没有监控服务器之前通过脚本来监控服务器。
centos7监控脚本 shell脚本监控linux 监控脚本 cpu 内存 -
python查看程序的cpu和内存资源占用情况
python查看线程的cpu和内存资源占用情况
python 递归 内存分析 堆栈 -
linux 监控CPU 内存情况
htop
Linux