Skip to content

Instantly share code, notes, and snippets.

@gswallow
Last active August 29, 2015 14:09
Show Gist options
  • Save gswallow/772055ad4707a92f0aea to your computer and use it in GitHub Desktop.
Save gswallow/772055ad4707a92f0aea to your computer and use it in GitHub Desktop.
Get the current MongoDB oplog time
#!/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