Skip to content

Commit

Permalink
more system info on widget
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 28, 2015
1 parent 9b1ea95 commit 2160dfe
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gui/admin-gui/pom.xml
Expand Up @@ -453,6 +453,12 @@
<artifactId>wicket-datetime</artifactId>
</dependency>

<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>4.0.0.Final</version>
</dependency>

<!-- Xtext DSL
<dependency>
<groupId>com.evolveum.midpoint.msl</groupId>
Expand Down
Expand Up @@ -34,6 +34,14 @@
<td><wicket:message key="SystemInfoPanel.threads"/></td>
<td><span wicket:id="threads"/></td>
</tr>
<tr>
<td><wicket:message key="SystemInfoPanel.starttime"/></td>
<td><span wicket:id="startTime"/></td>
</tr>
<tr>
<td><wicket:message key="SystemInfoPanel.uptime"/></td>
<td><span wicket:id="uptime"/></td>
</tr>
</table>
</wicket:panel>
</html>
Expand Up @@ -30,6 +30,7 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.time.Duration;
import org.ocpsoft.prettytime.PrettyTime;

import javax.management.Attribute;
import javax.management.AttributeList;
Expand All @@ -38,6 +39,8 @@
import javax.management.openmbean.CompositeData;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

Expand All @@ -53,6 +56,8 @@ public class SystemInfoPanel extends SimplePanel<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_START_TIME = "startTime";
private static final String ID_UPTIME = "uptime";

public SystemInfoPanel(String id) {
super(id);
Expand All @@ -69,6 +74,7 @@ protected SystemInfoDto load() {
fillCpuUsage(dto);
fillMemoryUsage(dto);
fillThreads(dto);
fillUptime(dto);
} catch (Exception ex) {
LOGGER.debug("Couldn't load jmx data", ex);
}
Expand All @@ -78,6 +84,14 @@ protected SystemInfoDto load() {
};
}

private void fillUptime(SystemInfoDto dto) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=Runtime");

dto.uptime = (long) mbs.getAttribute(name, "Uptime");
dto.starttime = (long) mbs.getAttribute(name, "StartTime");
}

private void fillCpuUsage(SystemInfoDto dto) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
Expand Down Expand Up @@ -142,6 +156,42 @@ protected void initLayout() {

Label threads = new Label(ID_THREADS, createThreadModel());
table.add(threads);

Label startTime = new Label(ID_START_TIME, createStartTimeModel());
table.add(startTime);

Label uptime = new Label(ID_UPTIME, createUptimeModel());
table.add(uptime);
}

private IModel<String> createUptimeModel() {
return new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
SystemInfoDto dto = getModelObject();

PrettyTime time = new PrettyTime();
return time.format(new Date(System.currentTimeMillis() - dto.uptime));
}
};
}

private IModel<String> createStartTimeModel() {
return new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
SystemInfoDto dto = getModelObject();

if (dto.starttime == 0) {
return null;
}

SimpleDateFormat df = new SimpleDateFormat();
return df.format(new Date(dto.starttime));
}
};
}

private IModel<String> createMemoryModel(final boolean heap) {
Expand Down Expand Up @@ -192,5 +242,8 @@ static class SystemInfoDto implements Serializable {
Long[] nonHeapMemory = new Long[3];
//ThreadCount, PeakThreadCount, TotalStartedThreadCount
Number[] threads = new Number[3];

long starttime = 0;
long uptime = 0;
}
}
Expand Up @@ -2717,4 +2717,6 @@ PageTemplate.version=Version:
PageTemplate.copy=<strong>Copyright &copy; 2010-2015 <a href="https://www.evolveum.com/">Evolveum</a> and partners.</strong> Thank you for using <a href="http://midpoint.evolveum.com">midPoint</a>
PageTemplate.toggleNavigation=Toggle navigation
PageTemplate.user=user
PageTemplate.couldntNavigateBreadcrumb=Couldn't navigate breadcrumb, reason: {0}
PageTemplate.couldntNavigateBreadcrumb=Couldn't navigate breadcrumb, reason: {0}
SystemInfoPanel.starttime=Start time
SystemInfoPanel.uptime=Uptime

0 comments on commit 2160dfe

Please sign in to comment.