better meet the needs of more refined | instancecsのブログ

instancecsのブログ

ブログの説明を入力します。

Recently a friend asked me from time to time there Nike Air Max are questions about aspects of server monitoring, server monitoring in addition to frequently used open source software, such as: cacti, nagios external monitor if you can write your own shell script it? According to their own needs to write shell scripts to better meet the needs of more refined host monitoring comprehensiveness. Here is my favorite script several hosts monitor, we can according to their own circumstances making changes, we hope to give you a little help. 1. Check the host LAN traffic # / bin / bash # / bin / bash # network # Mike.Xuwhile:; do time = 'date +% m '-'% d ''% k ':'% M'!! Day = 'date +% m '-'% d' rx_before = 'ifconfig eth0 | sed -n '8' p | awk' {print $ 2} '| cut -c7-' tx_before = 'ifconfig eth0 | sed -n '8 'p | awk '{print $ 6}' | cut -c7- 'sleep 2 rx_after =' ifconfig eth0 | sed -n' 8 'p | awk '{print $ 2}' | cut -c7- 'tx_after =' ifconfig eth0 | sed -n '8' p | awk '{print $ 6}' | cut -c7- 'rx_result = $ [(rx_after-rx_before) / 256] Air Max 2012 Womens Navy Blue White tx_result = $ [(tx_after-tx_before) / 256] echo '$ time Now_In_Speed: '$ rx_result' kbps Now_OUt_Speed: '$ tx_result' kbps 'sleep 2donedone2, system health monitoring # / bin / sh # systemstat.sh # Mike.XuIP = 192.168.1.227top -n 2 | grep!' Cpu '\u0026 gt; \u0026 gt; ./ temp / cpu.txtfree -m | grep 'Mem' \u0026 gt; \u0026 gt; ./temp/mem.txtdf -k | grep 'sda1' \u0026 gt; \u0026 gt; ./temp/drive_sda1.txt#df -k | grep sda2 \u0026 gt; \u0026 gt; ./temp/drive_sda2.txtdf -k | grep '/ mnt / storage_0' \u0026 gt; \u0026 gt; ./temp/mnt_storage_0.txtdf -k | grep '/ mnt / storage_pic' \u0026 gt; \u0026 gt; ./ '.' temp / mnt_storage_pic.txttime = `date +% m% d' '% k': '% M`connect =` netstat -na | grep '219.238.148.30:80' | wc -l`echo '$ time $ connect '\u0026 gt; \u0026 gt; ./temp/connect_count.txt3, monitoring host disk space, when the use of space more than 90% can be made by sending a mail warning # / bin / bash # monitor available disk spaceSPACE = 'df | sed! Kyrie Irving -n '/ \\ / $ / p' | gawk '{print $ 5}' | sed 's /% //' if [$ SPACE -ge 90] thenfty89@163.comfi4, monitor CPU and memory usage #! / bin / bash # script to capture Black Grey Blue Nike Air LeBron E.E. 2013 Online system statisticsOUTFILE = / home / xu / capstats.csvDATE = 'date +% m /% d /% Y'TIME =' date +% k:% m:% s'TIMEOUT = 'uptime 'VMOUT =' vmstat 1 2 'USERS =' echo $ Air Jordan Outlet TIMEOUT | gawk '{print $ 4}' 'LOAD =' echo $ TIMEOUT | gawk '{print $ 9}' | sed 's /, // '' FREE = ' echo $ VMOUT | sed -n '/ Black Grey Pink Nike Hyperdunk 2013 Outlet [0-9] / p' | sed -n '2p' | gawk '{print $ 4}' 'IDLE =' echo $ VMOUT | sed -n '/ [0-9] Nike 6.0 Mavrk Mid 2 Skate Shoes Red Black / p '| sed -n' 2p '| gawk' {print $ 15} '' echo '$ DATE, $ TIME, $ USERS, $ LOAD, $ FREE, $ IDLE' \u0026 gt; \u0026 gt; $ OUTFILE5, comprehensive monitoring host #! / bin / bash # check_xu.sh # 0 Nike 6.0 Mavrk Mid 2 Skate Shoes White Blue * * * * /home/check_xu.shDAT='`date +% Y% m% d` 'HOUR =' `date +% H`' DIR = '/ home / oslog / host _ $ {DAT} / $ {HOUR} 'DELAY = 60COUNT = 60 # whether the responsible directory existif! test -d $ {DIR} Nike Air Max 2012 Womens Navy Blue White Heels Boots then / bin / mkdir -p $ {DIR} fi # general checkexport TERM = linux / usr / bin / top -b -d $ {DELAY} -n $ {COUNT} \u0026 gt; $ {DIR} / top _ $ {DAT} .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; # cpu check / usr / bin / sar -u $ Black White Yellow Nike Zoom Lebron 10.8 Outlet {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / cpu _ $ {DAT} .log 2 \u0026 2015 Nike Free 5.0 gt; \u0026 amp; 1 \u0026 amp; # / usr / bin / mpstat -P 0 $ {DELAY} $ Black Grey Blue Nike Air LeBron E.E. 2013 Online {COUNT} \u0026 gt; $ {DIR} / cpu_0 _ $ {DAT} .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; # / usr / bin / mpstat -P 1 $ {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / cpu_1 _ $ {DAT } .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; # memory check / usr / bin / vmstat $ {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / vmstat _ $ {DAT} .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; # I / O check / usr / bin / iostat Nike Dunk Heels $ {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / iostat _ $ {DAT} .log 2 \u0026 gt; Air Max 2012 Purple Black \u0026 amp; 1 \u0026 amp; # network check / usr / bin / sar -n DEV $ {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / net _ $ {DAT} .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; # / usr / bin / sar -n EDEV $ {DELAY} $ {COUNT} \u0026 gt; $ {DIR} / net_edev _ $ {DAT} .log 2 \u0026 gt; \u0026 amp; 1 \u0026 amp; put crontab Lane executed automatically every hour: 0 * * * * /home/check_xu.sh This will in / home / oslog / host_yyyymmdd / hh directory Under generate statistics for each hour cpu, memory, network, IO's. If a period of time to produce a problem, you can see the corresponding log information, then see how the host performance.I used Shell Scripting Host Monitoring