使用Bash脚本进行进程性能监控
2014-11-18 17:11
330 查看
对一个Linux进程进行监控,使用Bash脚本实现。
使用ps命令对进程进行监控,使用循环加睡眠时间实现连续监控。
用法:
psmonitor.sh -p [pid] -d [interval] -n [statistics count]
参数:
-p 监控的进程ID
-d 读性能数据间隔
-n 统计次数,达到该次数,自动退出
监控效果:
使用ps命令对进程进行监控,使用循环加睡眠时间实现连续监控。
用法:
psmonitor.sh -p [pid] -d [interval] -n [statistics count]
参数:
-p 监控的进程ID
-d 读性能数据间隔
-n 统计次数,达到该次数,自动退出
#!/bin/bash interval=0 count=0 pid="" while getopts "p:d:n:" arg do case $arg in p) pid=$OPTARG echo "pid: $pid" ;; d) interval=$OPTARG echo "interval:$interval" ;; n) count=$OPTARG echo "count:$count" ;; \?) echo "unkonw argument" exit 1 ;; esac done i=0; while [ true ]; do if [ $i -gt $count ] then exit 0; else let "i+=1" fi ps h -p $pid -o rss,vsz,%mem,%cpu sleep $interval done
监控效果:
-bash-3.2$ ./psmonitor.sh -p 4181 -d 1 -n 10 pid: 4181 interval:1 count:10 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4 1511232 2537664 37.3 2.4
相关文章推荐
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 转:使用Shell脚本对Linux系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控(转)
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控