//Yes this is a hack, but there is no other way to insert
//CSS in the correct spot
html.style(".metrics {margin-bottom:5px}");
ResourceScheduler rs = rm.getResourceScheduler();
QueueMetrics metrics = rs.getRootQueueMetrics();
ClusterMetrics clusterMetrics = ClusterMetrics.getMetrics();
int appsSubmitted = metrics.getAppsSubmitted();
int reservedGB = metrics.getReservedGB();
int availableGB = metrics.getAvailableGB();
int allocatedGB = metrics.getAllocatedGB();
int containersAllocated = metrics.getAllocatedContainers();
int totalGB = availableGB + reservedGB + allocatedGB;
int totalNodes = clusterMetrics.getNumNMs();
int lostNodes = clusterMetrics.getNumLostNMs();
int unhealthyNodes = clusterMetrics.getUnhealthyNMs();
int decommissionedNodes = clusterMetrics.getNumDecommisionedNMs();
int rebootedNodes = clusterMetrics.getNumRebootedNMs();
DIV<Hamlet> div = html.div().$class("metrics");
div.table("#metricsoverview").
thead().$class("ui-widget-header").
tr().
th().$class("ui-state-default")._("Apps Submitted")._().
th().$class("ui-state-default")._("Containers Running")._().
th().$class("ui-state-default")._("Memory Used")._().
th().$class("ui-state-default")._("Memopry Total")._().
th().$class("ui-state-default")._("Memory Reserved")._().
th().$class("ui-state-default")._("Total Nodes")._().
th().$class("ui-state-default")._("Decommissioned Nodes")._().
th().$class("ui-state-default")._("Lost Nodes")._().
th().$class("ui-state-default")._("Unhealthy Nodes")._().
th().$class("ui-state-default")._("Rebooted Nodes")._().
_().
_().
tbody().$class("ui-widget-content").
tr().
td(String.valueOf(appsSubmitted)).
td(String.valueOf(containersAllocated)).
td(StringUtils.byteDesc(allocatedGB * BYTES_IN_GB)).
td(StringUtils.byteDesc(totalGB * BYTES_IN_GB)).
td(StringUtils.byteDesc(reservedGB * BYTES_IN_GB)).
td().a(url("nodes"),String.valueOf(totalNodes))._().
td().a(url("nodes/decommissioned"),String.valueOf(decommissionedNodes))._().
td().a(url("nodes/lost"),String.valueOf(lostNodes))._().
td().a(url("nodes/unhealthy"),String.valueOf(unhealthyNodes))._().
td().a(url("nodes/rebooted"),String.valueOf(rebootedNodes))._().
_().
_()._();
String user = request().getRemoteUser();
if (user != null) {
QueueMetrics userMetrics = metrics.getUserMetrics(user);
if(userMetrics != null) {
int myAppsSubmitted = userMetrics.getAppsSubmitted();
int myRunningContainers = userMetrics.getAllocatedContainers();
int myPendingContainers = userMetrics.getPendingContainers();
int myReservedContainers = userMetrics.getReservedContainers();
int myReservedGB = userMetrics.getReservedGB();
int myPendingGB = userMetrics.getPendingGB();
int myAllocatedGB = userMetrics.getAllocatedGB();
div.table("#usermetricsoverview").
thead().$class("ui-widget-header").
tr().
th().$class("ui-state-default")._("Apps Submitted ("+user+")")._().
th().$class("ui-state-default")._("Containers Running ("+user+")")._().