Projet

Général

Profil

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

root / plugins / percona / percona_ @ 31ee164e

Historique | Voir | Annoter | Télécharger (4,23 ko)

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

    
44
import os
45
import sys
46
from warnings import filterwarnings
47

    
48
import MySQLdb
49
import MySQLdb.cursors
50

    
51
filterwarnings('ignore', category=MySQLdb.Warning)
52

    
53
program_name = os.path.basename(__file__)
54

    
55
variables = {
56
  'percona_queues': {
57
    'label': 'Queue sizes',
58
    'vlabel': 'size',
59
    'fields': ['wsrep_local_recv_queue', 'wsrep_local_send_queue']
60
  },
61
  'percona_flow': {
62
    'label': 'Flow control',
63
    'vlabel': '',
64
    'fields': ['wsrep_flow_control_sent', 'wsrep_flow_control_recv']
65
  },
66
  'percona_transactions': {
67
    'label': 'Transactions in and out',
68
    'vlabel': 'transactions',
69
    'fields': ['wsrep_replicated', 'wsrep_received']
70
  },
71
  'percona_transactions_bytes': {
72
    'label': 'Transactions in and out in bytes',
73
    'vlabel': 'bytes',
74
    'fields': ['wsrep_replicated_bytes', 'wsrep_received_bytes']
75
  },
76
  'percona_replication': {
77
    'label': 'Replication conflicts',
78
    'vlabel': 'conflicts',
79
    'fields': ['wsrep_local_cert_failures', 'wsrep_local_bf_aborts'],
80
  }
81
}
82

    
83
# Parse environment variables
84
# Mysql host
85
if "host" in os.environ and os.environ["host"] is not None:
86
    server = os.environ["host"]
87
else:
88
    server = "localhost"
89

    
90
# Mysql port
91
if "port" in os.environ and os.environ["port"] is not None:
92
    try:
93
        port = int(os.environ["port"])
94
    except ValueError:
95
        port = 3306
96
else:
97
    port = 3306
98

    
99
# Mysql username
100
if "user" in os.environ and os.environ["user"] is not None:
101
    login = os.environ["user"]
102
else:
103
    login = ""
104

    
105
# Mysql password
106
if "password" in os.environ and os.environ["password"] is not None:
107
    passw = os.environ["password"]
108
else:
109
    passw = ""
110

    
111
# Mysql connection handler
112
conn = None
113

    
114
label = variables[program_name]['label']
115
vlabel = variables[program_name]['vlabel']
116
fields = ["'{0}'".format(x) for x in variables[program_name]['fields']]
117

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

    
120
# Connect to mysql
121
try:
122
    conn = MySQLdb.connect(host=server, user=login, passwd=passw)
123
    cursor = conn.cursor()
124
except MySQLdb.Error as e:
125
    print("Error %d: %s" % (e.args[0], e.args[1]))
126
    sys.exit(1)
127

    
128

    
129
values = {}
130

    
131
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
132
    print("yes")
133
elif len(sys.argv) == 2 and sys.argv[1] == "config":
134

    
135
    print("graph_title %s" % label)
136
    print("graph_vlabel %s" % vlabel)
137
    print("graph_category db")
138
    print()
139

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

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

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

    
150
else:
151
    try:
152
        cursor.execute(query)
153
        results = cursor.fetchall()
154

    
155
        for result in results:
156
            print("%s_size.value %s" % (result[0], result[1]))
157

    
158
    except MySQLdb.Error as e:
159
        print("Error %d: %s" % (e.args[0], e.args[1]))
160

    
161
if conn:
162
    conn.close()