Skip to content

Commit

Permalink
MID-7090: GUI Info Dashboard System status panel - DB connections sta…
Browse files Browse the repository at this point in the history
…ts (#143)

* MID-7090: GUI Info Dashboard System status panel - DB connections stats added

* hopefully fixing the test
  • Loading branch information
martin-lizner committed Jul 26, 2021
1 parent daf990e commit 6dbcce4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<td><wicket:message key="SystemInfoPanel.threads"/></td>
<td><span wicket:id="threads"/></td>
</tr>
<tr>
<td><wicket:message key="SystemInfoPanel.dbPool"/></td>
<td><span wicket:id="dbPool"/></td>
</tr>
<tr>
<td><wicket:message key="SystemInfoPanel.starttime"/></td>
<td><span wicket:id="startTime"/></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SystemInfoPanel extends BasePanel<SystemInfoPanel.SystemInfoDto> {
private static final String ID_HEAP_MEMORY = "heapMemory";
private static final String ID_NON_HEAP_MEMORY = "nonHeapMemory";
private static final String ID_THREADS = "threads";
private static final String ID_DB_POOL = "dbPool";
private static final String ID_START_TIME = "startTime";
private static final String ID_UPTIME = "uptime";

Expand Down Expand Up @@ -70,12 +71,17 @@ protected SystemInfoDto load() {
} catch (Exception ex) {
LOGGER.debug("Couldn't load jmx data", ex);
}
fillDBPool(dto);

return dto;
}
};
}

private void fillDBPool(SystemInfoDto dto) {
dto.dbPool = getPageBase().getTaskManager().getDBPoolStats();
}

private void fillUptime(SystemInfoDto dto) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=Runtime");
Expand Down Expand Up @@ -148,6 +154,9 @@ private void initLayout() {
Label threads = new Label(ID_THREADS, createThreadModel());
table.add(threads);

Label dbPool = new Label(ID_DB_POOL, createDBPoolModel());
table.add(dbPool);

DateLabelComponent startTime = new DateLabelComponent(ID_START_TIME, createStartTimeModel(),
WebComponentUtil.getLongDateTimeFormat(SystemInfoPanel.this.getPageBase()));
table.add(startTime);
Expand Down Expand Up @@ -231,6 +240,28 @@ public String getObject() {
};
}

private IModel<String> createDBPoolModel() {
return () -> {
SystemInfoDto dto = getModelObject();

if (dto == null) {
return null;
}

if (dto.dbPool == null)
return "N/A";

StringBuilder sb = new StringBuilder();
sb.append(dto.dbPool[0]).append(" / ");
sb.append(dto.dbPool[1]).append(" / ");
sb.append(dto.dbPool[2]).append(" / ");
sb.append(dto.dbPool[3]).append(" / ");
sb.append(dto.dbPool[4]);

return sb.toString();
};
}

static class SystemInfoDto implements Serializable {

static final String F_CPU_USAGE = "cpuUsage";
Expand All @@ -244,6 +275,8 @@ static class SystemInfoDto implements Serializable {
Long[] nonHeapMemory = new Long[3];
//ThreadCount, PeakThreadCount, TotalStartedThreadCount
Number[] threads = new Number[3];
//Hikari pool connections active, idle, waiting, total, max-size"
Number[] dbPool = new Number[5];

long starttime = 0;
long uptime = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,5 +736,11 @@ String recordTaskThreadsDump(String taskOid, String cause, OperationResult paren
*/
void waitForTransientChildrenAndCloseThem(RunningTask task, OperationResult result);

/**
* Returns hikari pool statistics (active, idle, waiting, total, max number of DB connections)
* Return null if pool is unavailable.
*/
Number[] getDBPoolStats();

//endregion
}
4 changes: 4 additions & 0 deletions repo/task-quartz-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<!-- Testing dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.annotation.PreDestroy;

import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.repo.sqlbase.DataSourceFactory;
import com.evolveum.midpoint.task.quartzimpl.cluster.NodeRegistrar;
import com.evolveum.midpoint.task.quartzimpl.execution.*;

Expand All @@ -25,6 +26,9 @@
import com.evolveum.midpoint.task.quartzimpl.tasks.*;

import com.google.common.annotations.VisibleForTesting;
import com.zaxxer.hikari.HikariConfigMXBean;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.HikariPoolMXBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -136,6 +140,7 @@ public class TaskManagerQuartzImpl implements TaskManager, SystemConfigurationCh
@Autowired private LightweightTaskManager lightweightTaskManager;
@Autowired private TaskSynchronizer taskSynchronizer;
@Autowired private TaskBeans beans;
@Autowired(required = false) private DataSourceFactory dataSourceFactory;

@Autowired
@Qualifier("securityContextManager")
Expand Down Expand Up @@ -1206,6 +1211,26 @@ public Collection<ObjectReferenceType> getLocalNodeGroups() {
}
}

@Override
public Number[] getDBPoolStats() {

if (dataSourceFactory != null && dataSourceFactory.getDataSource() instanceof HikariDataSource) {
HikariDataSource dataSource = (HikariDataSource) dataSourceFactory.getDataSource();

if (dataSource == null)
return null;

HikariPoolMXBean pool = dataSource.getHikariPoolMXBean();
HikariConfigMXBean config = dataSource.getHikariConfigMXBean();

if (pool == null || config == null)
return null;

return new Number[]{pool.getActiveConnections(), pool.getIdleConnections(), pool.getThreadsAwaitingConnection(), pool.getTotalConnections(), config.getMaximumPoolSize()};
}
return null;
}

public TaskBeans getBeans() {
return beans;
}
Expand Down

0 comments on commit 6dbcce4

Please sign in to comment.