Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor multiple hosts by shell

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how shell monitors multiple hosts, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

First of all, you need to establish a trust relationship between the monitored host and the monitored host. For those who do not know ssh certificate verification, please take a look at:

Http://dragon123.blog.51cto.com/9152073/1586795

Install mutt:

[root@centos-server ~] # yum install mutt

Monitoring list:

[root@centos-server] # cat > iplist.txt 22.22.22.129 > 22.22.22.130 > 22.22.22.134 > end

Monitoring script:

#! / bin/bashfor ip in `cat iplist.txt`; do ping $ip-C1 > / dev/null # first check whether the host is online, and if it is online, further monitor if [$?-eq 0]; then rootused= ``ssh $ip df-h | grep / $| awk'{print $4}'| cut-d%-f1` # take root directory usage for hardid in `ssh $ip df-h | grep "^\ / dev\ / s [aMuz] [AMAZ]" | awk'{print $1}'`| Dohardused= ``ssh $ip df-h | grep $hardid | awk'{print $5}'| cut-d%-f1` # take the usage of other local hard disks done memtotal= `ssh $ip free-m | grep Mem | awk'{print $2} '`memused= `ssh $ip free-m | grep Mem | awk' {print $3} '`mem= `expr $memused\ * 100 / $memtotal`idelcpu= `ssh $ip top-N1 | grep Cpu | awk' {print $5}'| cut-d "."-f1`cpuused= `expr 100-$idelcpu`if [$mem-gt 70] Then # notify echo "warm:$ip memory is $mem" if memory usage is higher than 70% | mutt-s "monitor report" 18507656225@163.comfiif [$hardused-le 80]; then # email notify echo "warm:$ip the Hard drive capacity is more 80%" if hard disk usage is higher than 80% | mutt-s "monitor report" 18507656225@163.comfiif [$rootused-le 80] Then # notify echo "warm:$ip the Hard drive capacity is more 80%" by email if the hard disk has been used by more than 80% | mutt-s "monitor report" 18507656225@163.com fifor hardid in `ssh $ip iostat | grep "^ s [amerz] [amerz]" | awk'{print $1}'` Do # prefetch character iostat= `ssh $ip iostat-x | grep $hardid | awk'{print $12}'| cut-d "."-f1` # get io busy echo $iostat if [$iostat-gt 80] Then # if the io is busy more than 80%, notify echo "ipaddress:$ip,hard:$hardid,iostat:$iostat" | mutt-s "warm" 18507656225@163.com fi doneelse echo "host:$ip is not alive" | mutt-s "monitor report" 18507656225@163.com # notify fidone by mail if the host is unable to ping

Monitor every 5 minutes (if there is a problem and this is not resolved, receive an email every 5 minutes, which is very troublesome):

[root@centos-server] # crontab-e

* / 5 * bash / root/monitor.sh

Check email:

The above is all the contents of the article "how shell monitors multiple hosts". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report