2018-06-04 Linux Learning

Source: Internet
Author: User

20.20 Alarm System Main script

main.sh Content

#!/bin/bash
#Written by Aming.

Whether to send mail switch

Export send=1

Filter IP Address

Export addr=/sbin/ifconfig |grep -A1 "ens33: "|awk ‘/inet/ {print $2}‘
Dir=pwd

Only the last level directory name is required

Last_dir=echo $dir|awk -F‘/‘ ‘{print $NF}‘

The purpose of the following is to ensure that the script is executed when we are in the bin directory, otherwise the monitoring scripts, messages and logs may not be found

if [$last _dir = = "Bin"] | | [$last _dir = = "bin/"]; Then
Conf_file= ". /conf/mon.conf "
Else
echo "You shoud cd bin dir"
Exit
Fi
exec 1>>. /log/mon.log 2>> /log/err.log
echo " date +"%F %T" load Average"
/bin/bash. /shares/load.sh
#先检查配置文件中是否需要监控502
If Grep-q ' to_mon_502=1 ' $conf _file; Then
Export log=grep ‘logfile=‘ $conf_file |awk -F ‘=‘ ‘{print $2}‘ |sed ‘s/ //g‘
/bin/bash??.. /shares/502.sh
Fi

Operation Process

[Email protected] shell]# cd/usr/local/sbin/
[Email protected] sbin]# mkdir Mon
[Email protected] sbin]# CD Mon
[[email protected] mon]# mkdir bin conf shares log mail
[[email protected] mon]# ls
Bin conf Log Mail shares

[Email protected] bin]# vim main.sh
Write the above main.sh content

20.21 Alarm System Configuration file

mon.conf Content

The options if to monitor defines MySQL's server address, port, and user, password

To_mon_cdb=0? # #0 or 1, default 0,0 not monitor, 1 monitor
db_ip=10.20.3.13
db_port=3315
Db_user=username
db_pass=passwd

HTTPd? If 1 is monitored, 0 is not monitored

To_mon_httpd=0

PHP if 1 is monitored, 0 is not monitored

To_mon_php_socket=0

http_code_502?? You need to define the path to the access log

To_mon_502=1
Logfile=/data/log/xxx.xxx.com/access.log

Request_count? Define log paths and domain names

To_mon_request_count=0
Req_log=/data/log/www.discuz.net/access.log
Domainname=www.discuz.net

Operation Process

[Email protected] mon]# vim conf/mon.conf
Write the above mon.conf content

20.22 Alarm System Monitoring Project

Shell Project-Alarm system load.sh

load.sh Content

#! /bin/bash
# #Writen by aming##
Load=uptime |awk -F ‘average:‘ ‘{print $2}‘|cut -d‘,‘ -f1|sed ‘s/ //g‘ |cut -d. -f1
If [$load-gt] && [$send-eq "1"]
Then
echo "$addr date +%T load is $load" ... /log/load.tmp
/bin/bash. /mail/mail.sh [email protected] "$addr _load: $load"cat ../log/load.tmp
Fi
echo " date +%T load is $load"

Shell Project-Alarm system 502.sh

502.sh Content

#! /bin/bash
D=date -d "-1 min" +%H:%M
C_502=grep :$d:??$log??|grep ‘ 502 ‘|wc -l
If [$c _502-gt] && [$send = = 1]; Then
? ??? echo "$addr $d 502 count is $c _502" ... /log/502.tmp
? ??? /bin/bash. /mail/mail.sh $addr _502 $c _502??.. /log/502.tmp
Fi
echo " date +%T 502 $c _502"

Shell Project-Alarm system disk.sh

disk.sh Content

#! /bin/bash
# #Writen by aming##
Rm-f. /log/disk.tmp
for R indf -h |awk -F ‘[ %]+‘ ‘{print $5}‘|grep -v Use
Do
? ? If [$r-gt] && [$send-eq "1"]
Then
? ? echo "$addr date +%T disk useage is $r" >> /log/disk.tmp
Fi
If [-F. /LOG/DISK.TMP]
Then
? ? Df-h >>. /log/disk.tmp
? ? /bin/bash. /mail/mail.sh $addr _disk $r. /log/disk.tmp
? ? echo " date +%T disk useage is Nook"
Else
? ? echo " date +%T disk useage is OK"
Fi

[Email protected] mon]# vim shares/load.sh
Write the above load.sh content

[Email protected] mon]# vim shares/502.sh
Write the above 502.sh content

[Email protected] mon]# vim shares/disk.sh
Write the above disk.sh content

2018-06-04 Linux Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.