I am fetching metrics about my mongo application and want to fetch replication oplog metrics using Mongo Java client.
From the terminal printReplicationInfo() command gives the required info. However I am not able to find it's equivalent to fetch the same data from Mongo Java client.
Some old pages claim this is not possible though Java client, wondering if the new client has any such options. Any help here would be appreciated.
Update: thanks for the suggestion, here is my attempt to fetch oplog window information:
DB db = mongoClient.getDB("local");
DBCollection collection = db.getCollection("oplog.rs");
List<DBObject> dbObjects = collection.find().sort(new
BasicDBObject("ts",-1)).toArray();
DBObject startEntry = dbObjects.get(0);
DBObject lastEntry = dbObjects.get(dbObjects.size()-1);
String startTime = (String)startEntry.get("ts");
String endTime = (String)lastEntry.get("ts");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy.MM.dd");
Date startDate = simpleDateFormat.parse(startTime);
Date endDate = simpleDateFormat.parse(endTime);
long diff = endDate.getTime() - startDate.getTime();