Skip to content

Commit

Permalink
Manage sort for stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Aug 10, 2012
1 parent 2c57472 commit 79d4385
Show file tree
Hide file tree
Showing 53 changed files with 1,024 additions and 184 deletions.
43 changes: 43 additions & 0 deletions com.mongodb.tools/src/com/mongodb/tools/driver/StatsHelper.java
@@ -0,0 +1,43 @@
package com.mongodb.tools.driver;

import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;

public class StatsHelper {

private static final String SIZE = "size";
private static final String COUNT = "count";
private static final String STORAGE = "storageSize";
private static final String AVG_OBJ = "avgObjSize";
private static final String PADDING = "paddingFactor";
private static final String INDEX_SIZES = "indexSizes";

public static double getSize(CommandResult stats) {
return stats.getDouble(SIZE);
}

public static double getCount(CommandResult stats) {
return stats.getDouble(COUNT);
}

public static double getStorage(CommandResult stats) {
return stats.getDouble(STORAGE);
}

public static double getAvgObj(CommandResult stats) {
return stats.getDouble(AVG_OBJ);
}

public static double getPadding(CommandResult stats) {
return stats.getDouble(PADDING);
}

public static BasicDBObject getIndexSizes(CommandResult stats) {
return (BasicDBObject) stats.get(INDEX_SIZES);
}

public static String formatAsBytes(double value) {
return String.valueOf(value);
}

}
Expand Up @@ -11,32 +11,55 @@ public class CollectionListStats extends ArrayList<CollectionStats> {


private double totalSize; private double totalSize;
private double totalCount; private double totalCount;
private double totalStorage;
private double totalAvgObj;
private double totalPadding;
private double totalIndexSize;


public CollectionListStats(int size) { public CollectionListStats(int size) {
super(size); super(size);
this.totalSize = 0; this.totalSize = 0;
this.totalIndexSize = 0;
} }


@Override @Override
public boolean add(CollectionStats stats) { public boolean add(CollectionStats stats) {
double size = stats.getSize(); totalSize += stats.getSize();
totalSize += size; totalCount += stats.getCount();
double count = stats.getCount(); totalStorage += stats.getStorage();
totalCount += count; totalAvgObj += stats.getAvgObj();
totalPadding += stats.getPadding();
totalIndexSize += stats.getTotalIndexSize();
return super.add(stats); return super.add(stats);
} }


public double getTotalSize() { public double getTotalSize() {
return totalSize; return totalSize;
} }


public double getTotalCount() {
return totalCount;
}

public double getTotalStorage() {
return totalStorage;
}

public double getTotalAvgObj() {
return totalAvgObj;
}

public double getTotalPadding() {
return totalPadding;
}

public double getTotalIndexSize() {
return totalIndexSize;
}

public void addCollection(Collection collection) public void addCollection(Collection collection)
throws UnknownHostException, MongoException { throws UnknownHostException, MongoException {
add(new CollectionStats(this, collection)); add(new CollectionStats(this, collection));
} }


public double getTotalCount() {
return totalCount;
}

} }
@@ -1,35 +1,76 @@
package fr.opensagres.mongodb.ide.core.model.stats; package fr.opensagres.mongodb.ide.core.model.stats;


import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Set;


import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult; import com.mongodb.CommandResult;
import com.mongodb.MongoException; import com.mongodb.MongoException;
import com.mongodb.tools.driver.StatsHelper;


import fr.opensagres.mongodb.ide.core.model.Collection; import fr.opensagres.mongodb.ide.core.model.Collection;


public class CollectionStats { public class CollectionStats extends ArrayList<IndexStats> {

public static final String NAME_PROPERTY = "name";
public static final String COUNT_PROPERTY = "count";
public static final String SIZE_PROPERTY = "size";
public static final String STORAGE_PROPERTY = "storage";
public static final String TOTAL_INDEX_SIZE_PROPERTY = "totalIndexSize";
public static final String AVGOBJ_PROPERTY = "avgObj";
public static final String PADDING_PROPERTY = "padding";


private final CollectionListStats listStats; private final CollectionListStats listStats;
private final Collection collection; private final Collection collection;
private double size;
private double count; private double count;
private double size;
private double storage;
private double totalIndexSize;
private double avgObj;
private double padding;


public CollectionStats(CollectionListStats listStats, Collection collection) public CollectionStats(CollectionListStats listStats, Collection collection)
throws UnknownHostException, MongoException { throws UnknownHostException, MongoException {
this.totalIndexSize = 0;
this.listStats = listStats; this.listStats = listStats;
this.collection = collection; this.collection = collection;
CommandResult stats = collection.getShellCommandManager() CommandResult stats = collection.getShellCommandManager()
.getDBCollectionGetStats(collection.getDBCollection()); .getDBCollectionGetStats(collection.getDBCollection());
size = stats.getDouble("size"); // Collection stats
count = stats.getDouble("count"); this.size = StatsHelper.getSize(stats);

this.count = StatsHelper.getCount(stats);
// System.err.println(stats); this.storage = StatsHelper.getStorage(stats);
this.avgObj = StatsHelper.getAvgObj(stats);
this.padding = StatsHelper.getPadding(stats);
// Indexes stats
BasicDBObject indexes = StatsHelper.getIndexSizes(stats);
Set<String> indexNames = indexes.keySet();
for (String id : indexNames) {
addIndex(id, indexes.getInt(id));
}
} }


public Collection getCollection() { public Collection getCollection() {
return collection; return collection;
} }


public String getName() {
return collection.getName();
}

public double getCount() {
return count;
}

public double getPercentCount() {
double totalCount = listStats.getTotalCount();
if (count == 0) {
return 0;
}
return (count / totalCount) * 100;
}

public double getSize() { public double getSize() {
return size; return size;
} }
Expand All @@ -42,15 +83,64 @@ public double getPercentSize() {
return (size / totalSize) * 100; return (size / totalSize) * 100;
} }


public double getCount() { public double getStorage() {
return count; return storage;
} }


public double getPercentCount() { public double getPercentStorage() {
double totalCount = listStats.getTotalCount(); double totalStorage = listStats.getTotalStorage();
if (count == 0) { if (storage == 0) {
return 0; return 0;
} }
return (size / totalCount) * 100; return (storage / totalStorage) * 100;
}

public double getAvgObj() {
return avgObj;
}

public double getPercentAvgObj() {
double totalAvgObj = listStats.getTotalAvgObj();
if (avgObj == 0) {
return 0;
}
return (avgObj / totalAvgObj) * 100;
}

public double getPadding() {
return padding;
}

public double getPercentPadding() {
double totalPadding = listStats.getTotalPadding();
if (padding == 0) {
return 0;
}
return (padding / totalPadding) * 100;
}

@Override
public boolean add(IndexStats stats) {
double size = stats.getIndexSize();
totalIndexSize += size;
return super.add(stats);
}

public double getTotalIndexSize() {
return totalIndexSize;
}

public void addIndex(String id, double indexSize)
throws UnknownHostException, MongoException {
add(new IndexStats(this, id, indexSize));
}

public CollectionListStats getListStats() {
return listStats;
}

public double getPercentIndexSize() {
double totalSize = listStats.getTotalIndexSize();
return (totalIndexSize / totalSize) * 100;
} }
} }
@@ -0,0 +1,30 @@
package fr.opensagres.mongodb.ide.core.model.stats;

