Example usage for com.mongodb CommandResult getString

List of usage examples for com.mongodb CommandResult getString

Introduction

In this page you can find the example usage for com.mongodb CommandResult getString.

Prototype

public String getString(final String key) 

Source Link

Document

Returns the value of a field as a string

Usage

From source file:de.uni_koeln.spinfo.maalr.mongo.core.Database.java

License:Apache License

public DatabaseStatistics getStatistics() {
    DatabaseStatistics stats = new DatabaseStatistics();
    stats.setNumberOfEntries((int) entryCollection.getCount());
    Map<Verification, Integer> count = new HashMap<Verification, Integer>();
    DBCursor cursor = entryCollection.find();
    int entryCount = 0, lemmaCount = 0;
    Verification[] values = Verification.values();
    for (Verification verification : values) {
        count.put(verification, 0);/*  w  w  w .  j av a2 s .  co  m*/
    }
    count.put(null, 0);
    while (cursor.hasNext()) {
        LexEntry entry = Converter.convertToLexEntry(cursor.next());
        List<LemmaVersion> history = entry.getVersionHistory();
        entryCount++;
        lemmaCount += history.size();
        for (LemmaVersion lemma : history) {
            Integer old = count.get(lemma.getVerification());
            count.put(lemma.getVerification(), old + 1);
        }
    }
    stats.setNumberOfApproved(count.get(Verification.ACCEPTED));
    stats.setNumberOfSuggestions(count.get(Verification.UNVERIFIED));
    stats.setNumberOfDeleted(count.get(Verification.REJECTED));
    stats.setNumberOfOutdated(count.get(Verification.OUTDATED));
    stats.setNumberOfUndefined(count.get(null));
    stats.setNumberOfEntries(entryCount);
    stats.setNumberOfLemmata(lemmaCount);
    /*
     * TODO: - Create a separate "System/Diagnostics"-Tab, containing a)
     * general information about - RAM - Free Disk Space - CPU - Network b)
     * DB-Statistics - general - entries - users
     * 
     * Check if this will work with sigar:
     * 
     * 
     * 
     * - Add green and red 'lamps' to each entry, each sub-statistic
     * (entries, users, general) - Add one lamp to the navigation bar, to
     * summarize the server state: should always be green.
     */

    CommandResult dbStats = entryCollection.getDB().getStats();

    NumberFormat nf = NumberFormat.getInstance();
    stats.addDBProperty("Server", dbStats.getString("serverUsed"));

    Double serverStatus = dbStats.getDouble("ok");
    if (Double.compare(1D, serverStatus) == 0) {
        stats.addDBProperty("Server Status", "ok");
    } else {
        stats.addDBProperty("Server Status", "not ok: " + serverStatus, Category.ERROR);
    }

    long collections = dbStats.getLong("collections");
    if (collections == 0) {
        stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections")), Category.ERROR);
    } else {
        stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections")));
    }
    stats.addDBProperty("Number of Indexes", nf.format(dbStats.getLong("indexes")));
    stats.addDBProperty("Average Object Size", nf.format(dbStats.getDouble("avgObjSize") / 1024) + " KB");
    stats.addDBProperty("Data Size", nf.format(dbStats.getLong("dataSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("Storage Size", nf.format(dbStats.getLong("storageSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("Index Size", nf.format(dbStats.getLong("indexSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("File Size", nf.format(dbStats.getLong("fileSize") / (1024 * 1024)) + " MB");

    BasicDBObject query;
    BasicDBList attributes;
    query = new BasicDBObject();
    attributes = new BasicDBList();
    DBObject lemmata = new BasicDBObject();
    lemmata.put(QUERY_VERSION_TIMESTAMP, new BasicDBObject("$gt", -1));
    attributes.add(lemmata);
    query.append("$and", attributes);
    // stats.setNumberOfLemmata((int) entryCollection.count(query));

    return stats;
}

From source file:it.tai.repository.MongoHealthIndicator.java

License:Apache License

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    CommandResult result = this.mongoTemplate.executeCommand("{ buildInfo: 1 }");
    builder.up().withDetail("version", result.getString("version"));
}

From source file:org.dizitart.no2.datagate.services.ReplicaStoreService.java

License:Apache License

public String getStoreVersion() {
    CommandResult buildInfo = jongo.getDatabase().command("buildInfo");
    return buildInfo.getString("version");
}

From source file:org.graylog2.system.stats.mongo.MongoProbe.java

License:Open Source License

private BuildInfo createBuildInfo() {
    final BuildInfo buildInfo;
    final CommandResult buildInfoResult = adminDb.command("buildInfo");
    if (buildInfoResult.ok()) {
        buildInfo = BuildInfo.create(buildInfoResult.getString("version"),
                buildInfoResult.getString("gitVersion"), buildInfoResult.getString("sysInfo"),
                buildInfoResult.getString("loaderFlags"), buildInfoResult.getString("compilerFlags"),
                buildInfoResult.getString("allocator"), (List<Integer>) buildInfoResult.get("versionArray"),
                buildInfoResult.getString("javascriptEngine"), buildInfoResult.getInt("bits"),
                buildInfoResult.getBoolean("debug"), buildInfoResult.getLong("maxBsonObjectSize")

        );/*  w w w .j a  v a  2s .c om*/
    } else {
        buildInfo = null;
    }

    return buildInfo;
}

From source file:org.graylog2.system.stats.mongo.MongoProbe.java

License:Open Source License

public MongoStats mongoStats() {
    final List<ServerAddress> serverAddresses = mongoClient.getServerAddressList();
    final List<HostAndPort> servers = Lists.newArrayListWithCapacity(serverAddresses.size());
    for (ServerAddress serverAddress : serverAddresses) {
        servers.add(HostAndPort.fromParts(serverAddress.getHost(), serverAddress.getPort()));
    }//w  w  w.  j  a  v  a 2 s .c om

    final DatabaseStats dbStats;
    final CommandResult dbStatsResult = db.command("dbStats");
    if (dbStatsResult.ok()) {
        final BasicDBObject extentFreeListMap = (BasicDBObject) dbStatsResult.get("extentFreeList");
        final DatabaseStats.ExtentFreeList extentFreeList = DatabaseStats.ExtentFreeList
                .create(extentFreeListMap.getInt("num"), extentFreeListMap.getInt("totalSize"));

        final BasicDBObject dataFileVersionMap = (BasicDBObject) dbStatsResult.get("dataFileVersion");
        final DatabaseStats.DataFileVersion dataFileVersion = DatabaseStats.DataFileVersion
                .create(dataFileVersionMap.getInt("major"), dataFileVersionMap.getInt("minor"));

        dbStats = DatabaseStats.create(dbStatsResult.getString("db"), dbStatsResult.getLong("collections"),
                dbStatsResult.getLong("objects"), dbStatsResult.getDouble("avgObjSize"),
                dbStatsResult.getLong("dataSize"), dbStatsResult.getLong("storageSize"),
                dbStatsResult.getLong("numExtents"), dbStatsResult.getLong("indexes"),
                dbStatsResult.getLong("indexSize"), dbStatsResult.getLong("fileSize"),
                dbStatsResult.getLong("nsSizeMB"), extentFreeList, dataFileVersion);
    } else {
        dbStats = null;
    }

    final ServerStatus serverStatus;
    final CommandResult serverStatusResult = adminDb.command("serverStatus");
    if (serverStatusResult.ok()) {
        final BasicDBObject connectionsMap = (BasicDBObject) serverStatusResult.get("connections");
        final ServerStatus.Connections connections = ServerStatus.Connections.create(
                connectionsMap.getInt("current"), connectionsMap.getInt("available"),
                connectionsMap.getLong("totalCreated"));

        final BasicDBObject networkMap = (BasicDBObject) serverStatusResult.get("network");
        final ServerStatus.Network network = ServerStatus.Network.create(networkMap.getInt("bytesIn"),
                networkMap.getInt("bytesOut"), networkMap.getInt("numRequests"));

        final BasicDBObject memoryMap = (BasicDBObject) serverStatusResult.get("mem");
        final ServerStatus.Memory memory = ServerStatus.Memory.create(memoryMap.getInt("bits"),
                memoryMap.getInt("resident"), memoryMap.getInt("virtual"), memoryMap.getBoolean("supported"),
                memoryMap.getInt("mapped"), memoryMap.getInt("mappedWithJournal"));

        serverStatus = ServerStatus.create(serverStatusResult.getString("host"),
                serverStatusResult.getString("version"), serverStatusResult.getString("process"),
                serverStatusResult.getLong("pid"), serverStatusResult.getInt("uptime"),
                serverStatusResult.getLong("uptimeMillis"), serverStatusResult.getInt("uptimeEstimate"),
                new DateTime(serverStatusResult.getDate("localTime")), connections, network, memory);
    } else {
        serverStatus = null;
    }

    // TODO Collection stats? http://docs.mongodb.org/manual/reference/command/collStats/

    return MongoStats.create(servers, buildInfo, hostInfo, serverStatus, dbStats);
}