{"action":"created","comment":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/51463103","id":51463103,"diff_hunk":"@@ -730,3 +733,41 @@ def check(self, instance):\n                         submit_method(self, metric_name_alias, value, tags=ns_tags)\n             except Exception, e:\n                 self.log.warning('Failed to record `top` metrics %s' % str(e))\n+\n+        # Fetch information analogous to Mongo's db.getReplicationInfo()\n+        localdb = cli['local']\n+\n+        oplog_data = {}\n+\n+        for ol_collection_name in (\"oplog.rs\", \"oplog.$main\", None):\n+            ol_metadata = localdb.system.namespaces.find_one({\"name\": \"local.%s\" % ol_collection_name})\n+            if ol_metadata is not None:\n+                break\n+\n+        if ol_collection_name is not None:\n+            try:\n+                oplog_data['totalSizeMB'] = round(ol_metadata['options']['size'] / 2.0 ** 20, 2)\n+\n+                oplog = localdb[ol_collection_name]\n+\n+                oplog_data['usedSizeMB'] = round(localdb.command(\"collstats\", ol_collection_name)['size'] / 2.0 ** 20, 2)\n+\n+                op_asc_cursor = oplog.find().sort(\"_id\", pymongo.ASCENDING).limit(1)\n+                op_dsc_cursor = oplog.find().sort(\"_id\", pymongo.DESCENDING).limit(1)\n+\n+                try:\n+                    first_timestamp = op_asc_cursor[0]['ts'].as_datetime()\n+                    last_timestamp = op_dsc_cursor[0]['ts'].as_datetime()\n+                    oplog_data['timeDiffSeconds'] = (last_timestamp - first_timestamp).total_seconds()","path":"checks.d/mongo.py","position":39,"original_position":39,"commit_id":"0217db220ddfd4eb730d67188391a8fce0f7a524","original_commit_id":"0217db220ddfd4eb730d67188391a8fce0f7a524","user":{"login":"olivielpeau","id":4912500,"avatar_url":"https://avatars.githubusercontent.com/u/4912500?v=3","gravatar_id":"","url":"https://api.github.com/users/olivielpeau","html_url":"https://github.com/olivielpeau","followers_url":"https://api.github.com/users/olivielpeau/followers","following_url":"https://api.github.com/users/olivielpeau/following{/other_user}","gists_url":"https://api.github.com/users/olivielpeau/gists{/gist_id}","starred_url":"https://api.github.com/users/olivielpeau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olivielpeau/subscriptions","organizations_url":"https://api.github.com/users/olivielpeau/orgs","repos_url":"https://api.github.com/users/olivielpeau/repos","events_url":"https://api.github.com/users/olivielpeau/events{/privacy}","received_events_url":"https://api.github.com/users/olivielpeau/received_events","type":"User","site_admin":false},"body":"I'd go with breaking that out into a separate function, duplicating the code here wouldn't be justified IMO.\r\n\r\nThanks!","created_at":"2016-02-01T18:59:36Z","updated_at":"2016-02-01T18:59:36Z","html_url":"https://github.com/DataDog/dd-agent/pull/2237#discussion_r51463103","pull_request_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237","_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/51463103"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/2237#discussion_r51463103"},"pull_request":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237"}}},"pull_request":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237","id":57712849,"html_url":"https://github.com/DataDog/dd-agent/pull/2237","diff_url":"https://github.com/DataDog/dd-agent/pull/2237.diff","patch_url":"https://github.com/DataDog/dd-agent/pull/2237.patch","issue_url":"https://api.github.com/repos/DataDog/dd-agent/issues/2237","number":2237,"state":"open","locked":false,"title":"[mongo] oplog replicationInfo metrics","user":{"login":"rhwlo","id":315383,"avatar_url":"https://avatars.githubusercontent.com/u/315383?v=3","gravatar_id":"","url":"https://api.github.com/users/rhwlo","html_url":"https://github.com/rhwlo","followers_url":"https://api.github.com/users/rhwlo/followers","following_url":"https://api.github.com/users/rhwlo/following{/other_user}","gists_url":"https://api.github.com/users/rhwlo/gists{/gist_id}","starred_url":"https://api.github.com/users/rhwlo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhwlo/subscriptions","organizations_url":"https://api.github.com/users/rhwlo/orgs","repos_url":"https://api.github.com/users/rhwlo/repos","events_url":"https://api.github.com/users/rhwlo/events{/privacy}","received_events_url":"https://api.github.com/users/rhwlo/received_events","type":"User","site_admin":false},"body":"# What’s this PR do?\r\n\r\nThis PR adds a few new metrics to dd-agent's mongo plugin, borrowed from [Mongo's db.getReplicationInfo()][0]:\r\n\r\n* [`mongodb.oplog.totalsizemb`][1]\r\n* [`mongodb.oplog.usedsizemb`][2]\r\n* [`mongodb.oplog.timediffseconds`][3]\r\n\r\n# Notes\r\n\r\nThe code for getting the metrics is a more-or-less direct translation from the Javascript `getReplicationInfo()` function from the mongo shell, with a few edits to exclude non-numerical fields. I also updated the metric names to include units where the mongo shell function didn’t.\r\n\r\n[0]: https://docs.mongodb.org/v3.2/reference/method/db.getReplicationInfo/\r\n[1]: https://docs.mongodb.org/v3.2/reference/method/db.getReplicationInfo/#db.getReplicationInfo.logSizeMB\r\n[2]: https://docs.mongodb.org/v3.2/reference/method/db.getReplicationInfo/#db.getReplicationInfo.usedMB\r\n[3]: https://docs.mongodb.org/v3.2/reference/method/db.getReplicationInfo/#db.getReplicationInfo.timeDiff","created_at":"2016-01-29T22:37:56Z","updated_at":"2016-02-01T18:59:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5a1c082420f7a44e9fa2382731b3c035b05bba6","assignee":null,"milestone":{"url":"https://api.github.com/repos/DataDog/dd-agent/milestones/62","html_url":"https://github.com/DataDog/dd-agent/milestones/Triage","labels_url":"https://api.github.com/repos/DataDog/dd-agent/milestones/62/labels","id":1485890,"number":62,"title":"Triage","description":null,"creator":{"login":"remh","id":1311477,"avatar_url":"https://avatars.githubusercontent.com/u/1311477?v=3","gravatar_id":"","url":"https://api.github.com/users/remh","html_url":"https://github.com/remh","followers_url":"https://api.github.com/users/remh/followers","following_url":"https://api.github.com/users/remh/following{/other_user}","gists_url":"https://api.github.com/users/remh/gists{/gist_id}","starred_url":"https://api.github.com/users/remh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remh/subscriptions","organizations_url":"https://api.github.com/users/remh/orgs","repos_url":"https://api.github.com/users/remh/repos","events_url":"https://api.github.com/users/remh/events{/privacy}","received_events_url":"https://api.github.com/users/remh/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":2,"state":"open","created_at":"2016-01-05T21:06:49Z","updated_at":"2016-02-01T18:45:36Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237/commits","review_comments_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237/comments","review_comment_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/issues/2237/comments","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/0217db220ddfd4eb730d67188391a8fce0f7a524","head":{"label":"stripe:add-mongodb-oplog-info","ref":"add-mongodb-oplog-info","sha":"0217db220ddfd4eb730d67188391a8fce0f7a524","user":{"login":"stripe","id":856813,"avatar_url":"https://avatars.githubusercontent.com/u/856813?v=3","gravatar_id":"","url":"https://api.github.com/users/stripe","html_url":"https://github.com/stripe","followers_url":"https://api.github.com/users/stripe/followers","following_url":"https://api.github.com/users/stripe/following{/other_user}","gists_url":"https://api.github.com/users/stripe/gists{/gist_id}","starred_url":"https://api.github.com/users/stripe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stripe/subscriptions","organizations_url":"https://api.github.com/users/stripe/orgs","repos_url":"https://api.github.com/users/stripe/repos","events_url":"https://api.github.com/users/stripe/events{/privacy}","received_events_url":"https://api.github.com/users/stripe/received_events","type":"Organization","site_admin":false},"repo":{"id":50688734,"name":"dd-agent","full_name":"stripe/dd-agent","owner":{"login":"stripe","id":856813,"avatar_url":"https://avatars.githubusercontent.com/u/856813?v=3","gravatar_id":"","url":"https://api.github.com/users/stripe","html_url":"https://github.com/stripe","followers_url":"https://api.github.com/users/stripe/followers","following_url":"https://api.github.com/users/stripe/following{/other_user}","gists_url":"https://api.github.com/users/stripe/gists{/gist_id}","starred_url":"https://api.github.com/users/stripe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stripe/subscriptions","organizations_url":"https://api.github.com/users/stripe/orgs","repos_url":"https://api.github.com/users/stripe/repos","events_url":"https://api.github.com/users/stripe/events{/privacy}","received_events_url":"https://api.github.com/users/stripe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stripe/dd-agent","description":"Datadog Agent","fork":true,"url":"https://api.github.com/repos/stripe/dd-agent","forks_url":"https://api.github.com/repos/stripe/dd-agent/forks","keys_url":"https://api.github.com/repos/stripe/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stripe/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stripe/dd-agent/teams","hooks_url":"https://api.github.com/repos/stripe/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/stripe/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/stripe/dd-agent/events","assignees_url":"https://api.github.com/repos/stripe/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/stripe/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/stripe/dd-agent/tags","blobs_url":"https://api.github.com/repos/stripe/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stripe/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stripe/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/stripe/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stripe/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/stripe/dd-agent/languages","stargazers_url":"https://api.github.com/repos/stripe/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/stripe/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/stripe/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/stripe/dd-agent/subscription","commits_url":"https://api.github.com/repos/stripe/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/stripe/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/stripe/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/stripe/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/stripe/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/stripe/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stripe/dd-agent/merges","archive_url":"https://api.github.com/repos/stripe/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stripe/dd-agent/downloads","issues_url":"https://api.github.com/repos/stripe/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/stripe/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/stripe/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/stripe/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stripe/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/stripe/dd-agent/releases{/id}","deployments_url":"https://api.github.com/repos/stripe/dd-agent/deployments","created_at":"2016-01-29T20:17:49Z","updated_at":"2016-01-29T20:17:51Z","pushed_at":"2016-01-29T22:38:37Z","git_url":"git://github.com/stripe/dd-agent.git","ssh_url":"git@github.com:stripe/dd-agent.git","clone_url":"https://github.com/stripe/dd-agent.git","svn_url":"https://github.com/stripe/dd-agent","homepage":"http://docs.datadoghq.com/","size":30922,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"DataDog:master","ref":"master","sha":"f599428882da85bae85ef4fff2ef3cbcf995d3fa","user":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":1210071,"name":"dd-agent","full_name":"DataDog/dd-agent","owner":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/dd-agent","description":"Datadog Agent","fork":false,"url":"https://api.github.com/repos/DataDog/dd-agent","forks_url":"https://api.github.com/repos/DataDog/dd-agent/forks","keys_url":"https://api.github.com/repos/DataDog/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-agent/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-agent/events","assignees_url":"https://api.github.com/repos/DataDog/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-agent/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-agent/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-agent/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-agent/merges","archive_url":"https://api.github.com/repos/DataDog/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-agent/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-agent/releases{/id}","deployments_url":"https://api.github.com/repos/DataDog/dd-agent/deployments","created_at":"2010-12-31T03:02:47Z","updated_at":"2016-02-01T05:15:17Z","pushed_at":"2016-02-01T18:44:47Z","git_url":"git://github.com/DataDog/dd-agent.git","ssh_url":"git@github.com:DataDog/dd-agent.git","clone_url":"https://github.com/DataDog/dd-agent.git","svn_url":"https://github.com/DataDog/dd-agent","homepage":"http://docs.datadoghq.com/","size":33183,"stargazers_count":419,"watchers_count":419,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":380,"mirror_url":null,"open_issues_count":133,"forks":380,"open_issues":133,"watchers":419,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/2237"},"issue":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/2237"},"comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/2237/comments"},"review_comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237/comments"},"review_comment":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/2237/commits"},"statuses":{"href":"https://api.github.com/repos/DataDog/dd-agent/statuses/0217db220ddfd4eb730d67188391a8fce0f7a524"}}}}