Created
June 12, 2014 11:14
-
-
Save RPDiep/9815315f2b3074d419f8 to your computer and use it in GitHub Desktop.
zabbix_wsrep_stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Author: Rene Diepstraten <rene@pcextreme.nl> | |
# | |
send_items=[ | |
'wsrep_apply_oooe', | |
'wsrep_apply_oool', | |
'wsrep_apply_window', | |
'wsrep_causal_reads', | |
'wsrep_cert_index_size', | |
'wsrep_cluster_conf_id', | |
'wsrep_cluster_size', | |
'wsrep_cluster_status', | |
'wsrep_commit_oool', | |
'wsrep_commit_window', | |
'wsrep_connected', | |
'wsrep_flow_control_paused', | |
'wsrep_flow_control_paused_ns', | |
'wsrep_flow_control_recv', | |
'wsrep_flow_control_sent', | |
'wsrep_last_committed', | |
'wsrep_local_bf_aborts', | |
'wsrep_local_cached_downto', | |
'wsrep_local_cert_failures', | |
'wsrep_local_commits', | |
'wsrep_local_index', | |
'wsrep_local_recv_queue', | |
'wsrep_local_recv_queue_avg', | |
'wsrep_local_replays', | |
'wsrep_local_send_queue', | |
'wsrep_local_send_queue_avg', | |
'wsrep_local_state', | |
'wsrep_local_state_comment', | |
'wsrep_ready', | |
'wsrep_received', | |
'wsrep_received_bytes', | |
'wsrep_repl_data_bytes', | |
'wsrep_repl_keys', | |
'wsrep_repl_keys_bytes', | |
'wsrep_repl_other_bytes', | |
'wsrep_replicated', | |
'wsrep_replicated_bytes', | |
] | |
zabbixhost='zabbix' | |
zabbixsender='/usr/bin/zabbix_sender' | |
import MySQLdb, socket, subprocess, sys, tempfile | |
### http://stackoverflow.com/questions/788411/check-to-see-if-python-script-is-running ### | |
def get_lock(process_name): | |
global lock_socket | |
lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) | |
try: | |
lock_socket.bind('\0' + process_name) | |
except socket.error: | |
print 'Wsrepstats already running, exiting' | |
sys.exit(1) | |
def spawn( command ): | |
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) | |
(result, err) = p.communicate() | |
result = result.strip() | |
return result | |
get_lock('wsrepstats') | |
socket.setdefaulttimeout(5) | |
hostname=socket.getfqdn() | |
tmpfile=tempfile.NamedTemporaryFile(dir='/tmp', delete=True) | |
conn = MySQLdb.connect ( read_default_file="~/.my.cnf" ) | |
cur = conn.cursor() | |
cur.execute("SHOW GLOBAL STATUS LIKE 'wsrep%'") | |
results = cur.fetchall() | |
wsrep_info=dict(results) | |
for item in send_items: | |
try: | |
tmpfile.write("%s %s %s\n" % (hostname,item.replace('wsrep_','wsrep.'), wsrep_info[item]) ) | |
except KeyError: | |
pass | |
tmpfile.flush() | |
command="%s -z %s -s %s -i %s" % ( zabbixsender, zabbixhost, hostname, tmpfile.name ) | |
print spawn(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment