diff --git a/README.md b/README.md index 5f2dc8a..56b6bed 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,9 @@ usage: proxysql-nagios [-h] [-u USER] [-p PASSWD] [-H HOST] [-P PORT] [-d DEFAULTS_FILE] -t {conns,hg,rules,status,var} [-n VAR_NAME] [-l] [-r] [-w WARN_THRESH] [-c CRIT_THRESH] [-i INCLUDE_HG] [-g IGNORE_HG] - [--log-file LOGFILE] [--text] + [-m {pct_used,error}] [--log-file LOGFILE] [--text] -ProxySQL Nagios Check version 1.0.0 +ProxySQL Nagios Check version 1.1.0 Options: -h, --help show this help message and exit @@ -62,8 +62,8 @@ Options: runtime_mysql_XXX tables rather than the mysql_XXX tables, although this is more correct it can lead to excessive logging in ProxySQL and needs to be - explicitely enabled (applies to "hg" and "rules" check - types) + explicitely enabled (applies to "conns" and "rules" + check types) -w WARN_THRESH, --warning WARN_THRESH Warning threshold -c CRIT_THRESH, --critical CRIT_THRESH @@ -74,6 +74,9 @@ Options: -g IGNORE_HG, --ignore-hostgroup IGNORE_HG ProxySQL hostgroup(s) to ignore (only applies to "-- type hg" checks, accepts comma-separated list) + -m {pct_used,error}, --metric {pct_used,error} + ProxySQL hostgroup connection metric (one of pct_used, + error; only applies to "--type conn") --log-file LOGFILE File to log to (default = stdout) --text Disable Nagios output mode and output pure text ``` @@ -106,6 +109,11 @@ define command{ command_line $USER1$/proxysql-nagios -H $HOSTADDRESS$ -P $_HOSTPADMIN_PORT$ -d /etc/nagios/proxysql.cnf -t conns -w $ARG1$ -c $ARG2$ } +define command{ + command_name check_proxysql_conn_pool_error + command_line $USER1$/proxysql-nagios -H $HOSTADDRESS$ -P $_HOSTPADMIN_PORT$ -d /etc/nagios/proxysql.cnf -t conns -m error -w $ARG1$ -c $ARG2$ + } + define command{ command_name check_proxysql_hg command_line $USER1$/proxysql-nagios -H $HOSTADDRESS$ -P $_HOSTPADMIN_PORT$ -d /etc/nagios/proxysql.cnf -t hg -w $ARG1$ -c $ARG2$ --include $ARG3$ diff --git a/icinga2/check_proxysql.conf b/icinga2/check_proxysql.conf index d4201b4..5f9dfab 100644 --- a/icinga2/check_proxysql.conf +++ b/icinga2/check_proxysql.conf @@ -57,6 +57,10 @@ object CheckCommand "proxysql" { value = "$proxysql_ignore_hostgroup$" description = "ProxySQL hostgroup(s) to ignore (only applies to '--type hg' checks, accepts comma-separated list)" } + "--metric" = { + value = "$proxysql_metric$" + description = "ProxySQL hostgroup connection metric (one of pct_used, error; only applies to '--type conn')" + } } } diff --git a/icinga2/services.conf b/icinga2/services.conf index f5236d5..fd9e19d 100644 --- a/icinga2/services.conf +++ b/icinga2/services.conf @@ -18,6 +18,19 @@ apply Service "Proxysql connections" { assign where host.vars.client_endpoint && host.vars.proxy_sql } +apply Service "Proxysql errored connections" { + import "generic-service" + vars.proxysql_defaultfile = "/etc/mysql/proxysql.cnf" + vars.proxysql_type = "conns" + vars.proxysql_metric = "error" + vars.proxysql_warning = 3 + vars.proxysql_critical = 10 + check_command = "proxysql" + command_endpoint = host.vars.client_endpoint + assign where host.vars.client_endpoint && host.vars.proxy_sql +} + + apply Service "Proxysql status" { import "generic-service" vars.proxysql_defaultfile = "/etc/mysql/proxysql.cnf" diff --git a/proxysql-nagios b/proxysql-nagios index bb1b6f3..d1c33f5 100755 --- a/proxysql-nagios +++ b/proxysql-nagios @@ -11,7 +11,7 @@ WARNING = 1 CRITICAL = 2 UNKNOWN = 3 -version = '1.0.0' +version = '1.1.0' nagioslogger = logging.getLogger(__name__) def debug_factory(logger, debug_level): @@ -59,6 +59,9 @@ def get_args(): help='ProxySQL hostgroup(s) to include (only applies to "--type hg" checks, accepts comma-separated list)', dest='include_hg', type=str, default=None) parser.add_argument('-g', '--ignore-hostgroup', required=False, help='ProxySQL hostgroup(s) to ignore (only applies to "--type hg" checks, accepts comma-separated list)', dest='ignore_hg', type=str, default=None) + parser.add_argument('-m', '--metric', required=False, + help='ProxySQL hostgroup connection metric (one of pct_used, error; only applies to "--type conn")', + dest='conn_metric', choices=['pct_used','error'], type=str, default='pct_used') parser.add_argument('--log-file', required=False, help='File to log to (default = stdout)', dest='logfile', type=str) parser.add_argument('--text', required=False, @@ -139,6 +142,15 @@ def pconn_check(pconn, nagioslogger, args): else: srv_table = 'mysql_servers' + if args.conn_metric == 'pct_used': + q_conn_metric = 'cast((ConnUsed*1.0/max_connections)*100 as int)' + conn_metric_name = args.conn_metric + conn_metric_unit = '%' + elif args.conn_metric == 'error': + q_conn_metric = 'ConnERR' + conn_metric_name = 'ConnERR' + conn_metric_unit = '' + if args.ignore_hg is not None: ignore_hg = 'AND s.hostgroup NOT IN (%s)' % args.ignore_hg else: @@ -148,13 +160,13 @@ def pconn_check(pconn, nagioslogger, args): else: include_hg = '' - pcursor.execute('SELECT hostgroup_id hg, srv_host srv, port, cast((ConnUsed*1.0/max_connections)*100 as int) pct_used ' \ + pcursor.execute('SELECT hostgroup_id hg, srv_host srv, port, %s metric ' \ 'FROM main.%s r ' \ 'JOIN stats.stats_mysql_connection_pool s ' \ 'ON r.hostgroup_id = s.hostgroup ' \ 'AND srv_host = hostname ' \ 'AND srv_port = port %s %s ' \ - 'ORDER BY pct_used desc;' % (srv_table, ignore_hg, include_hg)) + 'ORDER BY metric desc;' % (q_conn_metric, srv_table, ignore_hg, include_hg)) output_values = pcursor.fetchall() @@ -164,12 +176,12 @@ def pconn_check(pconn, nagioslogger, args): fmt_unk_output = list() for output_value in output_values: - vals = ('hg: %s' % output_value['hg'], 'srv: %s' % output_value['srv'], 'port: %s' % output_value['port'], 'pct_used: %s%%' % output_value['pct_used']) - if int(output_value['pct_used']) < args.warn_thresh: + vals = ('hg: %s' % output_value['hg'], 'srv: %s' % output_value['srv'], 'port: %s' % output_value['port'], '%s: %s%s' % (conn_metric_name, output_value['metric'], conn_metric_unit)) + if int(output_value['metric']) < args.warn_thresh: fmt_ok_output.append(', '.join(vals)) - elif int(output_value['pct_used']) >= args.crit_thresh: + elif int(output_value['metric']) >= args.crit_thresh: fmt_crit_output.append(', '.join(vals)) - elif int(output_value['pct_used']) >= args.warn_thresh: + elif int(output_value['metric']) >= args.warn_thresh: fmt_warn_output.append(', '.join(vals)) else: fmt_unk_output.append(', '.join(vals))