Use the Perl hash array for personalized monitoring

Source: Internet
Author: User

For DBAs, an accurate and stable monitoring system is nothing more than a powerful sword. If hundreds of systems rely on manual checks every day, the workload is too heavy to imagine, and the human cannot capture errors in real time.

However, with so many database systems, each database has different load and different importance for the entire system, and the DBA in charge cannot be the same person. If all the metrics are monitored based on the same KPI threshold, some important systems may not be able to generate accurate alarms, while some unimportant systems may frequently report false alarms.

For example, because some core libraries use relatively high-end hardware for system load ~ About 30 is normal, and some edge databases may exceed 5, which is dangerous. Therefore, different check thresholds must be set for different databases for load.

If you want to achieve this through the shell script, you may need to write a bunch of if or Case Judgments. Once you want to change the configuration, it will be a headache. However, the Perl hash array can solve this problem well.

#! /Usr/bin/perl-W
# Creator: Jiangfeng
######################################## ####################
Use strict;

# Configure the KPI check threshold for each host
# Two threshold values are configured here to send im reminders when the first value is reached, and send SMS messages when the second value is reached
# Server, load1 load2
My % cutoff = ("db1", [30, 40],
"DB2", [20, 35],
"Db3", [10, 18]
);

# Configure the position in the array of each threshold value, so that you do not need to modify the function code even if you modify the threshold position in the future.
# Separating configuration and functions greatly simplifies subsequent maintenance work
My ($ load1, $ load2) = (0, 1 );
######################################## ####################
# Check the load function
Sub check_load {
My ($ server) = @_;
My $ load = get_server_load (); # obtain the current load of the Database Host. We will not go into details here.
My $ cutoff1 = $ cutoff {$ server} [$ load1];
My $ cutoff2 = $ cutoff {$ server} [$ load2];

If ($ load> $ cutoff2 ){
My $ mesg = $ server. "load more than". $ cutoff2. ", now is". $ load. "/N ";
Send_mobile ($ server, $ mesg); # Send a mobile phone alarm when the value is greater than load2.
}
Elsif ($ load> $ cutoff1 ){
My $ mesg = $ server. "load more than". $ cutoff1. ", now is". $ load. "/N ";
Send_wangwang ($ server, $ mesg); # Send a trademanager alarm when the value is greater than load1.
}
}
######################################## ####################
# Check the load of all hosts cyclically
Foreach my $ server (Keys (% cutoff )){
Print "----". $ server. "-----/N ";
Check_load ($ server );
}

The $ server parameter is introduced in the send_mobile and send_wangwang functions for sending alerts. You can also use the hash array configuration to send alerts to different owners. There is no big difference between the basic idea and here, do not repeat the code.

-- EOF --

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.