summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-07-26 12:48:55 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-07-26 19:02:04 +0530
commit17d81f5f32a577023a456315daadb5d4544d57c5 (patch)
treebfc1d2c65e907a1829e9c60dac74ac090555203b /src
parent070771ad1da13a9a6c874a51cecabd6abe98e603 (diff)
Story #38 - CPU Usage graph
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/ClusterListener.java2
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/DefaultClusterListener.java5
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java9
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java21
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartViewerComposite.java79
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java98
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java2
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java39
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java18
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java39
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java18
11 files changed, 165 insertions, 165 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/ClusterListener.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/ClusterListener.java
index 2a4a9920..355483e7 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/ClusterListener.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/ClusterListener.java
@@ -52,4 +52,6 @@ public interface ClusterListener {
public void alertRemoved(Alert alert);
public void alertUpdated(Alert alert);
+
+ public void aggregatedStatsChanged();
}
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/DefaultClusterListener.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/DefaultClusterListener.java
index e72ff3e5..6a3c5dae 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/DefaultClusterListener.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/DefaultClusterListener.java
@@ -110,4 +110,9 @@ public class DefaultClusterListener implements ClusterListener {
public void alertUpdated(Alert alert) {
modelChanged();
}
+
+ @Override
+ public void aggregatedStatsChanged() {
+ modelChanged();
+ }
}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java
index 33132c64..afc0e7aa 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/GlusterDataModelManager.java
@@ -201,8 +201,17 @@ public class GlusterDataModelManager {
updateDiscoveredServers(model);
updateTasks(model);
updateAlerts(model);
+ updateServerStatistics(model);
}
+ private void updateServerStatistics(GlusterDataModel newModel) {
+ model.getCluster().setAggregatedCpuStats(newModel.getCluster().getAggregatedCpuStats());
+ model.getCluster().setAggregatedNetworkStats(newModel.getCluster().getAggregatedNetworkStats());
+ for(ClusterListener listener : listeners) {
+ listener.aggregatedStatsChanged();
+ }
+ }
+
private void updateAlerts(GlusterDataModel newModel) {
List<Alert> oldAlerts = model.getCluster().getAlerts();
List<Alert> newAlerts = newModel.getCluster().getAlerts();
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java
index 2d16fcd2..850407d1 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/ChartsPreferencePage.java
@@ -20,28 +20,20 @@ package com.gluster.storage.management.gui.preferences;
import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import com.gluster.storage.management.gui.Activator;
+
/**
*
*/
public class ChartsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public ChartsPreferencePage() {
- }
-
- public ChartsPreferencePage(int style) {
- super(style);
- }
-
- public ChartsPreferencePage(String title, int style) {
- super(title, style);
- }
-
- public ChartsPreferencePage(String title, ImageDescriptor image, int style) {
- super(title, image, style);
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("Gluster Management Console");
}
/* (non-Javadoc)
@@ -57,8 +49,7 @@ public class ChartsPreferencePage extends FieldEditorPreferencePage implements I
@Override
protected void createFieldEditors() {
String[][] entryNamesAndValues = new String[][] {
- { "1d", "1d" }, { "1w", "1w" }, { "1m", "1m" }, { "1y", "1y" } };
- //{ "1 day", "1d" }, { "1 week", "1w" }, { "1 month", "1m" }, { "1 year", "1y" } };
+ { "1 day", "1d" }, { "1 week", "1w" }, { "1 month", "1m" }, { "1 year", "1y" } };
addField(new ComboFieldEditor(PreferenceConstants.P_CPU_CHART_PERIOD, "CPU Usage chart period", entryNamesAndValues,
getFieldEditorParent()));
addField(new ComboFieldEditor(PreferenceConstants.P_MEM_CHART_PERIOD, "Memory Usage chart period", entryNamesAndValues,
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartViewerComposite.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartViewerComposite.java
index 30982096..95f0277c 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartViewerComposite.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartViewerComposite.java
@@ -18,8 +18,6 @@
*******************************************************************************/
package com.gluster.storage.management.gui.utils;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -30,7 +28,6 @@ import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.Generator;
import org.eclipse.birt.chart.model.Chart;
-import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.ChartWithoutAxes;
import org.eclipse.birt.chart.model.attribute.Anchor;
import org.eclipse.birt.chart.model.attribute.AxisType;
@@ -39,7 +36,6 @@ import org.eclipse.birt.chart.model.attribute.ChartDimension;
import org.eclipse.birt.chart.model.attribute.FontDefinition;
import org.eclipse.birt.chart.model.attribute.LineAttributes;
import org.eclipse.birt.chart.model.attribute.LineStyle;
-import org.eclipse.birt.chart.model.attribute.NumberFormatSpecifier;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
@@ -72,16 +68,6 @@ import org.eclipse.birt.chart.model.type.impl.AreaSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
import org.eclipse.birt.core.framework.PlatformConfig;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.PaintEvent;
@@ -92,7 +78,6 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import com.ibm.icu.util.Calendar;
-import com.ibm.icu.util.ULocale;
/**
*
@@ -139,12 +124,13 @@ public final class ChartViewerComposite extends Composite implements PaintListen
* @param values
* Values of each category in the pie chart Constructs a pie
* chart viewer composite for given categories and values
+ * @param maxValue
*/
- public ChartViewerComposite(Composite parent, int style, Calendar[] categories, Double[] values, String unit, String timestampFormat) {
+ public ChartViewerComposite(Composite parent, int style, Calendar[] categories, Double[] values, String unit, String timestampFormat, double maxValue) {
super(parent, style);
init();
- createSingleAreaChart(categories, values, unit, timestampFormat);
+ createSingleAreaChart(categories, values, unit, timestampFormat, maxValue);
addPaintListener(this);
}
@@ -170,17 +156,18 @@ public final class ChartViewerComposite extends Composite implements PaintListen
});
}
- private void createSingleAreaChart(Calendar[] timestamps, Double[] values, String unit, String timestampFormat) {
- createAreaChart(timestamps, new Double[][] {values}, unit, timestampFormat);
+ private void createSingleAreaChart(Calendar[] timestamps, Double[] values, String unit, String timestampFormat, double maxValue) {
+ createAreaChart(timestamps, new Double[][] {values}, unit, timestampFormat, maxValue);
}
/**
* Creates a line chart model as a reference implementation
+ * @param maxValue
*
* @return An instance of the simulated runtime chart model (containing
* filled datasets)
*/
- private final void createAreaChart(Calendar[] timestamps, Double[][] values, final String unit, final String timestampFormat) {
+ private final void createAreaChart(Calendar[] timestamps, Double[][] values, final String unit, final String timestampFormat, double maxValue) {
chart = ChartWithAxesImpl.create();
// Plot
chart.getBlock().setBackground(ColorDefinitionImpl.WHITE());
@@ -206,12 +193,12 @@ public final class ChartViewerComposite extends Composite implements PaintListen
lg.getOutline( ).setVisible( false );
lg.setAnchor( Anchor.NORTH_LITERAL );
- updateDataSet(timestamps, values, unit, timestampFormat);
+ updateDataSet(timestamps, values, unit, timestampFormat, maxValue);
}
- private void updateDataSet(Calendar[] timestamps, Double[][] values, final String unit, final String timestampFormat) {
+ private void updateDataSet(Calendar[] timestamps, Double[][] values, final String unit, final String timestampFormat, double maxValue) {
Axis xAxisPrimary = setupXAxis(timestamps, timestampFormat);
- Axis yAxisPrimary = setupYAxis(unit, xAxisPrimary);
+ Axis yAxisPrimary = setupYAxis(unit, xAxisPrimary, maxValue);
configureXSeries(timestamps, xAxisPrimary);
configureYSeries(values, yAxisPrimary);
}
@@ -253,9 +240,11 @@ public final class ChartViewerComposite extends Composite implements PaintListen
sdX.getSeries().add(seCategory);
}
- private Axis setupYAxis(final String unit, Axis xAxisPrimary) {
+ private Axis setupYAxis(final String unit, Axis xAxisPrimary, double maxValue) {
Axis yAxisPrimary = ((ChartWithAxesImpl)chart).getPrimaryOrthogonalAxis(xAxisPrimary);
- yAxisPrimary.getScale().setMax(NumberDataElementImpl.create(100));
+ if(maxValue > 0) {
+ yAxisPrimary.getScale().setMax(NumberDataElementImpl.create(maxValue));
+ }
yAxisPrimary.getScale().setMin(NumberDataElementImpl.create(0));
yAxisPrimary.setGapWidth(0);
yAxisPrimary.getScale().setStep(20);
@@ -396,26 +385,26 @@ public final class ChartViewerComposite extends Composite implements PaintListen
}
}
- public void chartRefresh(Calendar[] timestamps, Double[][] values, String unit, String timestampFormat)
- {
- if ( !isDisposed( ) )
- {
- final Generator gr = Generator.instance( );
- updateDataSet( timestamps, values, unit, timestampFormat);
-
- // Refresh
- try
- {
- gr.refresh( generatedChartState );
- }
- catch ( ChartException ex )
- {
- // TODO: log the exception
- ex.printStackTrace( );
- }
- redraw( );
- }
- }
+// public void chartRefresh(Calendar[] timestamps, Double[][] values, String unit, String timestampFormat)
+// {
+// if ( !isDisposed( ) )
+// {
+// final Generator gr = Generator.instance( );
+// updateDataSet( timestamps, values, unit, timestampFormat);
+//
+// // Refresh
+// try
+// {
+// gr.refresh( generatedChartState );
+// }
+// catch ( ChartException ex )
+// {
+// // TODO: log the exception
+// ex.printStackTrace( );
+// }
+// redraw( );
+// }
+// }
/*
* (non-Javadoc)
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java
index 40b0491d..b67cca30 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java
@@ -47,6 +47,8 @@ import com.gluster.storage.management.client.GlusterServersClient;
import com.gluster.storage.management.core.constants.GlusterConstants;
import com.gluster.storage.management.core.model.Alert;
import com.gluster.storage.management.core.model.Cluster;
+import com.gluster.storage.management.core.model.ClusterListener;
+import com.gluster.storage.management.core.model.DefaultClusterListener;
import com.gluster.storage.management.core.model.EntityGroup;
import com.gluster.storage.management.core.model.GlusterDataModel;
import com.gluster.storage.management.core.model.GlusterServer;
@@ -74,7 +76,11 @@ public class ClusterSummaryView extends ViewPart {
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
private ScrolledForm form;
private Cluster cluster;
+ private Composite cpuChartSection;
+ private Composite networkChartSection;
private GlusterDataModel model = GlusterDataModelManager.getInstance().getModel();
+ private ClusterListener clusterListener;
+ private static final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
private static final int CHART_WIDTH = 350;
/*
@@ -89,6 +95,28 @@ public class ClusterSummaryView extends ViewPart {
}
setPartName("Summary");
createSections(parent);
+
+ clusterListener = new DefaultClusterListener() {
+ @Override
+ public void aggregatedStatsChanged() {
+ super.aggregatedStatsChanged();
+ refreshCharts();
+ }
+ };
+ GlusterDataModelManager.getInstance().addClusterListener(clusterListener);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ GlusterDataModelManager.getInstance().removeClusterListener(clusterListener);
+ }
+
+ private void refreshCharts() {
+ String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_CHART_PERIOD);
+ String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD);
+ refreshChartSection(cpuChartSection, cluster.getAggregatedCpuStats(), cpuStatsPeriod, "%", 100, 4, new CpuChartPeriodLinkListener(cpuStatsPeriod));
+ refreshChartSection(networkChartSection, cluster.getAggregatedNetworkStats(), networkStatsPeriod, "KiB/s", -1, 4, new NetworkChartPeriodLinkListener(networkStatsPeriod));
}
private int getServerCountByStatus(Cluster cluster, SERVER_STATUS status) {
@@ -145,6 +173,7 @@ public class ClusterSummaryView extends ViewPart {
protected String statsPeriod;
protected String unit;
protected int columnCount;
+ protected double maxValue;
public String getStatsPeriod() {
return this.statsPeriod;
@@ -154,10 +183,11 @@ public class ClusterSummaryView extends ViewPart {
this.statsPeriod = statsPeriod;
}
- public ChartPeriodLinkListener(String statsPeriod, String unit, int columnCount) {
+ public ChartPeriodLinkListener(String statsPeriod, String unit, double maxValue, int columnCount) {
this.statsPeriod = statsPeriod;
this.unit = unit;
this.columnCount = columnCount;
+ this.maxValue = maxValue;
}
@Override
@@ -165,16 +195,8 @@ public class ClusterSummaryView extends ViewPart {
super.linkActivated(e);
//GlusterDataModelManager.getInstance().initializeAlerts(cluster);
Composite section = ((Hyperlink)e.getSource()).getParent().getParent();
- for(Control control : section.getChildren()) {
- control.dispose();
- }
- List<Calendar> timestamps = new ArrayList<Calendar>();
- List<Double> data = new ArrayList<Double>();
ServerStats stats = fetchStats();
- extractChartData(stats, timestamps, data, 2);
- createAreaChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit, getTimestampFormatForPeriod(statsPeriod));
- createChartLinks(section, columnCount, this);
- section.layout();
+ refreshChartSection(section, stats, statsPeriod, unit, maxValue, columnCount, this);
}
public abstract ChartPeriodLinkListener getInstance(String statsPeriod);
@@ -187,20 +209,22 @@ public class ClusterSummaryView extends ViewPart {
super(statsPeriod);
}
- private CpuChartPeriodLinkListener(String statsPeriod, String unit, int columnCount) {
- super(statsPeriod, unit, columnCount);
+ private CpuChartPeriodLinkListener(String statsPeriod, String unit, double maxValue, int columnCount) {
+ super(statsPeriod, unit, maxValue, columnCount);
}
@Override
protected ServerStats fetchStats() {
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
preferenceStore.setValue(PreferenceConstants.P_CPU_CHART_PERIOD, statsPeriod);
- return new GlusterServersClient().getAggregatedCpuStats(statsPeriod);
+ ServerStats stats = new GlusterServersClient().getAggregatedCpuStats(statsPeriod);
+ cluster.setAggregatedCpuStats(stats);
+ return stats;
}
@Override
public ChartPeriodLinkListener getInstance(String statsPeriod) {
- return new CpuChartPeriodLinkListener(statsPeriod, "%", 4);
+ return new CpuChartPeriodLinkListener(statsPeriod, "%", 100, 4);
}
}
@@ -209,20 +233,22 @@ public class ClusterSummaryView extends ViewPart {
super(statsPeriod);
}
- private NetworkChartPeriodLinkListener(String statsPeriod, String unit, int columnCount) {
- super(statsPeriod, unit, columnCount);
+ private NetworkChartPeriodLinkListener(String statsPeriod, String unit, double maxValue, int columnCount) {
+ super(statsPeriod, unit, maxValue, columnCount);
}
@Override
protected ServerStats fetchStats() {
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
preferenceStore.setValue(PreferenceConstants.P_NETWORK_CHART_PERIOD, statsPeriod);
- return new GlusterServersClient().getAggregatedNetworkStats(statsPeriod);
+ ServerStats stats = new GlusterServersClient().getAggregatedNetworkStats(statsPeriod);
+ cluster.setAggregatedNetworkStats(stats);
+ return stats;
}
@Override
public ChartPeriodLinkListener getInstance(String statsPeriod) {
- return new NetworkChartPeriodLinkListener(statsPeriod, "KiB/s", 4);
+ return new NetworkChartPeriodLinkListener(statsPeriod, "KiB/s", -1d, 4);
}
}
@@ -253,8 +279,8 @@ public class ClusterSummaryView extends ViewPart {
}
}
- private ChartViewerComposite createAreaChart(Composite section, Calendar timestamps[], Double values[], String unit, String timestampFormat) {
- ChartViewerComposite chartViewerComposite = new ChartViewerComposite(section, SWT.NONE, timestamps, values, unit, timestampFormat);
+ private ChartViewerComposite createAreaChart(Composite section, Calendar timestamps[], Double values[], String unit, String timestampFormat, double maxValue) {
+ ChartViewerComposite chartViewerComposite = new ChartViewerComposite(section, SWT.NONE, timestamps, values, unit, timestampFormat, maxValue);
GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.widthHint = CHART_WIDTH;
data.heightHint = 250;
@@ -345,7 +371,7 @@ public class ClusterSummaryView extends ViewPart {
parent.layout(); // IMP: lays out the form properly
}
- private void createAreaChartSection(ServerStats stats, String sectionTitle, int dataColumnIndex, String unit, String timestampFormat, ChartPeriodLinkListener listener) {
+ private Composite createAreaChartSection(ServerStats stats, String sectionTitle, int dataColumnIndex, String unit, String timestampFormat, ChartPeriodLinkListener listener, double maxValue) {
Composite section = guiHelper.createSection(form, toolkit, sectionTitle, null, 1, false);
List<Calendar> timestamps = new ArrayList<Calendar>();
@@ -353,17 +379,22 @@ public class ClusterSummaryView extends ViewPart {
if (cluster.getServers().size() == 0) {
toolkit.createLabel(section, "This section will be populated after at least\none server is added to the storage cloud.");
- return;
+ return null;
+ }
+
+ if(stats == null) {
+ toolkit.createLabel(section, "Server statistics not available. Try after some time!");
+ return null;
}
extractChartData(stats, timestamps, data, dataColumnIndex);
if(timestamps.size() == 0) {
toolkit.createLabel(section, "Server statistics not available!\n Check if all services are running properly on the cluster servers.");
- return;
+ return null;
}
- createAreaChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit, timestampFormat);
+ createAreaChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit, timestampFormat, maxValue);
// Calendar[] timestamps = new Calendar[] { new CDateTime(1000l*1310468100), new CDateTime(1000l*1310468400), new CDateTime(1000l*1310468700),
// new CDateTime(1000l*1310469000), new CDateTime(1000l*1310469300), new CDateTime(1000l*1310469600), new CDateTime(1000l*1310469900),
@@ -375,6 +406,7 @@ public class ClusterSummaryView extends ViewPart {
// Double[] values = new Double[] { 10d, 11.23d, 17.92d, 18.69d, 78.62d, 89.11d, 92.43d, 89.31d, 57.39d, 18.46d, 10.44d, 16.28d, 13.51d, 17.53d, 12.21, 20d, 21.43d, 16.45d, 14.86d, 15.27d };
// createLineChart(section, timestamps, values, "%");
createChartLinks(section, 4, listener);
+ return section;
}
private void createCPUUsageSection() {
@@ -382,7 +414,7 @@ public class ClusterSummaryView extends ViewPart {
String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_CHART_PERIOD);
// in case of CPU usage, there are three elements in usage data: user, system and total. we use total.
- createAreaChartSection(cluster.getAggregatedCpuStats(), "CPU Usage (Aggregated)", 2, "%", getTimestampFormatForPeriod(cpuStatsPeriod), new CpuChartPeriodLinkListener(cpuStatsPeriod));
+ cpuChartSection = createAreaChartSection(cluster.getAggregatedCpuStats(), "CPU Usage (Aggregated)", 2, "%", getTimestampFormatForPeriod(cpuStatsPeriod), new CpuChartPeriodLinkListener(cpuStatsPeriod), 100);
}
private String getTimestampFormatForPeriod(String statsPeriod) {
@@ -410,7 +442,7 @@ public class ClusterSummaryView extends ViewPart {
String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD);
// in case of network usage, there are three elements in usage data: received, transmitted and total. we use total.
- createAreaChartSection(cluster.getAggregatedNetworkStats(), "Network Usage (Aggregated)", 2, "KiB/s", getTimestampFormatForPeriod(networkStatsPeriod), new NetworkChartPeriodLinkListener(networkStatsPeriod));
+ networkChartSection = createAreaChartSection(cluster.getAggregatedNetworkStats(), "Network Usage (Aggregated)", 2, "KiB/s", getTimestampFormatForPeriod(networkStatsPeriod), new NetworkChartPeriodLinkListener(networkStatsPeriod), -1);
}
private void createRunningTasksSection() {
@@ -453,4 +485,18 @@ public class ClusterSummaryView extends ViewPart {
form.setFocus();
}
}
+
+ private void refreshChartSection(Composite section, ServerStats stats, String statsPeriod, String unit, double maxValue, int columnCount, ChartPeriodLinkListener linkListener) {
+ for(Control control : section.getChildren()) {
+ if(! control.isDisposed()) {
+ control.dispose();
+ }
+ }
+ List<Calendar> timestamps = new ArrayList<Calendar>();
+ List<Double> data = new ArrayList<Double>();
+ extractChartData(stats, timestamps, data, 2);
+ createAreaChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit, getTimestampFormatForPeriod(statsPeriod), maxValue);
+ createChartLinks(section, columnCount, linkListener);
+ section.layout();
+ }
}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java
index e7ef1648..492b51f3 100644
--- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java
@@ -116,7 +116,7 @@ public class GlusterServerSummaryView extends ViewPart {
}
private void createAreaChart(Composite section, Calendar timestamps[], Double values[], String unit) {
- ChartViewerComposite chartViewerComposite = new ChartViewerComposite(section, SWT.NONE, timestamps, values, unit, "HH:mm");
+ ChartViewerComposite chartViewerComposite = new ChartViewerComposite(section, SWT.NONE, timestamps, values, unit, "HH:mm", 100);
GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.widthHint = CHART_WIDTH;
data.heightHint = 250;
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java
deleted file mode 100644
index 99089eb7..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterExceptionMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
- * This file is part of Gluster Management Console.
- *
- * Gluster Management Console is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Gluster Management Console is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- *******************************************************************************/
-package com.gluster.storage.management.server.resources.v1_0;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-
-import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
-
-@Provider
-public class GlusterExceptionMapper implements ExceptionMapper<GlusterRuntimeException> {
-
- /* (non-Javadoc)
- * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
- */
- @Override
- public Response toResponse(GlusterRuntimeException exception) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage())
- .type(MediaType.TEXT_PLAIN).build();
- }
-}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
index 1b2bb41e..9693ace9 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
@@ -522,6 +522,14 @@ public class GlusterServersResource extends AbstractServersResource {
if (clusterName == null || clusterName.isEmpty()) {
throw new GlusterValidationException("Cluster name must not be empty!");
}
+
+ if (type == null || type.isEmpty()) {
+ throw new GlusterValidationException("Statistics type name must not be empty!");
+ }
+
+ if (period == null || period.isEmpty()) {
+ throw new GlusterValidationException("Statistics period name must not be empty! Valid values are 1d/1w/1m/1y");
+ }
ClusterInfo cluster = clusterService.getCluster(clusterName);
if (cluster == null) {
@@ -541,9 +549,19 @@ public class GlusterServersResource extends AbstractServersResource {
if (clusterName == null || clusterName.isEmpty()) {
throw new GlusterValidationException("Cluster name must not be empty!");
}
+
if (serverName == null || serverName.isEmpty()) {
throw new GlusterValidationException("Server name must not be empty!");
}
+
+ if (type == null || type.isEmpty()) {
+ throw new GlusterValidationException("Statistics type name must not be empty!");
+ }
+
+ if (period == null || period.isEmpty()) {
+ throw new GlusterValidationException("Statistics period name must not be empty! Valid values are 1d/1w/1m/1y");
+ }
+
return okResponse(getStatsFactory(type).fetchStats(serverName, period, networkInterface), mediaType);
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java
deleted file mode 100644
index cab6cc62..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/ValidationExceptionMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
- * This file is part of Gluster Management Console.
- *
- * Gluster Management Console is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Gluster Management Console is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see
- * <http://www.gnu.org/licenses/>.
- *******************************************************************************/
-package com.gluster.storage.management.server.resources.v1_0;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
-
-import com.gluster.storage.management.core.exceptions.GlusterValidationException;
-
-@Provider
-public class ValidationExceptionMapper implements ExceptionMapper<GlusterValidationException> {
-
- /* (non-Javadoc)
- * @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
- */
- @Override
- public Response toResponse(GlusterValidationException exception) {
- return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage())
- .type(MediaType.TEXT_PLAIN).build();
- }
-}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
index 96bb0c65..2a50d598 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/NetworkStatsFactory.java
@@ -27,6 +27,7 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.model.NetworkInterface;
import com.gluster.storage.management.core.model.Server;
import com.gluster.storage.management.core.model.ServerStats;
+import com.gluster.storage.management.core.model.ServerStatsRow;
/**
*
@@ -102,4 +103,21 @@ public class NetworkStatsFactory extends AbstractStatsFactory {
averageAggregatedStats(aggregatedStats, dataCount);
}
+
+ @Override
+ public ServerStats fetchStats(String serverName, String period, String... args) {
+ ServerStats stats = super.fetchStats(serverName, period, args);
+
+ // the data returned by rrd contains "bytes" transferred in the given time step. Update the stats object to represent KiB/s
+ int step = stats.getMetadata().getStep();
+ for(ServerStatsRow row : stats.getRows()) {
+ List<Double> data = row.getUsageData();
+ for (int i = 0; i < data.size(); i++) {
+ Double val = data.get(i);
+ data.set(i, val / 1024 / step);
+ }
+ }
+
+ return stats;
+ }
}