Skip to content

Add --metric parameter to check for different connection metrics #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
```
Expand Down Expand Up @@ -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$
Expand Down
4 changes: 4 additions & 0 deletions icinga2/check_proxysql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
}
}
}

13 changes: 13 additions & 0 deletions icinga2/services.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 19 additions & 7 deletions proxysql-nagios
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand All @@ -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))
Expand Down