Révision 31ee164e
plugin percona_: fix python style; python3 compatibility
| plugins/percona/percona_ | ||
|---|---|---|
| 24 | 24 |
# This plugin requires pythons MySQLdb module which can be installed via easy_install. |
| 25 | 25 |
# |
| 26 | 26 |
# ## Installation |
| 27 |
# Copy file to directory /usr/share/munin/plugins/ and create symbolic links for each type you wish to monitor: |
|
| 27 |
# Copy file to directory /usr/share/munin/plugins/ and create symbolic links for each type you wish |
|
| 28 |
# to monitor: |
|
| 28 | 29 |
# percona_flow |
| 29 | 30 |
# percona_queues |
| 30 | 31 |
# percona_replication |
| ... | ... | |
| 37 | 38 |
# env.user root |
| 38 | 39 |
# env.password vErYsEcReT |
| 39 | 40 |
# |
| 40 |
#%# capabilities=autoconf |
|
| 41 |
#%# family=contrib |
|
| 41 |
# #%# capabilities=autoconf
|
|
| 42 |
# #%# family=contrib
|
|
| 42 | 43 |
|
| 44 |
import os |
|
| 45 |
import sys |
|
| 43 | 46 |
from warnings import filterwarnings |
| 44 |
import os, sys, MySQLdb, MySQLdb.cursors |
|
| 45 |
filterwarnings('ignore', category = MySQLdb.Warning)
|
|
| 46 | 47 |
|
| 47 |
progName = os.path.basename(__file__) |
|
| 48 |
import MySQLdb |
|
| 49 |
import MySQLdb.cursors |
|
| 50 |
|
|
| 51 |
filterwarnings('ignore', category=MySQLdb.Warning)
|
|
| 52 |
|
|
| 53 |
program_name = os.path.basename(__file__) |
|
| 48 | 54 |
|
| 49 | 55 |
variables = {
|
| 50 | 56 |
'percona_queues': {
|
| ... | ... | |
| 76 | 82 |
|
| 77 | 83 |
# Parse environment variables |
| 78 | 84 |
# Mysql host |
| 79 |
if "host" in os.environ and os.environ["host"] != None:
|
|
| 85 |
if "host" in os.environ and os.environ["host"] is not None:
|
|
| 80 | 86 |
server = os.environ["host"] |
| 81 | 87 |
else: |
| 82 |
server = "localhost"
|
|
| 88 |
server = "localhost" |
|
| 83 | 89 |
|
| 84 | 90 |
# Mysql port |
| 85 |
if "port" in os.environ and os.environ["port"] != None:
|
|
| 91 |
if "port" in os.environ and os.environ["port"] is not None:
|
|
| 86 | 92 |
try: |
| 87 | 93 |
port = int(os.environ["port"]) |
| 88 | 94 |
except ValueError: |
| ... | ... | |
| 91 | 97 |
port = 3306 |
| 92 | 98 |
|
| 93 | 99 |
# Mysql username |
| 94 |
if "user" in os.environ and os.environ["user"] != None:
|
|
| 100 |
if "user" in os.environ and os.environ["user"] is not None:
|
|
| 95 | 101 |
login = os.environ["user"] |
| 96 | 102 |
else: |
| 97 | 103 |
login = "" |
| 98 | 104 |
|
| 99 | 105 |
# Mysql password |
| 100 |
if "password" in os.environ and os.environ["password"] != None:
|
|
| 106 |
if "password" in os.environ and os.environ["password"] is not None:
|
|
| 101 | 107 |
passw = os.environ["password"] |
| 102 | 108 |
else: |
| 103 | 109 |
passw = "" |
| ... | ... | |
| 105 | 111 |
# Mysql connection handler |
| 106 | 112 |
conn = None |
| 107 | 113 |
|
| 108 |
label = variables[progName]['label']
|
|
| 109 |
vlabel = variables[progName]['vlabel']
|
|
| 110 |
fields = ['\'{0}\''.format(x) for x in variables[progName]['fields']]
|
|
| 114 |
label = variables[program_name]['label']
|
|
| 115 |
vlabel = variables[program_name]['vlabel']
|
|
| 116 |
fields = ["'{0}'".format(x) for x in variables[program_name]['fields']]
|
|
| 111 | 117 |
|
| 112 | 118 |
query = "show status where Variable_name in (%s)" % ', '.join(fields) |
| 113 | 119 |
|
| ... | ... | |
| 115 | 121 |
try: |
| 116 | 122 |
conn = MySQLdb.connect(host=server, user=login, passwd=passw) |
| 117 | 123 |
cursor = conn.cursor() |
| 118 |
except MySQLdb.Error, e:
|
|
| 119 |
print "Error %d: %s" % (e.args[0], e.args[1])
|
|
| 124 |
except MySQLdb.Error as e:
|
|
| 125 |
print("Error %d: %s" % (e.args[0], e.args[1]))
|
|
| 120 | 126 |
sys.exit(1) |
| 121 | 127 |
|
| 122 | 128 |
|
| 123 | 129 |
values = {}
|
| 124 | 130 |
|
| 125 | 131 |
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
| 126 |
print "yes"
|
|
| 132 |
print("yes")
|
|
| 127 | 133 |
elif len(sys.argv) == 2 and sys.argv[1] == "config": |
| 128 | 134 |
|
| 129 |
print "graph_title %s" % label
|
|
| 130 |
print "graph_vlabel %s" % vlabel
|
|
| 131 |
print "graph_category db"
|
|
| 132 |
print ""
|
|
| 135 |
print("graph_title %s" % label)
|
|
| 136 |
print("graph_vlabel %s" % vlabel)
|
|
| 137 |
print("graph_category db")
|
|
| 138 |
print()
|
|
| 133 | 139 |
|
| 134 | 140 |
try: |
| 135 | 141 |
cursor.execute(query) |
| 136 | 142 |
results = cursor.fetchall() |
| 137 | 143 |
|
| 138 | 144 |
for result in results: |
| 139 |
print "%s_size.label %s" % (result[0], result[0])
|
|
| 145 |
print("%s_size.label %s" % (result[0], result[0]))
|
|
| 140 | 146 |
|
| 141 |
except MySQLdb.Error, e:
|
|
| 142 |
print "Error %d: %s" % (e.args[0], e.args[1])
|
|
| 147 |
except MySQLdb.Error as e:
|
|
| 148 |
print("Error %d: %s" % (e.args[0], e.args[1]))
|
|
| 143 | 149 |
|
| 144 | 150 |
else: |
| 145 | 151 |
try: |
| ... | ... | |
| 147 | 153 |
results = cursor.fetchall() |
| 148 | 154 |
|
| 149 | 155 |
for result in results: |
| 150 |
print "%s_size.value %s" % (result[0], result[1])
|
|
| 156 |
print("%s_size.value %s" % (result[0], result[1]))
|
|
| 151 | 157 |
|
| 152 |
except MySQLdb.Error, e:
|
|
| 153 |
print "Error %d: %s" % (e.args[0], e.args[1])
|
|
| 158 |
except MySQLdb.Error as e:
|
|
| 159 |
print("Error %d: %s" % (e.args[0], e.args[1]))
|
|
| 154 | 160 |
|
| 155 | 161 |
if conn: |
| 156 | 162 |
conn.close() |
Formats disponibles : Unified diff