Search in sources :

Example 1 with DataStorageStats

use of io.lumeer.engine.api.data.DataStorageStats in project engine by Lumeer.

the class MongoDbStorage method getCollectionStats.

@Override
public DataStorageStats getCollectionStats(final String collectionName) {
    final Document collStats = database.runCommand(Document.parse("{ collStats: \"" + collectionName + "\", scale: 1, verbose: false }"));
    final DataStorageStats dss = new DataStorageStats();
    final String ns = collStats.getString("ns");
    dss.setDatabaseName(ns.substring(0, ns.indexOf(".")));
    dss.setCollectionName(ns.substring(ns.indexOf(".") + 1));
    dss.setDocuments(collStats.getInteger("count"));
    dss.setDataSize(collStats.getInteger("size"));
    dss.setStorageSize(collStats.getInteger("storageSize"));
    dss.setIndexes(collStats.getInteger("nindexes"));
    dss.setIndexSize(collStats.getInteger("totalIndexSize"));
    return dss;
}
Also used : DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) BsonDocument(org.bson.BsonDocument)

Example 2 with DataStorageStats

use of io.lumeer.engine.api.data.DataStorageStats in project engine by Lumeer.

the class MongoDbStorage method getDbStats.

@Override
public DataStorageStats getDbStats() {
    final Document dbStats = database.runCommand(Document.parse("{ dbStats: 1, scale: 1 }"));
    final DataStorageStats dss = new DataStorageStats();
    dss.setDatabaseName(dbStats.getString("db"));
    dss.setCollections(dbStats.getInteger("collections"));
    dss.setDocuments(dbStats.getInteger("objects"));
    dss.setDataSize(dbStats.getDouble("dataSize").longValue());
    dss.setStorageSize(dbStats.getDouble("storageSize").longValue());
    dss.setIndexes(dbStats.getInteger("indexes"));
    dss.setIndexSize(dbStats.getDouble("indexSize").longValue());
    return dss;
}
Also used : DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) BsonDocument(org.bson.BsonDocument)

Example 3 with DataStorageStats

use of io.lumeer.engine.api.data.DataStorageStats in project engine by Lumeer.

the class MongoDbStorageTest method collectionStatsTest.

@Test
public void collectionStatsTest() {
    mongoDbStorage.createCollection(COLLECTION_CSTATS);
    mongoDbStorage.createDocument(COLLECTION_CSTATS, new DataDocument("stats", 4));
    mongoDbStorage.createIndex(COLLECTION_CSTATS, new DataDocument("stats", 1), false);
    final DataStorageStats dss = mongoDbStorage.getCollectionStats(COLLECTION_CSTATS);
    assertThat(dss.getDatabaseName()).isEqualTo(EmbeddedMongoDb.NAME);
    assertThat(dss.getCollectionName()).isEqualTo(COLLECTION_CSTATS);
    assertThat(dss.getDocuments()).isEqualTo(1);
    assertThat(dss.getIndexes()).isEqualTo(2);
    assertThat(dss.getDataSize()).isGreaterThan(0);
    assertThat(dss.getStorageSize()).isGreaterThan(0);
    assertThat(dss.getIndexSize()).isGreaterThan(0);
    mongoDbStorage.dropCollection(COLLECTION_CSTATS);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Test(org.junit.Test)

Example 4 with DataStorageStats

use of io.lumeer.engine.api.data.DataStorageStats in project engine by Lumeer.

the class MongoDbStorageTest method dataStatsTest.

@Test
public void dataStatsTest() {
    mongoDbStorage.createCollection(COLLECTION_STATS);
    mongoDbStorage.createDocument(COLLECTION_STATS, new DataDocument("stats", 4));
    mongoDbStorage.createIndex(COLLECTION_STATS, new DataDocument("stats", 1), false);
    final DataStorageStats dss = mongoDbStorage.getDbStats();
    assertThat(dss.getDatabaseName()).isEqualTo(EmbeddedMongoDb.NAME);
    assertThat(dss.getCollections()).isGreaterThan(0);
    assertThat(dss.getDocuments()).isGreaterThan(0);
    assertThat(dss.getIndexes()).isGreaterThan(0);
    assertThat(dss.getDataSize()).isGreaterThan(0);
    assertThat(dss.getStorageSize()).isGreaterThan(0);
    assertThat(dss.getIndexSize()).isGreaterThan(0);
    mongoDbStorage.dropCollection(COLLECTION_STATS);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataStorageStats(io.lumeer.engine.api.data.DataStorageStats) Test(org.junit.Test)

Aggregations

DataDocument (io.lumeer.engine.api.data.DataDocument)4 DataStorageStats (io.lumeer.engine.api.data.DataStorageStats)4 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 BsonDocument (org.bson.BsonDocument)2 Document (org.bson.Document)2 Test (org.junit.Test)2