Zabbix implementation of MySQL database monitoring (iv)

Source: Internet
Author: User

The previous content is to use the third-party developed plug-in for MySQL monitoring, there may be some of our concern about the monitoring content is not in it, then a common method is to define our own script and integrate it into the Zabbix, so that the original monitoring based on the strong complement. The following uses a script to monitor the master-slave replication status and alarm notification.

Let's introduce some common terms in Zabbix:

Host:           the network device to monitor, which can be specified by IP or DNS name. Host group: A logical container for hosts, which   can contain hosts and templates, but hosts and stencils within the same group cannot link to each other, and host groups are typically used when group users or user groups assign monitoring permissions. Monitoring item:         A specific monitoring indicator of the relevant data, the data from the monitored object, item is the core of data collection Zabbix, without item, there is no data, each item is identified by "key". Trigger (Trigger):      An expression that evaluates whether the data received within a particular item of a monitor object is within a reasonable range, that is, the threshold value, the trigger state is converted from "OK" to "problem" when the amount of data received is greater than the threshold value. When the amount of data is returned to a reasonable extent, its state is converted from "problem" back to "OK". Event:         A noteworthy event that occurs, such as the state transition of a trigger, the automatic registration of a new agent or a re-launch agent, and so on. Action:        refers to a pre-defined processing method for a specific event, by including an action (such as sending a notification) and a condition (when an action is taken). Alarm escalation (escalation): A custom scheme that sends an alert or executes a remote command, such as how often to send an alert every time. Media:         means or channels for sending notifications, such as Email,jabber or SMS. Notification (motification):  information about an event that is sent to the user through the selected media. Remote command: A predefined command that can be executed automatically when the monitored host is under a certain condition. Template:      a set of preset entries that are used to quickly define a monitored host, usually containing the item,trigger,graph,screen,application,low-level discovery rule, Templates can be linked directly to a single host. Application (Application):   one or more HTTP requests to detect the availability of a Web site. Front End (frontend):      Zabbix Web interface.

First, the script monitoring

1. Create a monitoring user

GRANT PROCESS, REPLICATION CLIENT on *. * to ' mpm ' @ ' 127.0.0.1 ' identified by PASSWORD ' *3B9F0373BC48DCD0459D19550D373FEBCC E003c8 '
Flush privileges;

2, write the monitoring script

#!/bin/sh#created by: Healthy grass #create date:2015/8/17#function:check mysql master-slave replication is OK or not ok.declare-a  slave_is  slave_is= ($ (/usr/local/mysql/bin/mysql-h 127.0.0.1  -umpm-p ' mpm '-e "show slave status \g" |grep Running |awk ' {print $} '))  if ["${slave_is[0]}" = "yes"-a "${slave_is[1]}" = "yes"               then                      echo ' 2 '   #代表正 Often two yes             else                      echo '-1 '  #代表不正常      fi

Execute the above script if the master-slave copy is normal, return status 0, otherwise return status 2.

3. Declare key in AGENTD configuration file

vim/usr/local/zabbix/etc/zabbix_agentd.conf# Add the following sentence Userparameter=mysql.replication,/data/scripts/check_ Replication.sh   #逗号前面是key, followed by scripts executed

4. Restart the AGENTD service and test

[[email protected] etc]#/etc/init.d/zabbix_agentd restart stop Zabbix agent:                                        [OK] starting Zabbix agent:                                     [OK]

Then go to Zabbix server to see if you can get the monitoring value to key:

[Email protected] bin]#/zabbix_get-s 192.168.245.131-k "mysql.replication" warning:using a password on the command Li Ne interface can be insecure.2

Okay, here the script is written, the following is the Zabbix Web page to create monitoring items, triggers, events and so on, the above mentioned several terms in series, to achieve the monitoring we need.

5, Zabbix Web side Add monitoring content

1) Create a monitoring item (item)

Click on the Create monitoring entry on the right to go to the following page:

type : Select Active mode here, need to open refreshactivechecks in agentd config file, indicate how often to request monitoring item detection, in seconds per server.
Key value: Need to be the same as the key declared in the Agentd configuration file

2) Create a trigger

3) View monitoring effects

You can stop and start the master-slave copy separately to see the specific monitoring effect.

Stop slave:

Start slave:

Second, alarm notification

1, Mail alarm

Zabbix sending mail alerts requires an environment on the server that can send mail, ensuring that the LIUNX server can send messages.

