Linux下脚本实战之系统监控
生活随笔
收集整理的這篇文章主要介紹了
Linux下脚本实战之系统监控
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Linux下腳本實(shí)戰(zhàn)之系統(tǒng)監(jiān)控
- 一、腳本要求
- 二、腳本內(nèi)容
- 三、運(yùn)行腳本
一、腳本要求
1.監(jiān)控系統(tǒng)的CPU、內(nèi)存、硬盤使用率
二、腳本內(nèi)容
#!/bin/bash ########################################################## #File Name:monitor.sh #Version:V1.0 #Aurhor: #Emali: #Created Time:2021-05-03 12:45:32 #Description: ###########################################################! /bin/bash DATETIME=$(date +%F" "%H%M) IP=$(ifconfig bond0 |awk '/netmask/ {print $2}') which vmstat &> /dev/null if [ ! $? = 0 ];then echo "vmstat command no found,please install the package!" exit 10 elif [ $? = 0 ] ; then## mem the state TOTAL=$(free -m |awk '/Mem/ {print $2}') USED=$(free -m |awk '/Mem/ {print $3}') FREE=$(free -m |awk '/Mem/ {print $4+$6}') if [ $FREE -lt 1024 ];then echo "Date: $DATETIMEHosts: $IPProblem: Total=$TOTAL,USE=$USED,Free=$FREE"fi## the cpu state US=$(vmstat |awk 'NR==3 {print $13}') SY=$(vmstat |awk 'NR==3 {print $14}') IDLE=$(vmstat |awk 'NR==3 {print $15}') WAIT=$(vmstat |awk 'NR==3 {print $15}') USE=$(($US+$SY)) if [ $USE -ge 50 ];thenecho "Date: $DATETIMEHost: $IPProblem: CPU utilization $USE" fi#disk the state PART_USE=$(df -h |awk -F'[% ]+' 'BEGIN{OFS="="} /^\/dev/ {print $1,$2,$5,$6}') for i in $PART_USE; doPART=$(echo $i |cut -d"=" -f1)TOTAL=$(echo $i |cut -d "=" -f2)USE=$(echo $i |cut -d"=" -f3)MOUNT=$(echo $i |cut -d"=" -f4)if [ $USE -gt 80 ]; thenecho "Date: $DATETIMEHost: $IPTotal: $TOTALProblem: $PART=$USE($MOUNT)"fi done elseecho " the system is OK! "fi三、運(yùn)行腳本
[root@control scripts]# ./monitor.sh the system is OK!總結(jié)
以上是生活随笔為你收集整理的Linux下脚本实战之系统监控的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下的samba服务配置详解
- 下一篇: Linux脚本之定时清空文件内容