#!/bin/bash
printf "%10s\n" "##主机名##"
printf "%-10s\n" "$(hostname)"
echo "############CPU状态#####################################################################"
/usr/bin/top -b |head -5
echo "------------------------------------------"
echo "占用CPU时间前10"
ps aux|head -1|awk ‘{printf "%-8s %5s %4s %4s %-8s %-8s %-10s \n", $1,$2,$3,$4,$5,$6,$11}‘
ps aux|grep -v PID|sort -rn -k +3|head|awk ‘{printf "%-8s %5s %4s %4s %-8s %-8s %-10s \n", $1,$2,$3,$4,$5,$6,$11}‘
echo "############内存状态:###################################################################"
free -m
echo "------------------------------------------"
echo "占用内存前10"
ps aux|head -1|awk ‘{printf "%-8s %5s %4s %4s %-8s %-8s %-10s \n", $1,$2,$3,$4,$5,$6,$11}‘
ps aux|grep -v PID|sort -rn -k +4|head|awk ‘{printf "%-8s %5s %4s %4s %-8s %-8s %-10s \n", $1,$2,$3,$4,$5,$6,$11}‘
echo "############硬盘状态:#####################################################################"
use_disk=$(df|grep "^/dev/vd"| grep -Eo "\<[0-9]+\>%"|tr -d %|sort -nr|head -1)
echo "硬盘容量使用率:$use_disk"
disk_inode=$(df -i|grep "^/dev/vd"| grep -Eo "\<[0-9]+\>%"|tr -d %|sort -nr|head -1)
echo "硬盘inode使用率:$disk_inode"
echo "############TCP状态:#######################################################################"
echo "当前TCP连接数:"`netstat -nat | grep ESTABLISHED | wc -l`
echo "查看TCP连接状态:"
ss -tan|awk ‘NR>1{++S[$1]}END{for (a in S) print a,S[a]}‘
echo "#############网卡状态:#####################################################################"
eth0=$1
RXpre=$(cat /proc/net/dev |grep eth0|awk ‘{print $2}‘)
TXpre=$(cat /proc/net/dev |grep eth0|awk ‘{print $10}‘)
RXpack=$(cat /proc/net/dev |grep eth0|awk ‘{print $3}‘)
TXpack=$(cat /proc/net/dev |grep eth0|awk ‘{print $11}‘)
RXerr=$(cat /proc/net/dev |grep eth0|awk ‘{print $4}‘)
TXerr=$(cat /proc/net/dev |grep eth0|awk ‘{print $12}‘)
RXdrop=$(cat /proc/net/dev |grep eth0|awk ‘{print $5}‘)
TXdrop=$(cat /proc/net/dev |grep eth0|awk ‘{print $13}‘)
sleep 1
RXnext=$(cat /proc/net/dev |grep eth0|awk ‘{print $2}‘)
TXnext=$(cat /proc/net/dev |grep eth0|awk ‘{print $10}‘)
RXnextpack=$(cat /proc/net/dev |grep eth0|awk ‘{print $3}‘)
TXnextpack=$(cat /proc/net/dev |grep eth0|awk ‘{print $11}‘)
RXnexterr=$(cat /proc/net/dev |grep eth0|awk ‘{print $4}‘)
TXnexterr=$(cat /proc/net/dev |grep eth0|awk ‘{print $12}‘)
RXnextdrop=$(cat /proc/net/dev |grep eth0|awk ‘{print $5}‘)
TXnextdrop=$(cat /proc/net/dev |grep eth0|awk ‘{print $13}‘)
RX=$(( ${RXnext} - ${RXpre} ))
TX=$(( ${TXnext} - ${TXpre} ))
RXpack=$((${RXnextpack} - ${RXpack}))
TXpack=$((${TXnextpack} - ${TXpack}))
RXerr=$((${RXnexterr} - ${RXerr}))
TXerr=$((${TXnexterr} - ${TXerr}))
RXdrop=$((${RXnextdrop} - ${RXdrop}))
TXdrop=$((${TXnextdrop} - ${TXdrop}))
printf "%s" "接收字节 发送字节 接收包数 发送包数 接收错误 发送错误 接收丢弃 发送丢弃"
echo -e "\n"
printf "%-9s" ${RX} ${TX} ${RXpack} ${TXpack} ${RXerr} ${TXerr} ${RXdrop} ${TXdrop}
echo -e "\n"
原文地址:https://www.cnblogs.com/kenny88/p/11904437.html