Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
HAL-354: display jvm uptime on jvm rutime view
Browse files Browse the repository at this point in the history
added *~ to .gitignore
added note to README related to firefox version and gwt plugin
  • Loading branch information
claudio4j committed Sep 4, 2014
1 parent 37be289 commit 5e887b3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ gwt-unitCache
.settings
.project
.classpath
*.*~

build/app/overlays
build/app/war
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ and verify changes. You can get the OOPHM Plugin, required for attaching your br
hosted mode execution here: http://gwt.google.com/samples/MissingPlugin/MissingPlugin.html

NOTE: you need to add user with WildFly add-user script.
NOTE2: firefox on linux should use version 24 or minor, because gwt plugin doesn't work with recent firefox versions.

## Running in web mode

Expand Down
@@ -1,15 +1,5 @@
package org.jboss.as.console.client.standalone.runtime;

import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.SuspendableViewImpl;
import org.jboss.as.console.client.shared.jvm.model.OSMetric;
import org.jboss.as.console.client.shared.jvm.model.RuntimeMetric;
Expand All @@ -19,8 +9,16 @@
import org.jboss.as.console.client.shared.runtime.vm.VMMetricsManagement;
import org.jboss.ballroom.client.widgets.ContentHeaderLabel;
import org.jboss.ballroom.client.widgets.tabs.FakeTabPanel;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;

import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* @author Heiko Braun
Expand All @@ -40,7 +38,7 @@ public class VMMetricsView extends SuspendableViewImpl implements VMMetricsPrese

private HTML osName;
private HTML processors;
private ToolButton pauseBtn;
private HTML uptime;

protected boolean hasServerPicker = false;

Expand Down Expand Up @@ -80,19 +78,23 @@ public void onClick(ClickEvent event) {

osName = new HTML();
processors = new HTML();
uptime = new HTML();

HorizontalPanel header = new HorizontalPanel();
header.setStyleName("fill-layout-width");
vmName = new ContentHeaderLabel("");
header.add(vmName);


HTML refreshBtn = new HTML("<i class='icon-refresh'></i> Refresh Results");
refreshBtn.setStyleName("html-link");
refreshBtn.addClickHandler(refreshHandler);

osPanel = new VerticalPanel();
osPanel.add(refreshBtn);
osPanel.add(osName);
osPanel.add(processors);
osPanel.add(uptime);

header.add(osPanel);

vpanel.add(header);
Expand Down Expand Up @@ -154,6 +156,47 @@ public void setThreads(Metric metric) {
@Override
public void setRuntimeMetric(RuntimeMetric runtime) {
vmName.setText(runtime.getVmName());
uptime.setHTML("<b style='color:#A7ABB4'>JVM Uptime:</b> " + humanReadable(runtime.getUptime()));
}

/*
* Converts the long uptime to an human readable format, examples:
* 2 d, 0 hour, 34 min, 2s
* 12 hours, 12 min, 22s
*
*/
private String humanReadable(long uptime) {
uptime = uptime / 1000;

int sec = (int) uptime % 60;
uptime /= 60;

int min = (int) uptime % 60;
uptime /= 60;

int hour = (int) uptime % 24;
uptime /= 24;

int day = (int) uptime;

String str = "";
if (day > 0)
if (day > 1)
str += day + " days, ";
else
str += day + " day, ";
// prints 0 hour in case days exists. Otherwise prints 2 days, 34 min, sounds weird.
if (hour > 0 || (day > 0))
if (hour > 1)
str += hour + " hours, ";
else
str += hour + " hour, ";
if (min > 0)
str += min + " min, ";
if (sec > 0)
str += sec + " s";

return str;
}

@Override
Expand Down

0 comments on commit 5e887b3

Please sign in to comment.