List of usage examples for com.mongodb CommandResult getInt
public int getInt(final String key)
From source file:com.hangum.tadpole.mongodb.core.editors.dbInfos.comosites.CollectionInformationComposite.java
License:Open Source License
/** * ?? ./*ww w . j a va2 s . c o m*/ */ public void initData(UserDBDAO userDB) { if (this.userDB == null) this.userDB = userDB; collectionList.clear(); try { DB mongoDB = MongoConnectionManager.getInstance(userDB); for (String col : mongoDB.getCollectionNames()) { CommandResult commandResult = mongoDB.getCollection(col).getStats(); //logger.debug(commandResult); MongoDBCollectionInfoDTO info = new MongoDBCollectionInfoDTO(); info.setName(col); try { info.setCount(commandResult.getInt("count")); //$NON-NLS-1$ info.setSize(commandResult.getInt("size")); //$NON-NLS-1$ info.setStorage(commandResult.getInt("storageSize")); //$NON-NLS-1$ info.setIndex(commandResult.getInt("totalIndexSize")); //$NON-NLS-1$ try { info.setAvgObj(commandResult.getDouble("avgObjSize")); //$NON-NLS-1$ } catch (NullPointerException npe) { info.setAvgObj(0); //$NON-NLS-1$ } info.setPadding(commandResult.getInt("paddingFactor")); //$NON-NLS-1$ try { info.setLastExtentSize(commandResult.getDouble("lastExtentSize")); //$NON-NLS-1$ } catch (NullPointerException npe) { info.setLastExtentSize(0); //$NON-NLS-1$ } } catch (Exception e) { logger.error("collection info error [" + col + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ } collectionList.add(info); } treeViewerCollections.setInput(collectionList); // summary . double dblSize = 0, dblStorage = 0, dblIndex = 0; for (MongoDBCollectionInfoDTO info : collectionList) { dblSize += info.getSize(); dblStorage += info.getStorage(); dblIndex += info.getIndex(); } lblCollection.setText(collectionList.size() + " Collections"); //$NON-NLS-1$ lblSizes.setText("Size " + NumberFormatUtils.kbMbFormat(dblSize)); //$NON-NLS-1$ lblStorages.setText("Storage " + NumberFormatUtils.kbMbFormat(dblStorage)); //$NON-NLS-1$ lblIndex.setText("Index " + NumberFormatUtils.kbMbFormat(dblIndex)); //$NON-NLS-1$ } catch (Exception e) { logger.error("mongodb collection infomtion init", e); //$NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError(null, "Error", "MongoDB Information", errStatus); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * collection list//from w w w. ja v a 2 s. c o m * * System collections(http://docs.mongodb.org/manual/reference/system-collections/)? collection list . * * * @param userDB * @return * @throws Exception */ public static List<TableDAO> listCollection(UserDBDAO userDB) throws Exception { List<TableDAO> listReturn = new ArrayList<TableDAO>(); DB mongoDB = MongoConnectionManager.getInstance(userDB); for (String col : mongoDB.getCollectionNames()) { if (!isSystemCollection(col)) { TableDAO dao = new TableDAO(); dao.setName(col); CommandResult commandResult = mongoDB.getCollection(col).getStats(); dao.setRows(commandResult.getLong("count")); dao.setSize(commandResult.getInt("size")); listReturn.add(dao); } } return filter(userDB, listReturn); }
From source file:DataBase.JavaMongoDB.java
oColecccion() { CommandResult aux = col.getStats(); double a = aux.getInt("size") / 1024.0 / 1024.0; return a; }
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") );//from w ww .j a v a 2s . c o m } 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())); }//from www. j a v a 2 s . c o m 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); }