Linux监控系统CPU、内存、磁盘空间和网口收发脚本
来源:互联网 发布:淘宝上好看的包包店铺 编辑:程序博客网 时间:2024/06/09 19:14
#!/bin/bash
get_cpu_info()
{
cat /proc/stat |grep "^cpu" |head -n1 |awk '{used=$2+$3+$4+$6+$7+$8;unused=$2+$3+$4+$5+$6+$7+$8} END{print used, unused}'
}
while true
do
time_point_1=`get_cpu_info`
tx_pre=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $10}')
rx_pre=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $2}')
sleep 60
time_point_2=`get_cpu_info`
tx_next=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $10}')
rx_next=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $2}')
mem_used=$(free -m |grep "Mem:" |awk '{print $3}')
mem_free=$(free -m |grep "Mem:" |awk '{print $4}')
disk_used=$(df -h |grep "rootfs" |awk '{print $3}')
disk_free=$(df -h |grep "rootfs" |awk '{print $4}')
cpu_rate=`echo $time_point_1 $time_point_2 |awk '{used=$3-$1;total=$4-$2; if(total>0) {print used*100/total}}'`
tx=$((${tx_next}-${tx_pre}))
rx=$((${rx_next}-${rx_pre}))
echo "cpu share: $cpu_rate"%" "
echo "net dev tx: $tx rx: $rx"
echo "memory used: $mem_used free: $mem_free "
echo "rootfs used: $disk_used available: $disk_free "
done
get_cpu_info()
{
cat /proc/stat |grep "^cpu" |head -n1 |awk '{used=$2+$3+$4+$6+$7+$8;unused=$2+$3+$4+$5+$6+$7+$8} END{print used, unused}'
}
while true
do
time_point_1=`get_cpu_info`
tx_pre=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $10}')
rx_pre=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $2}')
sleep 60
time_point_2=`get_cpu_info`
tx_next=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $10}')
rx_next=$(cat /proc/net/dev |grep eth0 |tr : " " |awk '{print $2}')
mem_used=$(free -m |grep "Mem:" |awk '{print $3}')
mem_free=$(free -m |grep "Mem:" |awk '{print $4}')
disk_used=$(df -h |grep "rootfs" |awk '{print $3}')
disk_free=$(df -h |grep "rootfs" |awk '{print $4}')
cpu_rate=`echo $time_point_1 $time_point_2 |awk '{used=$3-$1;total=$4-$2; if(total>0) {print used*100/total}}'`
tx=$((${tx_next}-${tx_pre}))
rx=$((${rx_next}-${rx_pre}))
echo "cpu share: $cpu_rate"%" "
echo "net dev tx: $tx rx: $rx"
echo "memory used: $mem_used free: $mem_free "
echo "rootfs used: $disk_used available: $disk_free "
done
0 0
- Linux监控系统CPU、内存、磁盘空间和网口收发脚本
- Linux 系统CPU,内存,负载,IO监控脚本
- shell脚本监控系统负载、CPU和内存使用情况
- shell脚本监控系统负载、CPU和内存使用情况
- linux服务器系统cpu监控-shell脚本
- Shell脚本监控Linux系统CPU使用率
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 【转载】linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- shell脚本: linux系统的负载与CPU、内存、硬盘、用户数监控
- 利用Shell脚本来监控Linux系统的负载、CPU、内存、硬盘、用户登录数
- Linux CPU 监控脚本
- centos 6.4 系统CPU,内存,负载,IO监控脚本
- Linux--shell监控CPU和内存
- Shell脚本监控Linux系统内存使用率
- Linux 系统CPU及系统负载监控脚本
- const 指针与指向const的指针
- jquery easyui dialog问题
- Linux套接字编程
- Matlab做PCA分析
- 《LoadRunner 没有告诉你的》和《JMeter从入门到精通》
- Linux监控系统CPU、内存、磁盘空间和网口收发脚本
- First Missing Positive
- unity3d优化总结
- SSH之hibernate——get和load方法的区别
- DB2:有关"ERRORCODE=-4499, SQLSTATE=08001"详解
- C++Builder中使用MSCOMM进行串口编程
- Linux常用命令和VI命令
- Node.js实现的BigPipe
- 关于面向对象的理解