Skip to content

Commit d6b9753

Browse files
smkniaziberthoug
authored andcommitted
[HOPSWORKS-CLOUD-1598] Added direct mem and DB utilization to HopsFS UI
1 parent 8949e27 commit d6b9753

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/main/java/io/hops/metadata/ndb/NdbStorageFactory.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,10 @@ public EntityDataAccess getDataAccess(Class type) {
159159
public boolean hasResources(double threshold) throws StorageException {
160160
return MysqlServerConnector.hasResources(threshold);
161161
}
162-
162+
163+
@Override
164+
public float getResourceMemUtilization() throws StorageException {
165+
return MysqlServerConnector.getResourceMemUtilization();
166+
}
167+
163168
}

src/main/java/io/hops/metadata/ndb/mysqlserver/MysqlServerConnector.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,24 @@ public String getClusterConnectString() {
297297
public String getDatabaseName() {
298298
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
299299
}
300-
300+
301+
public static float getResourceMemUtilization() throws StorageException {
302+
return MySQLQueryHelper.execute("SELECT memory_type, used, total FROM " +
303+
"ndbinfo.memoryusage where memory_type = \"Data memory\"",
304+
new MySQLQueryHelper.ResultSetHandler<Float>() {
305+
@Override
306+
public Float handle(ResultSet result)
307+
throws SQLException {
308+
while (result.next()) {
309+
long used = result.getLong("used");
310+
long total = result.getLong("total");
311+
return Float.valueOf((float) (((float)used / (float) total) * 100.0));
312+
}
313+
return Float.valueOf(-1);
314+
}
315+
});
316+
}
317+
301318
public static boolean hasResources(final double threshold) throws StorageException {
302319
return MySQLQueryHelper.execute("SELECT memory_type, used, total FROM " +
303320
"ndbinfo.memoryusage where memory_type = \"Data memory\"",

0 commit comments

Comments
 (0)