[root@localhost ~]# cat monitor.sh
#!/bin/bash
# chkconfig: 2345 08 92
# description: The scripts is to monitor system health !
Today=`date +%Y%m%d`
function disk {
clear
df -h
}
function memory {
clear
free -m
function cpu {
top
function process {
clear
process_nu=`lsof|wc -l`
echo "The current process numbers is $process_nu" !
function ipaddress {
ipaddr=`ifconfig eth0|awk '/inet addr/ {print $2}'|awk -F':' '{print $2}'`
echo "This server ip address is $ipaddr" !
function disk_io {
clear
diskblockin=`vmstat |sed 1d|sed 1d|awk '{print $9}'`
diskblockout=`vmstat |sed 1d|sed 1d|awk '{print $10}'`
echo "The block equipment received $diskblockin blocks one second !"
echo "The block equipment send $diskblockout blocks one second !"
function current_time {
current_time=`date|awk '{print $5}'`
echo "The current time is $current_time o clock !"
function users {
current_user=`who|wc -l`
echo "There are $current_user users login in the system !"
function networkcardflow {
receive1=`cat /proc/net/dev|grep eth0|awk '{print $2}'`
send1=`cat /proc/net/dev|grep eth0|awk '{print $10}'`
sleep 5
receive2=`cat /proc/net/dev|grep eth0|awk '{print $2}'`
send2=`cat /proc/net/dev|grep eth0|awk '{print $10}'`
receive_cnt=`expr $receive2 - $receive1`
receive_cnt=`expr $receive_cnt / 40`
send_cnt=`expr $send2 - $send1`
send_cnt=`expr $send_cnt / 40`
echo "The networkcard flow Input is $receive_cnt bps per second !"
echo "The networkcard flow Ouput is $send_cnt bps per second |"
function menu {
echo
echo -e "\t\t\tSystem Admin Menu\n"
echo -e "\t1. Display disk space"
echo -e "\t2. Display memory usage"
echo -e "\t3. Display cpu usage"
echo -e "\t4. Display process statistics"
echo -e "\t5. Display ip address"
echo -e "\t6. Display disk io information"
echo -e "\t7. Display current time"
echo -e "\t8. Display current users"
echo -e "\t9. Display networkcard flow"
echo -e "\t0. Exit program\n\n"
echo -en "\t\tEnter option: "
read -n 1 option
while true
do
menu
case $option in
0)
break ;;
1)
disk ;;
2)
memory ;;
3)
cpu ;;
4)
process ;;
5)
ipaddress ;;
6)
disk_io ;;
7)
current_time ;;
8)
users ;;
9)
networkcardflow ;;
*)
echo "Sorry , wrong selection !"
esac
echo -en "\n\n\t\t\tHit any key to continue"
read -n 1 line
done
clear
chmod +x monitor.sh
執行顯示效果如下:
<a href="https://s5.51cto.com/wyfs02/M02/8F/51/wKiom1jbAc3DSTYzAAAwKQji9XE746.png-wh_500x0-wm_3-wmp_4-s_1417126213.png" target="_blank"></a>
可以輸入自己的選項,顯示相應的結果:
比如輸入 1
顯示如下:
<a href="https://s5.51cto.com/wyfs02/M02/8F/4F/wKioL1jbAkvyiKWwAAAi8YdxeFo781.png-wh_500x0-wm_3-wmp_4-s_2699119243.png" target="_blank"></a>
本文轉自伺服器運維部落格51CTO部落格,原文連結http://blog.51cto.com/shamereedwine/1911284如需轉載請自行聯系原作者
neijiade10000