Skip to content

Commit

Permalink
CHE-1361 Artik: Resources monitor (CPU, memory and storage)
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guliy <[email protected]>
  • Loading branch information
Vitaliy Guliy committed Jul 25, 2016
1 parent ff31a1e commit 8c977b5
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1511,4 +1511,12 @@ public interface Theme {
String vcsConsoleChangesLineNumbersColor();

String editorPreferenceCategoryBackgroundColor();

/********************************************************************************************
*
* Resource monitors
*
********************************************************************************************/
String resourceMonitorBarBackground();

}
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,16 @@ public String vcsConsoleChangesLineNumbersColor() {
public String editorPreferenceCategoryBackgroundColor() {
return "rgba(215, 215, 215, 0.10)";
}

/********************************************************************************************
*
* Resource monitors
*
********************************************************************************************/

@Override
public String resourceMonitorBarBackground() {
return "rgb(76, 76, 76)";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1476,4 +1476,16 @@ public String vcsConsoleChangesLineNumbersColor() {
public String editorPreferenceCategoryBackgroundColor() {
return "rgba(27, 27, 27, 0.10)";
}

/********************************************************************************************
*
* Resource monitors
*
********************************************************************************************/

@Override
public String resourceMonitorBarBackground() {
return "#e0e0e0";
}

}
17 changes: 17 additions & 0 deletions ide/commons-gwt/src/main/java/org/eclipse/che/ide/ui/Tooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ public static Tooltip create(Element targetElement, PositionController.VerticalA
new SimpleStringRenderer(tooltipText)).build();
}

/** Static factory method for creating a simple tooltip with given element as content. */
public static Tooltip create(Element targetElement, PositionController.VerticalAlign vAlign,
PositionController.HorizontalAlign hAlign, final Element tooltipContent) {
return new Builder(targetElement, new TooltipPositionerBuilder().setVerticalAlign(vAlign)
.setHorizontalAlign(hAlign)
.buildAnchorPositioner(targetElement)).setTooltipRenderer(

new TooltipRenderer() {
@Override
public Element renderDom() {
return tooltipContent;
}
}

).build();
}

/** The Tooltip is a flyweight that uses a singleton View base element. */
private static AutoHideView<Void> getViewInstance(Css css) {
if (tooltipViewInstance == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
display: inline-block;
position: relative;
margin: 0;
max-width: 200px;
max-width: 250px;
}

/*
* Imageless triangles can be made using only css by adding a large border on one side,
* then transparent borders on the two adjacent sides.
*/
/*
* Imageless triangles can be made using only css by adding a large border on one side,
* then transparent borders on the two adjacent sides.
*/
.triangle {
position: absolute;
width: 0px;
Expand All @@ -52,7 +52,7 @@
margin-left: -4px;
}

/* A tooltip that is below but right aligned */
/* A tooltip that is below but right aligned */
.tooltipBelowRightAligned {
margin-top: 7px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface Handler extends EventHandler {
/**
* Type class used to register this event.
*/
public static Type<MachineStateEvent.Handler> TYPE = new Type<>();
public static final Type<MachineStateEvent.Handler> TYPE = new Type<>();

private final org.eclipse.che.api.core.model.machine.Machine machine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.machine.MachineServiceClient;
import org.eclipse.che.ide.api.machine.events.DevMachineStateEvent;
import org.eclipse.che.ide.api.mvp.View;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.outputconsole.OutputConsole;
Expand Down Expand Up @@ -81,8 +80,7 @@ public class ConsolesPanelPresenter implements ConsolesPanelView.ActionDelegate,
OutputConsole.ConsoleOutputListener,
WorkspaceStartingEvent.Handler,
WorkspaceStoppedEvent.Handler,
MachineStateEvent.Handler,
DevMachineStateEvent.Handler {
MachineStateEvent.Handler {

private static final String DEFAULT_TERMINAL_NAME = "Terminal";

Expand Down Expand Up @@ -153,13 +151,12 @@ public ConsolesPanelPresenter(ConsolesPanelView view,
this.consoleCommands = new HashMap<>();
this.machineNodes = new HashMap<>();

this.view.setDelegate(this);
view.setDelegate(this);

eventBus.addHandler(ProcessFinishedEvent.TYPE, this);
eventBus.addHandler(WorkspaceStartingEvent.TYPE, this);
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, this);
eventBus.addHandler(MachineStateEvent.TYPE, this);
eventBus.addHandler(DevMachineStateEvent.TYPE, this);

rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, rootNodes);

Expand Down Expand Up @@ -215,14 +212,6 @@ public void onMachineDestroyed(MachineStateEvent event) {
view.setProcessesData(rootNode);
}

@Override
public void onDevMachineStarted(DevMachineStateEvent event) {
}

@Override
public void onDevMachineDestroyed(DevMachineStateEvent event) {
}

/** Get the list of all available machines. */
public void fetchMachines() {
machineService.getMachines(appContext.getWorkspaceId()).then(new Operation<List<MachineDto>>() {
Expand Down Expand Up @@ -262,9 +251,11 @@ public void printDevMachineOutput(String text) {
}

private ProcessTreeNode addMachineNode(MachineDto machine) {
List<ProcessTreeNode> processTreeNodes = new ArrayList<ProcessTreeNode>();
if (machineNodes.containsKey(machine.getId())) {
return machineNodes.get(machine.getId());
}

ProcessTreeNode machineNode = new ProcessTreeNode(MACHINE_NODE, rootNode, machine, null, processTreeNodes);
ProcessTreeNode machineNode = new ProcessTreeNode(MACHINE_NODE, rootNode, machine, null, new ArrayList<ProcessTreeNode>());
machineNode.setRunning(true);
machineNodes.put(machine.getId(), machineNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void setProcessesData(@NotNull ProcessTreeNode root) {

processTree.asWidget().setVisible(true);
processTree.getModel().setRoot(root);
processTree.renderTree(-1);
processTree.renderTree();

for (ProcessTreeNode processTreeNode : processTreeNodes.values()) {
if (!processTreeNode.getId().equals(activeProcessId) && processTreeNode.hasUnreadContent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.che.ide.api.parts.PartStackUIResources;
import org.eclipse.che.ide.extension.machine.client.MachineLocalizationConstant;
import org.eclipse.che.ide.extension.machine.client.MachineResources;
import org.eclipse.che.ide.extension.machine.client.processes.monitoring.MachineMonitors;
import org.eclipse.che.ide.ui.Tooltip;
import org.eclipse.che.ide.ui.tree.NodeRenderer;
import org.eclipse.che.ide.ui.tree.TreeNodeElement;
Expand Down Expand Up @@ -59,13 +60,17 @@ public class ProcessTreeRenderer implements NodeRenderer<ProcessTreeNode> {
private AddTerminalClickHandler addTerminalClickHandler;
private PreviewSshClickHandler previewSshClickHandler;
private StopProcessHandler stopProcessHandler;
private final MachineMonitors machineMonitors;

@Inject
public ProcessTreeRenderer(MachineResources resources, MachineLocalizationConstant locale,
PartStackUIResources partStackUIResources) {
public ProcessTreeRenderer(MachineResources resources,
MachineLocalizationConstant locale,
PartStackUIResources partStackUIResources,
MachineMonitors machineMonitors) {
this.resources = resources;
this.locale = locale;
this.partStackUIResources = partStackUIResources;
this.machineMonitors = machineMonitors;
}

@Override
Expand Down Expand Up @@ -190,6 +195,13 @@ public void handleEvent(Event event) {
newTerminalButton.addEventListener(Event.CLICK, blockMouseListener, true);
newTerminalButton.addEventListener(Event.DBLCLICK, blockMouseListener, true);

Element monitorsElement = Elements.createSpanElement();
monitorsElement.getStyle().setProperty("float", "right");
monitorsElement.getStyle().setProperty("cursor", "default");
root.appendChild(monitorsElement);

Node monitorNode = (Node)machineMonitors.getMonitorWidget(machine.getId(), this).getElement();
monitorsElement.appendChild(monitorNode);

Element nameElement = Elements.createSpanElement(resources.getCss().nameLabel());
nameElement.setTextContent(machine.getConfig().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.extension.machine.client.processes.monitoring;

import com.google.inject.Singleton;

import java.util.HashMap;
import java.util.Map;

/**
* Manages and provides widgets for displaying CPU, memory and disk usages for the machines.
*
* @author Vitaliy Guliy
*/
@Singleton
public class MachineMonitors {

private Map<String, Map<Object, MonitorWidget>> monitorWidgets = new HashMap<>();

/**
* Creates new or returns existed widget for the given machine and referrer.
* Referrer is an UI object containing monitor widgets attached as children.
*
* @param machineID
* machines ID
* @param referrer
* referrer object
* @return
* monitor widget
*/
public MonitorWidget getMonitorWidget(String machineID, Object referrer) {
Map<Object, MonitorWidget> widgets = monitorWidgets.get(machineID);
if (widgets == null) {
widgets = new HashMap<>();
monitorWidgets.put(machineID, widgets);
}

MonitorWidget widget = widgets.get(referrer);
if (widget == null) {
widget = new MonitorWidget();
widgets.put(referrer, widget);
}

return widget;
}

/**
* Sets new CPU usage value for machine with given ID.
*
* @param machineID
* machine ID
* @param cpuUsage
* new cpu usage
*/
public void setCpuUsage(String machineID, int cpuUsage) {
Map<Object, MonitorWidget> widgets = monitorWidgets.get(machineID);
if (widgets != null) {
for (MonitorWidget widget : widgets.values()) {
widget.setCpuUsage(cpuUsage);
}
}
}

/**
* Sets new memory usage value for machine with given ID.
*
* @param machineID
* machine ID
* @param mem
* new memory usage
* @param max
* maximum amount of memory
*/
public void setMemoryUsage(String machineID, int mem, int max) {
Map<Object, MonitorWidget> widgets = monitorWidgets.get(machineID);
if (widgets != null) {
for (MonitorWidget widget : widgets.values()) {
widget.setMemoryUsage(mem, max);
}
}
}

/**
* Sets new disk usage value for machine with given ID.
*
* @param machineID
* machine ID
* @param disk
* new disk usage
* @param max
* maximum amount of disk space
*/
public void setDiskUsage(String machineID, int disk, int max) {
Map<Object, MonitorWidget> widgets = monitorWidgets.get(machineID);
if (widgets != null) {
for (MonitorWidget widget : widgets.values()) {
widget.setDiskUsage(disk, max);
}
}
}

}
Loading

0 comments on commit 8c977b5

Please sign in to comment.