cat cpuinfo.sh
#!/bin/bash
cpu() {
local user system idle cwait
user=$(vmstat |awk 'NR==3{print $13}')
system=$(vmstat |awk 'NR==3{print $14}')
idle=$(vmstat |awk 'NR==3{print $15}')
cwait=$(vmstat |awk 'NR==3{print $16}')
echo "CPU用户占用: $user%"
echo "CPU系统占用: $system%"
echo "CPU空闲: $idle%"
echo "CPU等待磁盘I/O响应占用: $cwait%"
}
cpu
while true;do bash cpuinfo.sh; sleep 1;done
#!/bin/bash
memory() {
local total used free
used=$(free -m |awk 'NR==3{print $3}')
free=$(free -m |awk 'NR==3{print $4}')
total=$(($used+$free))
echo "内存总共: ${total}M"
echo "内存使用: ${used}M"
echo "内存剩余: ${free}M"
}
Memory
disk() {
local mount total used_parent free
part=$(df -h |awk 'BEGIN{OFS="="}/^/dev/{print $6,$2,$3,$4,int($5)}')
for p in $part;do
mount=$(echo $p |cut -d"=" -f1)
total=$(echo $p |cut -d"=" -f2)
used=$(echo $p |cut -d"=" -f3)
free=$(echo $p |cut -d"=" -f4)
used_parent=$(echo $p |cut -d"=" -f5)
if [ $used_parent -ge 13 ];then
echo "挂载点: $mount"
echo "总大小: $total"
echo "使用: $used"
echo "剩余:$free"
fi
done
}
Disk
traffic() {
echo -e " In ------Out"
local old_in old_out new_in new_out
old_in=$(ifconfig eth0 |awk '/RX/&&/dropped/{print $2}' |awk -F: '{print $2}')
old_out=$(ifconfig eth0 |awk '/TX/&&/dropped/{print $2}' |awk -F: '{print $2}')
sleep 1
new_in=$(ifconfig eth0 |awk '/RX/&&/dropped/{print $2}' |awk -F: '{print $2}')
new_out=$(ifconfig eth0 |awk '/TX/&&/dropped/{print $2}' |awk -F: '{print $2}')
in=$(($new_in-$old_in))
out=$(($new_out-$old_out))
echo "$in kB/s,$out kB/s"
}
traffic
cat sys_all.sh
#!/bin/bash
cpu() {
local user system idle cwait
user=$(vmstat |awk 'NR==3{print $13}')
system=$(vmstat |awk 'NR==3{print $14}')
idle=$(vmstat |awk 'NR==3{print $15}')
cwait=$(vmstat |awk 'NR==3{print $16}')
echo "CPU用户占用: $user%"
echo "CPU系统占用: $system%"
echo "CPU空闲: $idle%"
echo "CPU等待磁盘I/O响应占用: $cwait%"
}
memory() {
local total used free
used=$(free -m |awk 'NR==3{print $3}')
free=$(free -m |awk 'NR==3{print $4}')
total=$(($used+$free))
echo "内存总共: ${total}M"
echo "内存使用: ${used}M"
echo "内存剩余: ${free}M"
}
disk() {
local mount total used_parent free
part=$(df -h |awk 'BEGIN{OFS="="}/^/dev/{print $6,$2,$3,$4,int($5)}')
for p in $part;do
mount=$(echo $p |cut -d"=" -f1)
total=$(echo $p |cut -d"=" -f2)
used=$(echo $p |cut -d"=" -f3)
free=$(echo $p |cut -d"=" -f4)
used_parent=$(echo $p |cut -d"=" -f5)
if [ $used_parent -ge 13 ];then
echo "挂载点: $mount"
echo "总大小: $total"
echo "使用: $used"
echo "剩余:$free"
fi
done
}
traffic() {
echo -e " In ------Out"
local old_in old_out new_in new_out
old_in=$(ifconfig eth0 |awk '/RX/&&/dropped/{print $2}' |awk -F: '{print $2}')
old_out=$(ifconfig eth0 |awk '/TX/&&/dropped/{print $2}' |awk -F: '{print $2}')
sleep 1
new_in=$(ifconfig eth0 |awk '/RX/&&/dropped/{print $2}' |awk -F: '{print $2}')
new_out=$(ifconfig eth0 |awk '/TX/&&/dropped/{print $2}' |awk -F: '{print $2}')
in=$(($new_in-$old_in))
out=$(($new_out-$old_out))
echo "$in kB/s,$out kB/s"
}
cpu
memory
disk
traffic
Copyright 2020-2026 同袍存储 粤ICP备2021121885号网站地图