mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
76 lines
2.3 KiB
Plaintext
76 lines
2.3 KiB
Plaintext
|
#!/usr/bin/env python
|
||
|
"""
|
||
|
MongoDB Replication Lag
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
|
||
|
Connects to a single mongo instance and retrieve
|
||
|
replication lag for all connected members.
|
||
|
|
||
|
munin-node.conf:
|
||
|
[mongodb_lag]
|
||
|
env.host 127.0.0.1
|
||
|
env.port 27017
|
||
|
|
||
|
:author: Stefan Andersen <stefan@stefanandersen.dk>
|
||
|
:license: The Beer Ware License (Revision 42)
|
||
|
<stefan@stefanandersen.dk> wrote this file. As long
|
||
|
as you retain this notice you can do whatever you want
|
||
|
with this stuff. If we meet some day, and you think
|
||
|
this stuff is worth it, you can buy me a beer in return.
|
||
|
"""
|
||
|
import os
|
||
|
import sys
|
||
|
import pymongo
|
||
|
|
||
|
def _get_members():
|
||
|
host = os.environ.get('host', '127.0.0.1')
|
||
|
port = os.environ.get('port', 27017)
|
||
|
conn = pymongo.Connection(host)
|
||
|
repl_status = conn.admin.command("replSetGetStatus")
|
||
|
|
||
|
members = {}
|
||
|
for member in repl_status['members']:
|
||
|
name = member['name'].split('.')[0]
|
||
|
members[name] = {'state': member['state'], 'optimeDate': member['optimeDate']}
|
||
|
return members
|
||
|
|
||
|
def run():
|
||
|
members = _get_members();
|
||
|
for member in members:
|
||
|
if members[member]['state'] == 1:
|
||
|
primary_optime = members[member]['optimeDate']
|
||
|
|
||
|
for member in members:
|
||
|
members[member]['lag'] = (primary_optime - members[member]['optimeDate']).seconds
|
||
|
|
||
|
print "multigraph mongodb_replication_lag"
|
||
|
for member in members:
|
||
|
print "{}_lag.value {}".format(member, members[member]['lag'])
|
||
|
print
|
||
|
|
||
|
for member in members:
|
||
|
print "multigraph mongodb_replication_lag.{}".format(member)
|
||
|
print "lag.value {}".format(members[member]['lag'])
|
||
|
print
|
||
|
|
||
|
def config():
|
||
|
print """graph_title MongoDB replication lag
|
||
|
graph_args --base 1000
|
||
|
graph_vlabel Replication lag (seconds)
|
||
|
graph_category MongoDB
|
||
|
"""
|
||
|
|
||
|
for member in _get_members():
|
||
|
print "{0}_lag.label {0}".format(member)
|
||
|
print "{}_lag.type GAUGE".format(member)
|
||
|
print "{}_lag.info Replication lag behind master".format(member)
|
||
|
print "{}_lag.min 0".format(member)
|
||
|
print "{}_lag.draw LINE1".format(member)
|
||
|
print
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
if len(sys.argv) > 1 and sys.argv[1] == "config":
|
||
|
config()
|
||
|
else:
|
||
|
run()
|