A better record of how MySQL monitoring scripts are written

Source: Internet
Author: User
Tags mysql client

Recently, their business to go online, after the launch, need to consider the various services to monitor, including (httpd services, mysqld services, etc.), now want to take mysqld services as an example to summarize the way the script is the most professional and reasonable:

(1). Monitor MySQL's service according to MySQL's port number. (Common for local services that monitor MySQL)

One of the more common scripts:

1 netstat-natup| grep mysqld| awk -F '[:]+'{print $}'

Above is the MYSQLD port number is filtered, the disadvantage of this method is: There may be a port, but the service may not be normal. For example: The system load is very high, the CPU load is also very high, the connection is full, this is one of its problems.

(2). Monitor MySQL's services according to the MySQL process:

One of the more common scripts:

1 PS -aux | grep mysqld | grep grep| WC -L

The disadvantage of this approach is the same as above: there may be ports on, but the service may not be normal. For example: The system load is very high, the CPU load is also very high, the connection is full, this is one of its problems.

(3). Use the MySQL client's commands and connect to MySQL with the account, and then determine whether MySQL is normal (local or remote connection state) based on the status of the command returned or what is returned.

A common judgment script (just a few of the core content):

1 mysql-uroot-p1234-e'Select version (); '>&/dev/null2echo $?

If the $0 above, the description is able to connect normally, if it is 1, then the connection failed.

The disadvantage of this approach is that you need to have MySQL connection client, to have the data account and password, and to connect the database host authorization.

(4). Monitor MySQL's service status by Php/java the way you connect to MySQL directly.

A more common script is also relatively simple:

1 <? PHP 2 $conn mysql_connect  die (' MySQL coulc not connect '. Mysql_error ()); 3 4 ?>

This approach is closest to the user's access, the effect is the best, because this way, even if the port exists, but as long as the server CPU load is high, the user's access is certainly not normal.

So the best way to alarm is not whether the service alarm is turned on, but whether the site's user access is still normal.  This is the best alarm principle and method. We should consider the problem from the user's point of view, not to say from the angle of operation and maintenance. So you should use this method at work.

A better record of how MySQL monitoring scripts are written

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.