Send monitoring metrics to the internal mailbox in Linux
Database health monitoring is a very important task. An important indicator/KPI monitoring result has a dedicated collection, monitoring, and alarm system for relevant tasks.
Some indicators that are not very important or are still in the design and debugging phase, I just want to send them to my own mailbox. This article describes the process of configuring mail to send monitoring data on the server.
The server version is RHEL 6.2:
[Pg @ gtlions ~] # Cat/etc/issue
Red Hat Enterprise Linux Server release 6.2 (Santiago)
Kernel \ r on an \ m
Disable related servers:
[Root @ gtlions etc] # service sendmail stop
[Root @ gtlions etc] # service postfix stop
[Root @ gtlions etc] # service sendmail status
Sendmail stopped
Sm-client stopped
[Root @ gtlions etc] # service postfix status
Master stopped
The next step is important. By default, the SMTP used by the server cannot send emails to the internal mailbox of the enterprise organization. Therefore, you need to configure the mailbox information of the enterprise organization:
[Root @ gtlions etc] # tail/etc/mail. rc
# For Linux and BSD, this shoshould be set.
Set bsdcompat
Set from = [Sender's email address]
Set smtp = [smtp server address]
Set smtp-auth-user = [email user name]
Set smtp-auth-password = [email password]
Set smtp-auth = login
Manually test the email sending function:
[Root @ gtlions etc] # echo hello world | mail-s "test" gtlions@lai.com
[Root @ gtlions etc] # python dbcheck. py> dbcheck.txt; cat dbcheck.txt | mail-s dbcheckgtlions@lai.com
[Root @ gtlions etc] # python dbcheck. py> dbcheck.txt; mail-s dbcheckgtlions@lai.com <dhcheck.txt
[Root @ gtlions etc] # python dbcheck. py | mail-s dbcheck gtlions@lai.com
Shell script for sending emails:
[Pg @ gtlions] $ cat/home/pg/PycharmProjects/dbcheck. sh
#! /Bin/sh
./Etc/profile
.~ /. Bash_profile
Python/home/pg/PycharmProjects/dbcheck. py | mail-s "dbcheck 'date + % f'' % t'" gtlions@lai.com
Set the scheduled task and CRON calls the shell script:
[Pg @ gtlions] $ crontab-l
*/1 ***** sh/home/pg/PycharmProjects/dbcheck. sh 1>/home/pg/check. log 2> & 1
-EOF-