一个监控系统性能的脚本

简介:

[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 {

           clear

           top

}

function process {

          clear

          process_nu=`lsof|wc -l`

          echo "The current process numbers is $process_nu" !

}

function ipaddress {

          clear

          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 {

         clear

         current_time=`date|awk '{print $5}'`

         echo "The current time is $current_time o clock !"

}

function users {

          clear

          current_user=`who|wc -l`

          echo "There are $current_user users login in the system !"

}

function networkcardflow  {

         clear
           
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 {


         clear

         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 ;;

       *)

         clear
        
         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


执行显示效果如下:


wKiom1jbAc3DSTYzAAAwKQji9XE746.png-wh_50


可以输入自己的选项,显示相应的结果:


比如输入 1


显示如下:


wKioL1jbAkvyiKWwAAAi8YdxeFo781.png-wh_50

本文转自服务器运维博客51CTO博客,原文链接http://blog.51cto.com/shamereedwine/1911284如需转载请自行联系原作者


neijiade10000

相关文章
|
4月前
|
Shell 开发工具
【优化篇】telegraf+shell脚本实现秒级的服务状态异常监测与告警
【优化篇】telegraf+shell脚本实现秒级的服务状态异常监测与告警
42 0
|
5月前
|
存储 设计模式 监控
如何诊断处理生产环境服务器变慢
在当今的高科技环境下,生产环境服务器的性能问题可能是一个复杂且棘手的问题。当服务器变慢时,可能会对企业的运营产生重大影响,包括客户满意度下降,工作效率降低,甚至可能导致整个系统崩溃。为了解决这些问题,我们需要深入了解生产环境服务器变慢的原因,并掌握有效的诊断和处理方法。本文将详细介绍如何诊断和处理生产环境服务器变慢的问题。通过深入探讨服务器的硬件和软件配置,网络环境,以及可能影响服务器性能的各种因素,我们将提供一系列实用的诊断和解决方案。
52 1
|
监控 Shell
|
运维 监控 数据可视化
JVM性能监控与故障处理工具
JVM性能监控与故障处理工具
141 0
JVM性能监控与故障处理工具
|
缓存 监控 数据安全/隐私保护