3
# Copyright (C) 2015 Canonical
5
# Author: Jill Rouleau <jill.rouleau@canonical.com>
7
# Check a running MySQL instance to see if it's running hot on used connections
14
hostname = socket.gethostname()
15
db = MySQLdb.connect(host='localhost', user='debian-sys-maint', passwd='0308NGsnQlrPaiso')
20
c.execute("SHOW STATUS LIKE 'threads_connected';")
24
c.execute("SHOW GLOBAL VARIABLES LIKE 'max_connections';")
28
percent_used = round(((float(CheckMysql.threads) / float(CheckMysql.maxconns)) * 100), 2)
30
parser = argparse.ArgumentParser()
31
parser.add_argument('-w', action="store", dest="warn", type=int)
32
parser.add_argument('-c', action="store", dest="crit", type=int)
33
args = parser.parse_args()
35
if percent_used < args.warn:
36
print("OK - {} is using {} percent of it's {} available connections".format
37
(hostname, percent_used, CheckMysql.maxconns)),
39
elif percent_used >= args.warn and percent_used < args.crit:
40
print("{} is using {} out of {} available connections, {} percent".format
41
(hostname, CheckMysql.threads, CheckMysql.maxconns, percent_used)),
43
elif percent_used >= args.crit:
44
print("{} is using {} out of {} available connections, {} percent".format
45
(hostname, CheckMysql.threads, CheckMysql.maxconns, percent_used)),