после выкапывания исходного кода драйвера MongoDB jdbc. я наконец смог получить то, что требуется. ниже - код для этого
public class MongoJmxStat {
private MongoClient mongo;
public MongoJmxStat(MongoClient mongo) {
this.mongo = mongo;
}
public CommandResult getServerStatus() {
CommandResult result = getDb("mongoDB").command("serverStatus");
if (!result.ok()) {
throw new MongoException("could not query for server status. Command Result = " + result);
}
return result;
}
public DB getDb(String databaseName) {
return MongoDbUtils.getDB(mongo, databaseName);
}
private int getOpCounter(String key) {
DBObject opCounters = (DBObject) getServerStatus().get("opcounters");
return (Integer) opCounters.get(key);
}
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Write operation count")
public int getWriteCount() {
return getOpCounter("insert") + getOpCounter("update") + getOpCounter("delete");
}
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Read operation count")
public int getReadCount() {
return getOpCounter("query") + getOpCounter("getmore");
}
}
какая проблема вы собираетесь решить? – profesor79
Посмотрите на это, некоторые команды, чтобы вернуть статистику БД: https://docs.mongodb.com/manual/administration/monitoring/ – yellowB
Является ли это скорее проблемой администрирования базы данных, чем проблемой программирования? Вы можете найти ответ, который вы хотите найти в http://dba.stackexchange.com/. –