Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / percona / percona_ @ 59751681

Historique | Voir | Annoter | Télécharger (3,75 ko)

1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# vim: set fileencoding=utf-8
4
#
5
# Munin plugin for percona
6
#
7
# created by Sven Schliesing
8
# borrowed code from mysql_aggregate_ by Igor Borodikhin
9
#
10
# License : GPLv3
11
#
12
# parsed environment variables:
13
# host: hostname or ip-address of Mysql server (default - localhost)
14
# port: port number of Mysql server (default - 3306)
15
# user: username to access Mysql server (default - empty)
16
# password: password of Mysql user (default - empty)
17
#
18
# ## Requirements
19
# This plugin requires pythons MySQLdb module which can be installed via easy_install.
20
#
21
# ## Installation
22
# Copy file to directory /usr/share/munin/plugins/ and create symbolic links for each type you wish to monitor:
23
# 	percona_flow
24
# 	percona_queues
25
# 	percona_replication
26
# 	percona_transactions
27
# 	percona_transactions_bytes
28
#
29
# Minimal config for monitoring local Percona-Server:
30
#
31
#     [percona]
32
#     env.user root
33
#     env.password vErYsEcReT
34
#
35
#%# capabilities=autoconf
36
#%# family=contrib
37

    
38
from warnings import filterwarnings
39
import os, sys, MySQLdb, MySQLdb.cursors
40
filterwarnings('ignore', category = MySQLdb.Warning)
41

    
42
progName = os.path.basename(__file__)
43

    
44
variables = {
45
  'percona_queues': {
46
    'label': 'Queue sizes',
47
    'vlabel': 'size',
48
    'fields': ['wsrep_local_recv_queue', 'wsrep_local_send_queue']
49
  },
50
  'percona_flow': {
51
    'label': 'Flow control',
52
    'vlabel': '',
53
    'fields': ['wsrep_flow_control_sent', 'wsrep_flow_control_recv']
54
  },
55
  'percona_transactions': {
56
    'label': 'Transactions in and out',
57
    'vlabel': 'transactions',
58
    'fields': ['wsrep_replicated', 'wsrep_received']
59
  },
60
  'percona_transactions_bytes': {
61
    'label': 'Transactions in and out in bytes',
62
    'vlabel': 'bytes',
63
    'fields': ['wsrep_replicated_bytes', 'wsrep_received_bytes']
64
  },
65
  'percona_replication': {
66
    'label': 'Replication conflicts',
67
    'vlabel': 'conflicts',
68
    'fields': ['wsrep_local_cert_failures', 'wsrep_local_bf_aborts'],
69
  }
70
}
71

    
72
# Parse environment variables
73
# Mysql host
74
if "host" in os.environ and os.environ["host"] != None:
75
    server = os.environ["host"]
76
else:
77
    server =  "localhost"
78

    
79
# Mysql port
80
if "port" in os.environ and os.environ["port"] != None:
81
    try:
82
        port = int(os.environ["port"])
83
    except ValueError:
84
        port = 3306
85
else:
86
    port = 3306
87

    
88
# Mysql username
89
if "user" in os.environ and os.environ["user"] != None:
90
    login = os.environ["user"]
91
else:
92
    login = ""
93

    
94
# Mysql password
95
if "password" in os.environ and os.environ["password"] != None:
96
    passw = os.environ["password"]
97
else:
98
    passw = ""
99

    
100
# Mysql connection handler
101
conn = None
102

    
103
label = variables[progName]['label']
104
vlabel = variables[progName]['vlabel']
105
fields = ['\'{0}\''.format(x) for x in variables[progName]['fields']]  
106

    
107
query = "show status where Variable_name in (%s)" % ', '.join(fields)
108

    
109
# Connect to mysql
110
try:
111
    conn = MySQLdb.connect(host=server, user=login, passwd=passw)
112
    cursor = conn.cursor()
113
except MySQLdb.Error, e:
114
    print "Error %d: %s" % (e.args[0], e.args[1])
115
    sys.exit(1)
116

    
117

    
118
values = {}
119

    
120
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
121
    print "yes"
122
elif len(sys.argv) == 2 and sys.argv[1] == "config":
123

    
124
    print "graph_title %s" % label
125
    print "graph_vlabel %s" % vlabel
126
    print "graph_category percona"
127
    print ""
128

    
129
    try:
130
        cursor.execute(query)
131
        results = cursor.fetchall()
132

    
133
        for result in results:
134
        	print "%s_size.label %s" % (result[0], result[0])
135

    
136
    except MySQLdb.Error, e:
137
        print "Error %d: %s" % (e.args[0], e.args[1])
138

    
139
else:
140
    try:
141
        cursor.execute(query)
142
        results = cursor.fetchall()
143

    
144
        for result in results:
145
        	print "%s_size.value %s" % (result[0], result[1])
146

    
147
    except MySQLdb.Error, e:
148
        print "Error %d: %s" % (e.args[0], e.args[1])
149

    
150
if conn:
151
    conn.close()