Last active
August 29, 2015 14:09
-
-
Save gswallow/772055ad4707a92f0aea to your computer and use it in GitHub Desktop.
Get the current MongoDB oplog time
This file contains hidden or 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/env ruby | |
require 'mongo' | |
require 'orderedhash' | |
include Mongo | |
c = MongoClient.new('localhost').db('admin') | |
def getReplSetStatus(c) | |
cmd = OrderedHash.new | |
cmd['replSetGetStatus'] = 1 | |
begin | |
c.command(cmd) | |
rescue | |
nil | |
end | |
end | |
status = getReplSetStatus(c) | |
unless status.nil? | |
hostname = `hostname -f`.strip | |
me = status['members'].select { |m| m['name'] =~ /#{hostname}/ }.first | |
puts me['optime'].seconds | |
puts me['optime'].increment | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment