Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mongodb] Add metrics for fsyncLocked-ness, replset votes and vote fraction #2975

Merged
merged 3 commits into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions checks.d/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class MongoDb(AgentCheck):
"cursors.totalOpen": GAUGE,
"extra_info.heap_usage_bytes": RATE,
"extra_info.page_faults": RATE,
"fsyncLocked": GAUGE,
"globalLock.activeClients.readers": GAUGE,
"globalLock.activeClients.total": GAUGE,
"globalLock.activeClients.writers": GAUGE,
Expand Down Expand Up @@ -156,6 +157,8 @@ class MongoDb(AgentCheck):
"replSet.health": GAUGE,
"replSet.replicationLag": GAUGE,
"replSet.state": GAUGE,
"replSet.votes": GAUGE,
"replSet.voteFraction": GAUGE,
"stats.avgObjSize": GAUGE,
"stats.collections": GAUGE,
"stats.dataSize": GAUGE,
Expand Down Expand Up @@ -728,6 +731,9 @@ def total_seconds(td):
if status['ok'] == 0:
raise Exception(status['errmsg'].__str__())

ops = db['$cmd.sys.inprog'].find_one()
status['fsyncLocked'] = 1 if ops.get('fsyncLock') else 0

status['stats'] = db.command('dbstats')
dbstats = {}
dbstats[db_name] = {'stats': status['stats']}
Expand Down Expand Up @@ -789,6 +795,16 @@ def total_seconds(td):
data['health'] = current['health']

data['state'] = replSet['myState']

if current is not None:
total = 0.0
cfg = cli['local']['system.replset'].find_one()
for member in cfg.get('members'):
total += member.get('votes', 1)
if member['_id'] == current['_id']:
data['votes'] = member.get('votes', 1)
data['voteFraction'] = data['votes'] / total

status['replSet'] = data

# Submit events
Expand Down
1 change: 1 addition & 0 deletions ci/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def travis_pr?
'sysstat' => 'system',
'elastic' => 'elasticsearch',
'gearmand' => 'gearman',
'mongo' => 'mongodb',
'mcache' => 'memcache',
'php_fpm' => 'phpfpm',
'redisdb' => 'redis',
Expand Down
31 changes: 29 additions & 2 deletions tests/checks/integration/test_mongo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# stdlib
from types import ListType
import time
import unittest

# 3p
from mock import Mock
Expand Down Expand Up @@ -153,8 +152,12 @@ def test_state_translation(self):
unknown_desc = self.check.get_state_description(500)
self.assertTrue(unknown_desc.find('500') != -1)


@attr(requires='mongo')
class TestMongo(unittest.TestCase):
class TestMongo(AgentCheckTest):

CHECK_NAME = 'mongo'

def setUp(self):
server = "mongodb://localhost:%s/test" % PORT1
cli = pymongo.mongo_client.MongoClient(
Expand Down Expand Up @@ -314,3 +317,27 @@ def testMongoOldConfig(self):
metric_name = m[0]
if metric_name in metric_val_checks:
self.assertTrue(metric_val_checks[metric_name](m[2]))

def testMongoFsyncLock(self):
server = "mongodb://localhost:%s/test" % PORT1
cli = pymongo.mongo_client.MongoClient(
server,
socketTimeoutMS=30000,
read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED,)

try:
cli.fsync(lock=True)

# Run the check
config = {
'instances': [
{'server': server}
]
}
self.run_check(config)

# Assert
self.assertMetric("mongodb.fsynclocked", 1, count=1)

finally:
cli.unlock()