about using shell scripts to customize the monitoring plug-in for the Nagios system

Source: Internet
Author: User

Before we write the monitoring plug-in, we first need to have some idea of the Nagios monitoring principle.

Nagios's function is to monitor the service and host, but he does not include this part of the function, all the monitoring, detection functions are through a variety of plug-ins to complete.

When Nagios is started, it periodically automatically calls the plugin to detect the state of the server, while Nagios maintains a queue.

all the status information returned by the plugin goes into the queue, Nagios reads the information from the beginning of the team and processes it, displaying the status results over the web.

Nagios provides a number of plug-ins that allow you to easily monitor many service statuses. After the installation is complete, there are all the plugins available in Nagios's/libexec in the Nagios home directory

For example, Check_disk is a plug-in that checks disk space, Check_load checks the CPU load, and so on. Basically every plug-in can run./check_xxx–h to see how and when it works.

Nagios can identify 4 status return information:

0 (OK) indicates the status is normal/green,

1 (WARNING) indicates warning/yellow

2 (CRITICAL) indicates a very serious error/red

3 (UNKNOWN) indicates an unknown error/dark yellow.

Nagios determines the state of the monitored object based on the value returned by the plug-in, and displays it through the Web for administrators to detect faults in a timely manner. The four monitoring States are as follows:

When we know that Nagios is using the command return value to determine the state, in the shell is also through the command exit status code to judge, so we can write a monitoring script

If you write the number of established connections that monitor the PostgreSQL database , you can write the following commands and syntax.

#!/bin/bash#if[" $"="- W"] && [" $"-gt"0"] && [" $"="- C"] && ["$4"-gt"0"]; ThenPgsql= ' netstat-lnaput|grep ": 5432"|grepEstablished |WC-l 'if["$pgsql"-ge"$4"]; Then                Echo "pgsql_concurrent:critical total: $pgsql-concurrent_count | Used= $pgsql; 200;500;"$ (Exit2)        elif["$pgsql"-ge" $"]; Then                Echo "pgsql_concurrent:warning Total: $pgsql-concurrent_count| Used= $pgsql; 200;500;"$ (Exit1)        Else                Echo "Pgsql_concurrent:ok Total: $pgsql-concurrent_count| Used= $pgsql; 200;500;"$ (Exit0)        fiElse        Echo "Check_pgsqlcount"        Echo ""        Echo "Usage:"        Echo "check_pgsqlcount-w <warn count>-C <crit count>"        Echo ""        Echo "Copyright (C) http://www.cnblogs.com/5201351 ([email protected])"Exitfi

The above monitoring scripts are written for the author's work, as a way to write the Nagios monitoring plug-in, where in the 3 echo statements in the IF statement, we can find that the content of the output is by | Separated

Where only the ' | ' is written The previous content is also OK, "|" After the content is optional,Nagios will "|" The content is then output as performance data . For output to Pnp4nagios, the performance data format is as follows:

' label '=value[uom]; [Warn]; [Crit]; [min]; [Max]

It is important to note that:

1. Multiple option values for performance data are separated by semicolons;

2. If the label contains a space, an equal sign, or a single quotation mark, the label needs to be enclosed in single quotation marks.

3, Warn/crit/min/max can be a null value, if the value units must be unified

4, if the UOM unit is%, then min and Max do not need to specify

5. UOM unit can be as follows: Default NULL, indicates quantity (for number of users, number of processors, etc.)

s    = seconds (can also be used with Us,ms)% for     percent B    to represent bytes (also KB,MB,TB,GB) c    a sequential count (e.g., number of bytes transmitted by the interface)

about using shell scripts to customize the monitoring plug-in for the Nagios system

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.