1) Installation and configuration Mutt

Yum install mutt-yvim/etc/muttrcset sendmail= "/USR/LOCAL/MSMTP/BIN/MSMTP" #你的msmtp命令路径set use_from=yesset realname= " Zabbix.com "   #随意填写个名字set editor=" Vim "

2) Installation and configuration Msmtp

Mkdir-p/USR/LOCAL/MSMTP/ETCVIM/USR/LOCAL/MSMTP/ETC/MSMTPRC Add the following # Set default values for all following accounts.defaultslogfile/usr/local/msmtp/log/mmlog.log# the SMTP server of the Provider.account 163# SMTP mail server address host smtp.163.com# sent Mail emailfrom [email protected]auth login# mail server login account user [email protected]# mail server login password #password [email] protected]#$% password jwehzbgxxbkkfmhw   #指163的客户端授权密码 # Set a default Accountaccount default:163

Then you need to change the permissions of the directory, it is important, or not send the mail, also not very good troubleshooting:

[Email protected] log]# chown-r zabbix.zabbix/usr/local/msmtp/

You can test to see if the message could be sent:

/USR/LOCAL/MSMTP/BIN/MSMTP [email protected]

Make sure that the server sends the mail as expected, and the next step is to configure Zabbix.

3) Create a script to send the message: The script must be uniformly placed in the/usr/local/zabbix/share/zabbix/alertscripts directory, otherwise Zabbix cannot be found. Of course you can also modify the Conf configuration file on the server to reassign the location. Need to point out that the script here is verified, there are many online is through the mutt call MSMTP, beginning I also use this method, but Zabbix page display has been sent, but dead and alive receive mail, spent a lot of time, estimate the problem on mutt, do not know what reason, spent a lot of time. Later instead of MSMTP directly send it, as follows:

#! /bin/shdebug=1if [$DEBUG-gt 0]thenexec 2>>/usr/local/msmtp/log/msmtp-logset-xfifrom= ' [email protected] ' MSMTP _account= ' 163 '     #msmtprc配置文件中的account # Parameters (as passed by Zabbix): Recipient=$1subject=$2message=$3date= ' Date--rfc-2822 ' sed ' s/$/\r/' <<eof | /USR/LOCAL/MSMTP/BIN/MSMTP--account $MSMTP _account $recipient from: < $FROM > To: < $recipient >subject: $ Subjectdate: $date $messageeof

4) Create a warning type, action, user, etc. on the Zabbix web.

    • Create a warning Type: management--Media type

Name can be self-starting, type Select "Script", the script name to fill in the script just created, do not write the full path, if there is a suffix name, please bring, otherwise cannot find.

    • Create action: Configure-action

Above the red box needs to fill in the correct, other according to the need to fill out their own.

    • Create a user and associate an event: Manage-user-click Red

To the "Warning Media" column to add just the new media we created, the recipient needs to fill in the correct, the status is enabled.

Now can be a problem alarm, the following the master-slave copy off to see if you can receive mail. Here is the email I received:

If you do not receive, first from the Zabbix to troubleshoot, monitored-- events , see the last column of action, if the normal means to send the message OK, otherwise it is a failure, you can click on the previous date for detailed view:

Here, Zabbix the whole process is the same, from nothing to the alarm to send an email, the following through a picture to connect the process from scratch:

"description":

    • First, you need to add a host group (which you can use to authorize by group), and then the monitoring host.
    • New monitoring entries in the monitored host need to be specified in the AGENTD configuration file Key,zabbix to find the output value of the script monitoring through key.
    • Creates a new trigger that indicates that a specific action is triggered based on the monitoring item output value, a new trigger needs to be associated with a monitoring item, and an expression selects a monitoring item to associate.
    • Next, you create the action because you need to perform some action based on the trigger. Associate triggers under the Conditions column in action (such as setting conditions: Trigger = problem, which is the action when there is a problem)
    • Create a warning medium (created before creating an action). Because the action contains many kinds of operations, such as sending e-mails, executing commands, and so on, the action and the warning media need to be correlated, and the warning medium can belong to a user by selecting an action in the action.

At this point, through two weeks of study, Zabbix monitoring MySQL database can finally work, in fact, Zabbix there are many features, such as automatic discovery of host, and so on, temporarily before the end of it, the process of building learning record down, the next time you can be handy.

Zabbix implementation of MySQL database monitoring (iv)

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.