public class IndexStats {

private final CollectionStats collectionStats;
private final String id;
private final double indexSize;

public IndexStats(CollectionStats collectionStats, String id, double indexSize) {
this.collectionStats = collectionStats;
this.id = id;
this.indexSize = indexSize;
}

public String getId() {
return id;
}

public double getIndexSize() {
return indexSize;
}

public double getPercentIndexSize() {
double totalSize = collectionStats.getListStats().getTotalIndexSize();
if (indexSize == 0) {
return 0;
}
return (indexSize / totalSize) * 100;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -76,19 +76,21 @@ databaseEditorOverviewShellDescription=You can connect you to Mongo console with
DatabaseEditor_OverviewPage_Shell_connection=Connection\: DatabaseEditor_OverviewPage_Shell_connection=Connection\:
databaseEditorOverviewStatsSection=Stats databaseEditorOverviewStatsSection=Stats
databaseEditorOvervieStatsDescription=Show stats of collection and indexes databaseEditorOvervieStatsDescription=Show stats of collection and indexes
DatabaseEditor_OverviewPage_DatabaseContent_title=Database content
DatabaseEditor_OverviewPage_DatabaseContent_content=<form>\
<p>The content of the Mongo database is made up of several sections:</p>\
<li style="image" value="stats_page" bindent="5"><a href="stats">Stats</a>: list of collection and indexes stats.</li>\
<li style="image" value="users_page" bindent="5"><a href="users">Users</a>: list the users.</li>\
<li style="image" value="indexes_page" bindent="5"><a href="indexes">Indexes</a>: list the indexes.</li>\
</form>
StatsPage_title=Stats StatsPage_title=Stats
UsersPage_title=Users UsersPage_title=Users
UsersEditor_UsersPage_UsersMasterDetailsBlock_title=List of users UsersEditor_UsersPage_UsersMasterDetailsBlock_title=List of users
UsersEditor_UsersPage_UsersMasterDetailsBlock_desc=Add/remove users UsersEditor_UsersPage_UsersMasterDetailsBlock_desc=Add/remove users
UserEditor_UsersPage_UserDetailsPage_title=User detail UserEditor_UsersPage_UserDetailsPage_title=User detail
UserEditor_UsersPage_UserDetailsPage_desc=Fill user UserEditor_UsersPage_UserDetailsPage_desc=Fill user
UserEditor_UsersPage_UserDetailsPage_userLabel_label=Name UserEditor_UsersPage_UserDetailsPage_userLabel_label=Name
DatabaseEditor_OverviewPage_DatabaseContent_title=Database content IndexesPage_title=Indexes
DatabaseEditor_OverviewPage_DatabaseContent_content=<form>\
<p>The content of the Mongo database is made up of several sections:</p>\
<li style="image" value="stats_page" bindent="5"><a href="stats">Stats</a>: list of collection and indexes stats.</li>\
<li style="image" value="users_page" bindent="5"><a href="users">Users</a>: list the users.</li>\
</form>


# Collection editor # Collection editor
DocumentsPage_title=Documents DocumentsPage_title=Documents
Expand All @@ -106,4 +108,8 @@ columnUsername=Username
columnReadonly=Readonly? columnReadonly=Readonly?
columnName=Name columnName=Name
columnSize=Size columnSize=Size
columnCount=Count columnCount=Count
columnStorage=Storage
columnAvgObj=AvgObj
columnPadding=Padding
columnIndexSize=Index
Binary file modified fr.opensagres.mongodb.ide.ui/icons/obj16/index.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions fr.opensagres.mongodb.ide.ui/plugin.properties
Expand Up @@ -19,8 +19,8 @@ perspectiveName=MongoDB IDE


# Views # Views
Mongo.category=MongoDB IDE Mongo.category=MongoDB IDE
ServerExplorer.name=MongoDB Explorer ServerExplorer.name=MongoDB
ShellCommandsView.name=Shell Commands. ShellCommandsView.name=Shell Commands


# Wizard # Wizard
NewServerWizard.name=New Server NewServerWizard.name=New Server
Expand Down

0 comments on commit 79d4385

Please sign in to comment.