jonathanio / monitoring-nagios-haproxy

Nagios plugin (suitable for Nagios Check-compatible programs) for monitoring HAProxy services.
GNU General Public License v2.0
16 stars 19 forks source link

check_haproxy Nagios Check Script

This is a Nagios plugin to check the status of HAProxy over a socket connection (by default, /var/run/haproxy.sock) and parse the statistics to ensure that it is operating within accepted limits, as per the defaults, or as set for each frontend/backend.

Usage

check_haproxy [--defaults (defaults)] [--overrides (1 2 ... n)]
  [--[no]frontends] [--[no]backends] [--[no]servers]
  [--socket (path)] [--help]

-f, --[no]frontends

Enable/disable checks for the frontends in HAProxy (that they're marked as OPEN and the session limits haven't been reached).

-b, --[no]backends

Enable/disable checks for the backends in HAProxy (that they have the required quorum of servers, and that the session limits haven't been reached).

-s, --[no]servers

Enable/disable checks for the servers in HAProxy (that they haven't reached the limits for the sessions or for queues).

-D, --defaults (defaults)

Set/Override the defaults which will be applied to all checks (unless specifically set by --overrides). Takes the form:

{u,d,x},{svr_warn},{svr_crit},{sess_warn},{sess_crit}

Each of these is optional, but the positioning is important. To fully override, set (for example):

u,10,5,.25,0.5

which means:

To override only some of these values from the pre-set defaults (u,5,2,.75,.9), simply leave the others as empty, for example: ,10,7 will leave checks as up, but increase the server WARN/CRIT to 10/7. or to switch to use down, use d,, or off with x.

Each number has two meanings:

The code does not alter this limit if it is greater than the available servers or sessions so there are situations where the alert may not trigger. For example, in the event of down being the trigger and the number of servers is less than the Warning or Critical thresholds, the error may never trigger. It is generally better to use up and percentage values where you are going to have a flexible number of backends.

-O, --overrides (override override ... override)

Override the defaults for a particular frontend or backend, in the form name:override, where override is the same format as --defaults above. For example, to override the frontend called "api" and allow that to increase to limits of 15/10 for WARN/CRIT, use api:,15,10. Add as many as you like as space-delimited options:

--overrides api:,15,10 assets:d,2,5 webmail:u,3,2

-S, --socket /path/to/socket

Path to the socket check_haproxy should connect to (requires read/write permissions and must be at least user level; no operator or admin privileges needed).

Icinga2 configuration

Copy check_haproxy.icinga2.conf to the icinga2 zone and define a new service for all Linux hosts with vars.haproxy, for example:

apply Service "Haproxy stats" {
  import "generic-service"
  check_command = "haproxy"
  vars.haproxy_socket = "/var/run/haproxy/admin.sock"
  vars.haproxy_default = "C<d,1,1,75,90>"
  command_endpoint = host.vars.client_endpoint
  assign where host.vars.client_endpoint && host.vars.os == "Linux" && host.vars.haproxy
}

Licence

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.