Get the App
SLTechnology News&Howtos  ›  Database  › 

Error log monitoring alarm script

Shulou Source: shulou.com Published: 2022-06-01 16:36:07 09月19日 Update

Write at the front:

In practice, checking the database error log regularly is an essential work item. But the check does not necessarily produce a new error message, or we prefer never to have an error message, because it means that our database is robust. In this case, it is impossible to predict when the error message will occur, and if we check the error log is often normal, it is easy to form thinking inertia, over time without misinformation, we are easy to ignore this work item. But the error log is essential for us, at this time, we hope that when there is an error message, directly email the police to notify me, I can make time to do something more meaningful. If you have the same need, then this article may help you.

Script file:

Cat monitor_errorlog.sh

#! / bin/bash

# error log monitoring alarm script

# Monitoring date

Time= `date +% F`

# time=2018-06-02

Cd / home/dbalzb

# generate error log monitoring files according to the date. First, check whether the error log has been generated on the same day.

Ls errorlog-$time.txt & > / dev/null

# the status return value is non-0, which means that it has not been generated in the current day

If [$?-ne 0]; then

Cat / home/data/mysql/error.log | grep "$time" | egrep-I 'error | warning' > errorlog-$time.txt

# determine whether there is an error log that day

Num= `cat errorlog-$time.txt | wc-l`

If [$num-ne 0]; then

Mutt lizibin_1@126.com-s "errorlog3306"

< errorlog-$time.txt fi md5sum errorlog-$time.txt >

Md5-errorlog-$time.txt

Else

Cat / home/data/mysql/error.log | grep "$time" | egrep-I 'error | warning' > errorlog-$time-new.txt

# script files executed for the second and later times will generate new errorlog files and new md5sum values

Md5sum errorlog-$time-new.txt > > md5-errorlog-$time.txt

Str1= `cat md5-errorlog-$time.txt | sed-n '1p' | awk' {print $1}'`

Str2= `cat md5-errorlog-$time.txt | sed-n '2p' | awk' {print $1}'`

# num1= `cat errorlog-$time-new.txt | wc-l`

# cat errorlog-$time.txt > > errorlog-$time-history.txt

# compare the md5sum values of the two files to determine whether a new error log is generated

If [$str1! = $str2]; then

Mutt lizibin_1@126.com-s "new-errorlog3306"

< errorlog-$time-new.txt #cat errorlog-$time-new.txt >

> errorlog-$time-history.txt

Fi

/ bin/rm-f errorlog-$time-new.txt

Sed-I '2d' md5-errorlog-$time.txt

Fi

Add scheduled tasks: (execute once every hour, can be adjusted by yourself)

5 * / 1 * sh / home/dbalzb/monitor_errorlog.sh

All roads lead to Rome. How do you monitor database error logs dynamically? Welcome to leave a message below.

Tags: Error log generation file monitoring information script data database time work inspection alarm essential date monitoring alarm robust over time all roads lead to Rome two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Shulou Tech Info Microsoft MySQL