root / plugins / percona / percona_ @ 31ee164e
Historique | Voir | Annoter | Télécharger (4,23 ko)
| 1 | 59751681 | muffl0n | #!/usr/bin/env python |
|---|---|---|---|
| 2 | # -*- coding: utf-8 -*- |
||
| 3 | # vim: set fileencoding=utf-8 |
||
| 4 | # |
||
| 5 | fe864b9d | muffl0n | # 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 | 59751681 | muffl0n | # |
| 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 | 31ee164e | Lars Kruse | # Copy file to directory /usr/share/munin/plugins/ and create symbolic links for each type you wish |
| 28 | # to monitor: |
||
| 29 | 59751681 | muffl0n | # percona_flow |
| 30 | # percona_queues |
||
| 31 | # percona_replication |
||
| 32 | # percona_transactions |
||
| 33 | # percona_transactions_bytes |
||
| 34 | # |
||
| 35 | fe864b9d | muffl0n | # Minimal config for monitoring local Percona XtraDB Cluster-Server: |
| 36 | 59751681 | muffl0n | # |
| 37 | # [percona] |
||
| 38 | # env.user root |
||
| 39 | # env.password vErYsEcReT |
||
| 40 | # |
||
| 41 | 31ee164e | Lars Kruse | # #%# capabilities=autoconf |
| 42 | # #%# family=contrib |
||
| 43 | 59751681 | muffl0n | |
| 44 | 31ee164e | Lars Kruse | import os |
| 45 | import sys |
||
| 46 | 59751681 | muffl0n | from warnings import filterwarnings |
| 47 | |||
| 48 | 31ee164e | Lars Kruse | import MySQLdb |
| 49 | import MySQLdb.cursors |
||
| 50 | |||
| 51 | filterwarnings('ignore', category=MySQLdb.Warning)
|
||
| 52 | |||
| 53 | program_name = os.path.basename(__file__) |
||
| 54 | 59751681 | muffl0n | |
| 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 | 31ee164e | Lars Kruse | if "host" in os.environ and os.environ["host"] is not None: |
| 86 | 59751681 | muffl0n | server = os.environ["host"] |
| 87 | else: |
||
| 88 | 31ee164e | Lars Kruse | server = "localhost" |
| 89 | 59751681 | muffl0n | |
| 90 | # Mysql port |
||
| 91 | 31ee164e | Lars Kruse | if "port" in os.environ and os.environ["port"] is not None: |
| 92 | 59751681 | muffl0n | try: |
| 93 | port = int(os.environ["port"]) |
||
| 94 | except ValueError: |
||
| 95 | port = 3306 |
||
| 96 | else: |
||
| 97 | port = 3306 |
||
| 98 | |||
| 99 | # Mysql username |
||
| 100 | 31ee164e | Lars Kruse | if "user" in os.environ and os.environ["user"] is not None: |
| 101 | 59751681 | muffl0n | login = os.environ["user"] |
| 102 | else: |
||
| 103 | login = "" |
||
| 104 | |||
| 105 | # Mysql password |
||
| 106 | 31ee164e | Lars Kruse | if "password" in os.environ and os.environ["password"] is not None: |
| 107 | 59751681 | muffl0n | passw = os.environ["password"] |
| 108 | else: |
||
| 109 | passw = "" |
||
| 110 | |||
| 111 | # Mysql connection handler |
||
| 112 | conn = None |
||
| 113 | |||
| 114 | 31ee164e | Lars Kruse | label = variables[program_name]['label'] |
| 115 | vlabel = variables[program_name]['vlabel'] |
||
| 116 | fields = ["'{0}'".format(x) for x in variables[program_name]['fields']]
|
||
| 117 | 59751681 | muffl0n | |
| 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 | 31ee164e | Lars Kruse | except MySQLdb.Error as e: |
| 125 | print("Error %d: %s" % (e.args[0], e.args[1]))
|
||
| 126 | 59751681 | muffl0n | sys.exit(1) |
| 127 | |||
| 128 | |||
| 129 | values = {}
|
||
| 130 | |||
| 131 | if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
||
| 132 | 31ee164e | Lars Kruse | print("yes")
|
| 133 | 59751681 | muffl0n | elif len(sys.argv) == 2 and sys.argv[1] == "config": |
| 134 | |||
| 135 | 31ee164e | Lars Kruse | print("graph_title %s" % label)
|
| 136 | print("graph_vlabel %s" % vlabel)
|
||
| 137 | print("graph_category db")
|
||
| 138 | print() |
||
| 139 | 59751681 | muffl0n | |
| 140 | try: |
||
| 141 | cursor.execute(query) |
||
| 142 | results = cursor.fetchall() |
||
| 143 | |||
| 144 | for result in results: |
||
| 145 | 31ee164e | Lars Kruse | print("%s_size.label %s" % (result[0], result[0]))
|
| 146 | 59751681 | muffl0n | |
| 147 | 31ee164e | Lars Kruse | except MySQLdb.Error as e: |
| 148 | print("Error %d: %s" % (e.args[0], e.args[1]))
|
||
| 149 | 59751681 | muffl0n | |
| 150 | else: |
||
| 151 | try: |
||
| 152 | cursor.execute(query) |
||
| 153 | results = cursor.fetchall() |
||
| 154 | |||
| 155 | for result in results: |
||
| 156 | 31ee164e | Lars Kruse | print("%s_size.value %s" % (result[0], result[1]))
|
| 157 | 59751681 | muffl0n | |
| 158 | 31ee164e | Lars Kruse | except MySQLdb.Error as e: |
| 159 | print("Error %d: %s" % (e.args[0], e.args[1]))
|
||
| 160 | 59751681 | muffl0n | |
| 161 | if conn: |
||
| 162 | conn.close() |
