Example usage for com.mongodb ReplicaSetStatus toString

List of usage examples for com.mongodb ReplicaSetStatus toString

Introduction

In this page you can find the example usage for com.mongodb ReplicaSetStatus toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.ebay.cloud.cms.sysmgmt.monitor.metrics.MongoMetric.java

License:Apache License

private void snapshot() {
    MongoClient client = dataSource.getMongoInstance();

    Map<String, Object> status = new TreeMap<String, Object>();
    // update driver
    status.put(MetricConstants.MONGO_DRIVER_VERSION, client.getVersion());
    // update status
    ReplicaSetStatus rss = client.getReplicaSetStatus();

    String master = NOT_FOUND;/*  ww w .  j  a  va  2s .c  o m*/
    if (rss != null) {
        status.put(MetricConstants.REPL_STATUS, rss.toString());
        ServerAddress masterServer = rss.getMaster();
        if (masterServer != null) {
            master = masterServer.getHost();
        }
    } else {
        status.put(MetricConstants.REPL_STATUS, "no repl set found!");
    }
    // update mongo cluster master
    status.put(MetricConstants.REPL_MASTER, master);
    // list mongo databases
    Map<String, Object> databaseSizeMap = listDatabases(client);
    String databases = StringUtils.join(databaseSizeMap.keySet(), ',');
    status.put(MetricConstants.REPL_DATABASES, databases);
    status.put(MetricConstants.MONGO_DB_SIZE, databaseSizeMap);

    mongoStatus = status;
}