1. Determine the disk space used
Df-h | grep-v File | sed's/% // G' | awk '{if ($5> 80) print "The used space exceeds 80% :", $6} 'or #! /Bin/bash # Filename: disk. sh # Date: 20110322 DISK_warn = 80 DISK_per = 'df-h | grep-v Filesystem | awk '{print int ($5 )} ''for I in $ DISK_per do if ["$ I"-gt "$ DISK_warn"]; then partion = 'df-h | grep "$ I %" | awk '{print $6} ''echo "used space exceeds 80%: $ partion" fi done
Determine whether the disk usage percentage has exceeded the set value. Here, you can change it to mail alarm.
2. Monitor CPU load
#! /Bin/bash # Filename: cpu_load.sh # Date: 20120322 LOAD_15 = $ (uptime | awk '{print $ NF }') CPU_num = $ (grep-c 'model name'/proc/cpuinfo) LOAD_avg = 'echo "scale = 2; a = $ LOAD_15/$ CPU_num; if (length () = scale (a) print 0; print a "| bc 'int_avg = 'echo $ LOAD_avg | cut-f 1-d ". "'load_warn = 0.70 if ($ INT_avg> 0); then echo" The average load of the current server for 15 minutes is $ LOAD_avg, exceeding the warning value of 1.0, please process "else LOAD_now = 'expr $ LOAD_avg \> $ load_warn' if (( $ LOAD_now = 1); then echo "The average load of the current server for 15 minutes is $ LOAD_avg, exceeding the warning value of 0.70. Please handle it in time. "Fi
Determine whether the cpu load exceeds the set value.
3. Monitor SWAP usage
#! /Bin/bash # Filename: swap. sh # Date: 20120322 TOTAL = $ (free-m | grep "Swap:" | awk '{print $2 }') USED = $ (FREE = $ (free-m | grep "Swap:" | awk '{print $3}') FREE = $ (free-m | grep "Swap: "| awk '{print $4}') SWAP_per =$ (expr $ FREE \ * 100/$ TOTAL) SWAP_warn = 50 if [$ SWAP_per-lt $ SWAP_warn]; then echo "the current server's SWAP space is available: $ free m, with less than 50% remaining. "fi
Determine whether the percentage used by swap exceeds the set value. Here, you can change it to mail alarm.
4. Use curl to determine whether the website can be accessed normally
#! /Bin/bash # Filename: web. sh # Date: 20110322 url =$ {1? "Enter the detected url address"} Status = $ (curl-s -- head $ url | awk '/HTTP/{print $2 }') [-z $ Status] & Status = 400 if ["$ Status"-eq 200]; then echo "$ the url can be accessed normally" else echo "$ the url cannot be accessed, please check! "Fi
|