2018-4-22 17 weeks 4 Lessons Shell alarm System script Configuration

Source: Internet
Author: User
20.20 Alarm System Main Script


Put the shell script in the / usr / local / sbin directory for easy searching

[[email protected] ~] # cd / usr / local / sbin /
[[email protected] sbin] # mkdir mon /
[[email protected] sbin] # cd mon /
[[email protected] mon] # mkdir bin conf shares mail log
[[email protected] mon] # ls
bin conf log mail shares
[[email protected] mon] # cd bin /
[[email protected] bin] # vim main.sh
Main script main.sh parameter address: http://note.youdao.com/noteshare?id=ef94586704b208ee6d7c7d1e5f04f644&sub=08E66A3760DF4961B29C74DED78E09F1

export send Whether to send mail. 1 is for sending. If it is under maintenance, the alarm should be closed.

addr local IP (change ens33 or other name according to the actual network card name)

last_dir / bin / directory

conf_file ../conf/mon.conf relative to / bin /

grep -q returns as long as it matches, for if logic







20.21 Alarm System Configuration File



mon.conf

## to config the options if to monitor

## Define mysql server address, port, 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 Need to define the path of the access log

to_mon_502 = 1

logfile = / data / log / xxx.xxx.com / access.log

## request_count Define the log path and domain name

to_mon_request_count = 0

req_log = / data / log / www.discuz.net / access.log

domainname = www.discuz.net







20.22 Alarm System Monitoring Project


Load.sh content

#! / bin / bash

## Writen by alex ##

load = `uptime | awk -F 'average:' '{print $ 2}' | cut -d ',' -f1 | sed 's / // g' | cut -d. -f1`

if [$ load -gt 10] && [$ 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 "



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 10] && [$ send == 1]; then

     echo "$ addr $ d 502 count is $ c_502"> ../ log / 502.tmp ## 502 count into the log

     / bin / bash ../mail/mail.sh $ addr \ _502 $ c_502 ../log/502.tmp ## Send mail

fi

echo "` date +% T` 502 $ c_502 "



disk.sh content

#! / bin / bash

## Writen by alex ##

rm -f ../log/disk.tmp

LANG = en

for r in `df -h | awk -F '[%] +' '{print $ 5}' | grep -v Use` ## Use one or more spaces or% as separators

do

    if [$ r -gt 90] && [$ 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

[%] + Means one or more spaces or%

[[email protected] shares] # echo "12: aaa # sadfsad: 111 # 3333" | awk -F '[: #]' '{print $ 3}'

sadfsad ## uses: or # as the separator, so the third paragraph is sadfsad

[[email protected] shares] # echo "12: aaa # sadfsad: 111 # 3333" | awk -F '[: #]' '{print NF}'

5 ## uses: or # as the separator, there are 5 paragraphs

[[email protected] shares] # echo "12: aaa # sadfsad: 111 ## 3333" | awk -F '[: #]' '{print NF}'

6 ## uses: or # as the separator, there are 6 segments, because there is a ##

[[email protected] shares] # echo "12: aaa # sadfsad: 111 ## 3333" | awk -F '[: #] +' '{print NF}'

5 ## With one or more: or # as a separator, there are only 5 paragraphs








2018-4-22 17 weeks 4 lessons shell alarm system script configuration

Related Article

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.