diff options
Diffstat (limited to 'src')
8 files changed, 212 insertions, 266 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java index 9042dc9a..3bc22370 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java @@ -101,7 +101,7 @@ public class GlusterServersClient extends AbstractClient { public ServerStats getNetworkStats(String serverName, String networkInterface, String period) { MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_MEMORY); + queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_NETWORK); queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); queryParams.add(RESTConstants.QUERY_PARAM_INTERFACE, networkInterface); return fetchSubResource(serverName + "/" + RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); 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 cacd987e..08bef79c 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 @@ -435,14 +435,14 @@ public class GlusterDataModelManager { public void initializeAggregatedCpuStats(Cluster cluster) { IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_CHART_PERIOD); + String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_AGGREGATED_CHART_PERIOD); cluster.setAggregatedCpuStats(new GlusterServersClient().getAggregatedCpuStats(cpuStatsPeriod)); } private void initializeAggregatedNetworkStats(Cluster cluster) { IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD); + String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_AGGREGATED_CHART_PERIOD); cluster.setAggregatedNetworkStats(new GlusterServersClient().getAggregatedNetworkStats(networkStatsPeriod)); } 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 850407d1..80cff1aa 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 @@ -50,6 +50,10 @@ public class ChartsPreferencePage extends FieldEditorPreferencePage implements I protected void createFieldEditors() { String[][] entryNamesAndValues = new String[][] { { "1 day", "1d" }, { "1 week", "1w" }, { "1 month", "1m" }, { "1 year", "1y" } }; + addField(new ComboFieldEditor(PreferenceConstants.P_CPU_AGGREGATED_CHART_PERIOD, "Aggregated CPU Usage chart period", entryNamesAndValues, + getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceConstants.P_NETWORK_AGGREGATED_CHART_PERIOD, "Aggregated Network Usage chart period", entryNamesAndValues, + getFieldEditorParent())); 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/preferences/PreferenceConstants.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java index 46af10d3..a53b1879 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java @@ -34,4 +34,6 @@ public class PreferenceConstants { public static final String P_CPU_CHART_PERIOD = "cpu.chart.period"; public static final String P_MEM_CHART_PERIOD = "memory.chart.period"; public static final String P_NETWORK_CHART_PERIOD = "network.chart.period"; + public static final String P_CPU_AGGREGATED_CHART_PERIOD = "cpu.aggregated.chart.period"; + public static final String P_NETWORK_AGGREGATED_CHART_PERIOD = "network.aggregated.chart.period"; } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java index 726e62b4..36289e8a 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java @@ -54,5 +54,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { store.setDefault(PreferenceConstants.P_CPU_CHART_PERIOD, "1d"); store.setDefault(PreferenceConstants.P_MEM_CHART_PERIOD, "1d"); store.setDefault(PreferenceConstants.P_NETWORK_CHART_PERIOD, "1d"); + store.setDefault(PreferenceConstants.P_CPU_AGGREGATED_CHART_PERIOD, "1d"); + store.setDefault(PreferenceConstants.P_NETWORK_AGGREGATED_CHART_PERIOD, "1d"); } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartUtil.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartUtil.java index a7559f9e..84b734c3 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartUtil.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ChartUtil.java @@ -24,6 +24,9 @@ import java.util.List; import org.eclipse.birt.chart.util.CDateTime; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -35,12 +38,13 @@ import org.eclipse.ui.forms.widgets.Hyperlink; import com.gluster.storage.management.client.GlusterServersClient; import com.gluster.storage.management.core.constants.GlusterConstants; -import com.gluster.storage.management.core.model.Cluster; +import com.gluster.storage.management.core.model.GlusterServer; +import com.gluster.storage.management.core.model.NetworkInterface; import com.gluster.storage.management.core.model.ServerStats; import com.gluster.storage.management.core.model.ServerStatsRow; import com.gluster.storage.management.gui.Activator; +import com.gluster.storage.management.gui.GlusterDataModelManager; import com.gluster.storage.management.gui.preferences.PreferenceConstants; -import com.gluster.storage.management.gui.views.ClusterSummaryView.ChartPeriodLinkListener; import com.ibm.icu.util.Calendar; /** @@ -48,8 +52,8 @@ import com.ibm.icu.util.Calendar; */ public class ChartUtil { private static final ChartUtil instance = new ChartUtil(); - private static final GUIHelper guiHelper = GUIHelper.getInstance(); private static final int CHART_WIDTH = 350; + private static final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); private ChartUtil() { } @@ -58,16 +62,33 @@ public class ChartUtil { return instance; } - public Composite createAreaChartSection(FormToolkit toolkit, Composite section, ServerStats stats, - int dataColumnIndex, String unit, String timestampFormat, ChartPeriodLinkListener listener, double maxValue) { + /** + * @param toolkit + * @param section + * @param stats + * @param dataColumnIndex + * @param unit + * @param timestampFormat + * @param listener + * @param maxValue + * @return The composite containing the various links related to the created chart + */ + public Composite createAreaChart(FormToolkit toolkit, Composite section, ServerStats stats, int dataColumnIndex, + String unit, String timestampFormat, ChartPeriodLinkListener listener, double maxValue, int linkColumnCount) { + if (stats == null) { + toolkit.createLabel(section, "Server statistics not available. Try after some time!"); + return null; + } + List<Calendar> timestamps = new ArrayList<Calendar>(); List<Double> data = new ArrayList<Double>(); 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."); + toolkit.createLabel( + section, + "Server statistics not available!\nCheck if all services are running properly \non the cluster servers, or try after some time!"); return null; } @@ -89,8 +110,13 @@ public class ChartUtil { // 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(toolkit, section, 4, listener); - return section; + Composite chartLinksComposite = createChartLinks(toolkit, section, linkColumnCount, listener); + + if (linkColumnCount == 5) { + createNetworkInterfaceCombo(section, chartLinksComposite, toolkit, + (NetworkChartPeriodLinkListener) listener); + } + return chartLinksComposite; } private ChartViewerComposite createAreaChart(Composite section, Calendar timestamps[], Double values[], @@ -149,23 +175,22 @@ public class ChartUtil { protected String unit; protected int columnCount; protected double maxValue; - protected Cluster cluster; protected FormToolkit toolkit; protected String serverName; + protected int dataColumnIndex; public String getStatsPeriod() { return this.statsPeriod; } - public ChartPeriodLinkListener(Cluster cluster, String serverName, String statsPeriod, String unit, - double maxValue, int columnCount, FormToolkit toolkit) { - this.cluster = cluster; + public ChartPeriodLinkListener(String serverName, String statsPeriod, String unit, double maxValue, + int columnCount, int dataColumnIndex, FormToolkit toolkit) { this.serverName = serverName; this.statsPeriod = statsPeriod; this.unit = unit; this.columnCount = columnCount; this.maxValue = maxValue; - this.cluster = cluster; + this.dataColumnIndex = dataColumnIndex; this.toolkit = toolkit; } @@ -178,10 +203,10 @@ public class ChartUtil { @Override public void linkActivated(HyperlinkEvent e) { super.linkActivated(e); - // GlusterDataModelManager.getInstance().initializeAlerts(cluster); Composite section = ((Hyperlink) e.getSource()).getParent().getParent(); ServerStats stats = fetchStats(serverName); - refreshChartSection(toolkit, section, stats, statsPeriod, unit, maxValue, columnCount, this); + refreshChartSection(toolkit, section, stats, statsPeriod, unit, maxValue, columnCount, this, + dataColumnIndex); } public abstract ChartPeriodLinkListener getInstance(String statsPeriod); @@ -190,9 +215,13 @@ public class ChartUtil { } public class CpuChartPeriodLinkListener extends ChartPeriodLinkListener { - private CpuChartPeriodLinkListener(Cluster cluster, String serverName, String statsPeriod, String unit, - double maxValue, int columnCount, FormToolkit toolkit) { - super(cluster, serverName, statsPeriod, unit, maxValue, columnCount, toolkit); + public CpuChartPeriodLinkListener(String serverName, String statsPeriod, FormToolkit toolkit) { + super(serverName, statsPeriod, toolkit); + } + + private CpuChartPeriodLinkListener(String serverName, String statsPeriod, String unit, double maxValue, + int columnCount, int dataColumnIndex, FormToolkit toolkit) { + super(serverName, statsPeriod, unit, maxValue, columnCount, dataColumnIndex, toolkit); } @Override @@ -202,7 +231,7 @@ public class ChartUtil { ServerStats stats; if (serverName == null) { stats = new GlusterServersClient().getAggregatedCpuStats(statsPeriod); - cluster.setAggregatedCpuStats(stats); + GlusterDataModelManager.getInstance().getModel().getCluster().setAggregatedCpuStats(stats); } else { stats = new GlusterServersClient().getCpuStats(serverName, statsPeriod); } @@ -211,7 +240,7 @@ public class ChartUtil { @Override public ChartPeriodLinkListener getInstance(String statsPeriod) { - return new CpuChartPeriodLinkListener(cluster, serverName, statsPeriod, "%", 100, 4, toolkit); + return new CpuChartPeriodLinkListener(serverName, statsPeriod, "%", 100, 4, dataColumnIndex, toolkit); } } @@ -220,9 +249,9 @@ public class ChartUtil { super(serverName, statsPeriod, toolkit); } - private MemoryChartPeriodLinkListener(Cluster cluster, String serverName, String statsPeriod, String unit, - double maxValue, int columnCount, FormToolkit toolkit) { - super(cluster, serverName, statsPeriod, unit, maxValue, columnCount, toolkit); + private MemoryChartPeriodLinkListener(String serverName, String statsPeriod, String unit, double maxValue, + int columnCount, int dataColumnIndex, FormToolkit toolkit) { + super(serverName, statsPeriod, unit, maxValue, columnCount, dataColumnIndex, toolkit); } @Override @@ -235,14 +264,23 @@ public class ChartUtil { @Override public ChartPeriodLinkListener getInstance(String statsPeriod) { - return new MemoryChartPeriodLinkListener(cluster, serverName, statsPeriod, "%", 100, 4, toolkit); + return new MemoryChartPeriodLinkListener(serverName, statsPeriod, "%", 100, 4, dataColumnIndex, toolkit); } } public class NetworkChartPeriodLinkListener extends ChartPeriodLinkListener { - private NetworkChartPeriodLinkListener(Cluster cluster, String serverName, String statsPeriod, String unit, - double maxValue, int columnCount, FormToolkit toolkit) { - super(cluster, serverName, statsPeriod, unit, maxValue, columnCount, toolkit); + private GlusterServer server; + + public NetworkChartPeriodLinkListener(GlusterServer server, String statsPeriod, FormToolkit toolkit) { + super(server == null ? null : server.getName(), statsPeriod, toolkit); + this.setServer(server); + } + + private NetworkChartPeriodLinkListener(GlusterServer server, String statsPeriod, String unit, double maxValue, + int columnCount, int dataColumnIndex, FormToolkit toolkit) { + super(server == null ? null : server.getName(), statsPeriod, unit, maxValue, columnCount, dataColumnIndex, + toolkit); + this.setServer(server); } @Override @@ -252,7 +290,7 @@ public class ChartUtil { ServerStats stats; if (serverName == null) { stats = new GlusterServersClient().getAggregatedNetworkStats(statsPeriod); - cluster.setAggregatedNetworkStats(stats); + GlusterDataModelManager.getInstance().getModel().getCluster().setAggregatedNetworkStats(stats); } else { stats = new GlusterServersClient().getNetworkStats(serverName, "eth0", statsPeriod); } @@ -262,23 +300,61 @@ public class ChartUtil { @Override public ChartPeriodLinkListener getInstance(String statsPeriod) { - return new NetworkChartPeriodLinkListener(cluster, serverName, statsPeriod, "KiB/s", -1d, 4, toolkit); + // if serverName is null, it means we are showing aggregated stats - so the "network interface" combo will + // not be shown in the "links" composite. + int columnCount = (serverName == null ? 4 : 5); + return new NetworkChartPeriodLinkListener(server, statsPeriod, "KiB/s", -1d, columnCount, dataColumnIndex, + toolkit); + } + + public void setServer(GlusterServer server) { + this.server = server; } + + public GlusterServer getServer() { + return server; + } + } + + public void createNetworkInterfaceCombo(final Composite section, final Composite graphComposite, + final FormToolkit toolkit, final NetworkChartPeriodLinkListener networkChartPeriodLinkListener) { + final GlusterServer server = networkChartPeriodLinkListener.getServer(); + final String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD); + + final CCombo interfaceCombo = new CCombo(graphComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER | SWT.FLAT); + final List<NetworkInterface> niList = server.getNetworkInterfaces(); + final String[] interfaces = new String[niList.size()]; + + for (int i = 0; i < interfaces.length; i++) { + interfaces[i] = niList.get(i).getName(); + } + interfaceCombo.setItems(interfaces); + interfaceCombo.select(0); + interfaceCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + int selectionIndex = interfaceCombo.getSelectionIndex(); + String networkInterface = interfaces[selectionIndex]; + ServerStats stats = new GlusterServersClient().getNetworkStats(server.getName(), networkInterface, + networkStatsPeriod); + ChartUtil.getInstance().refreshChartSection(toolkit, section, stats, networkStatsPeriod, "KiB/s", -1, + 5, networkChartPeriodLinkListener, 2); + } + }); } - private void refreshChartSection(FormToolkit toolkit, Composite section, ServerStats stats, String statsPeriod, - String unit, double maxValue, int columnCount, ChartPeriodLinkListener linkListener) { + public void refreshChartSection(FormToolkit toolkit, Composite section, ServerStats stats, String statsPeriod, + String unit, double maxValue, int columnCount, ChartPeriodLinkListener linkListener, int dataColumnIndex) { + // TODO: Invoke guiHelper.clearSection when it's ready 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(toolkit, section, columnCount, linkListener); + + createAreaChart(toolkit, section, stats, dataColumnIndex, unit, getTimestampFormatForPeriod(statsPeriod), + linkListener, maxValue, columnCount); section.layout(); } 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 6d13e409..5a84b1bc 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 @@ -20,16 +20,13 @@ */ package com.gluster.storage.management.gui.views; -import java.util.ArrayList; import java.util.List; -import org.eclipse.birt.chart.util.CDateTime; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -37,13 +34,11 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.ImageHyperlink; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.part.ViewPart; -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; @@ -55,7 +50,6 @@ import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.Server; import com.gluster.storage.management.core.model.Server.SERVER_STATUS; import com.gluster.storage.management.core.model.ServerStats; -import com.gluster.storage.management.core.model.ServerStatsRow; import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.utils.NumberUtil; import com.gluster.storage.management.gui.Activator; @@ -63,9 +57,10 @@ import com.gluster.storage.management.gui.GlusterDataModelManager; import com.gluster.storage.management.gui.IImageKeys; import com.gluster.storage.management.gui.actions.IActionConstants; import com.gluster.storage.management.gui.preferences.PreferenceConstants; +import com.gluster.storage.management.gui.utils.ChartUtil; +import com.gluster.storage.management.gui.utils.ChartUtil.ChartPeriodLinkListener; import com.gluster.storage.management.gui.utils.ChartViewerComposite; import com.gluster.storage.management.gui.utils.GUIHelper; -import com.ibm.icu.util.Calendar; /** * @@ -81,9 +76,9 @@ public class ClusterSummaryView extends ViewPart { private GlusterDataModel model = GlusterDataModelManager.getInstance().getModel(); private ClusterListener clusterListener; private static final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - private static final int CHART_WIDTH = 350; private Composite alertsSection; private Composite tasksSection; + private static final ChartUtil chartUtil = ChartUtil.getInstance(); /* * (non-Javadoc) @@ -147,10 +142,12 @@ public class ClusterSummaryView extends ViewPart { } 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)); + String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_AGGREGATED_CHART_PERIOD); + String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_AGGREGATED_CHART_PERIOD); + refreshChartSection(cpuChartSection, cluster.getAggregatedCpuStats(), cpuStatsPeriod, "%", 100, 4, + chartUtil.new CpuChartPeriodLinkListener(null, cpuStatsPeriod, toolkit), 2); + refreshChartSection(networkChartSection, cluster.getAggregatedNetworkStats(), networkStatsPeriod, "KiB/s", -1, + 4, chartUtil.new NetworkChartPeriodLinkListener(null, networkStatsPeriod, toolkit), 2); } private int getServerCountByStatus(Cluster cluster, SERVER_STATUS status) { @@ -203,126 +200,6 @@ public class ClusterSummaryView extends ViewPart { chartViewerComposite.setLayoutData(data); } - public abstract class ChartPeriodLinkListener extends HyperlinkAdapter { - protected String statsPeriod; - protected String unit; - protected int columnCount; - protected double maxValue; - - public String getStatsPeriod() { - return this.statsPeriod; - } - - public ChartPeriodLinkListener(String statsPeriod) { - this.statsPeriod = statsPeriod; - } - - public ChartPeriodLinkListener(String statsPeriod, String unit, double maxValue, int columnCount) { - this.statsPeriod = statsPeriod; - this.unit = unit; - this.columnCount = columnCount; - this.maxValue = maxValue; - } - - @Override - public void linkActivated(HyperlinkEvent e) { - super.linkActivated(e); - //GlusterDataModelManager.getInstance().initializeAlerts(cluster); - Composite section = ((Hyperlink)e.getSource()).getParent().getParent(); - ServerStats stats = fetchStats(); - refreshChartSection(section, stats, statsPeriod, unit, maxValue, columnCount, this); - } - - public abstract ChartPeriodLinkListener getInstance(String statsPeriod); - - protected abstract ServerStats fetchStats(); - } - - public class CpuChartPeriodLinkListener extends ChartPeriodLinkListener { - public CpuChartPeriodLinkListener(String statsPeriod) { - super(statsPeriod); - } - - 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); - ServerStats stats = new GlusterServersClient().getAggregatedCpuStats(statsPeriod); - cluster.setAggregatedCpuStats(stats); - return stats; - } - - @Override - public ChartPeriodLinkListener getInstance(String statsPeriod) { - return new CpuChartPeriodLinkListener(statsPeriod, "%", 100, 4); - } - } - - public class NetworkChartPeriodLinkListener extends ChartPeriodLinkListener { - public NetworkChartPeriodLinkListener(String statsPeriod) { - super(statsPeriod); - } - - 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); - ServerStats stats = new GlusterServersClient().getAggregatedNetworkStats(statsPeriod); - cluster.setAggregatedNetworkStats(stats); - return stats; - } - - @Override - public ChartPeriodLinkListener getInstance(String statsPeriod) { - return new NetworkChartPeriodLinkListener(statsPeriod, "KiB/s", -1d, 4); - } - } - - private Composite createChartLinks(Composite section, int columnCount, ChartPeriodLinkListener listener) { - GridLayout layout = new org.eclipse.swt.layout.GridLayout(columnCount, false); - layout.marginBottom = 0; - layout.marginTop = 0; - layout.marginLeft = (CHART_WIDTH - (50*columnCount)) / 2; - Composite graphComposite = toolkit.createComposite(section, SWT.NONE); - graphComposite.setLayout(layout); - GridData data = new GridData(SWT.FILL, SWT.FILL, false, false); - data.widthHint = CHART_WIDTH; - graphComposite.setLayoutData(data); - - createStatsLink(listener, graphComposite, "1 day", GlusterConstants.STATS_PERIOD_1DAY); - createStatsLink(listener, graphComposite, "1 week", GlusterConstants.STATS_PERIOD_1WEEK); - createStatsLink(listener, graphComposite, "1 month", GlusterConstants.STATS_PERIOD_1MONTH); - createStatsLink(listener, graphComposite, "1 year", GlusterConstants.STATS_PERIOD_1YEAR); - - return graphComposite; - } - - private void createStatsLink(ChartPeriodLinkListener listener, Composite parent, String label, String statsPeriod) { - Hyperlink link1 = toolkit.createHyperlink(parent, label, SWT.NONE); - link1.addHyperlinkListener(listener.getInstance(statsPeriod)); - if(listener.getStatsPeriod().equals(statsPeriod)) { - link1.setEnabled(false); - } - } - - 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; - data.verticalAlignment = SWT.CENTER; - chartViewerComposite.setLayoutData(data); - return chartViewerComposite; - } - private void createAlertsSection() { alertsSection = guiHelper.createSection(form, toolkit, "Alerts", null, 1, false); populateAlerts(); @@ -408,30 +285,14 @@ public class ClusterSummaryView extends ViewPart { parent.layout(); // IMP: lays out the form properly } - private Composite createAreaChartSection(ServerStats stats, String sectionTitle, int dataColumnIndex, String unit, String timestampFormat, ChartPeriodLinkListener listener, double maxValue) { + private Composite createAreaChartSection(ServerStats stats, String sectionTitle, int dataColumnIndex, String unit, String timestampFormat, ChartPeriodLinkListener listener, double maxValue, int chartLinkColumnCount) { Composite section = guiHelper.createSection(form, toolkit, sectionTitle, null, 1, false); - - List<Calendar> timestamps = new ArrayList<Calendar>(); - List<Double> data = new ArrayList<Double>(); - 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 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 null; - } - - createAreaChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit, timestampFormat, maxValue); + ChartUtil.getInstance().createAreaChart(toolkit, section, stats, dataColumnIndex, unit, timestampFormat, listener, maxValue, chartLinkColumnCount); // 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), @@ -442,16 +303,17 @@ 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() { IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_CHART_PERIOD); + String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_AGGREGATED_CHART_PERIOD); // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. - cpuChartSection = createAreaChartSection(cluster.getAggregatedCpuStats(), "CPU Usage (Aggregated)", 2, "%", getTimestampFormatForPeriod(cpuStatsPeriod), new CpuChartPeriodLinkListener(cpuStatsPeriod), 100); + cpuChartSection = createAreaChartSection(cluster.getAggregatedCpuStats(), "CPU Usage (Aggregated)", 2, "%", + getTimestampFormatForPeriod(cpuStatsPeriod), chartUtil.new CpuChartPeriodLinkListener(null, + cpuStatsPeriod, toolkit), 100, 4); } private String getTimestampFormatForPeriod(String statsPeriod) { @@ -464,22 +326,14 @@ public class ClusterSummaryView extends ViewPart { } } - private void extractChartData(ServerStats stats, List<Calendar> timestamps, List<Double> data, int dataColumnIndex) { - for(ServerStatsRow row : stats.getRows()) { - Double cpuUsage = row.getUsageData().get(dataColumnIndex); - if(!cpuUsage.isNaN()) { - timestamps.add(new CDateTime(row.getTimestamp() * 1000)); - data.add(cpuUsage); - } - } - } - private void createNetworkUsageSection() { IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD); + String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_AGGREGATED_CHART_PERIOD); // in case of network usage, there are three elements in usage data: received, transmitted and total. we use total. - networkChartSection = createAreaChartSection(cluster.getAggregatedNetworkStats(), "Network Usage (Aggregated)", 2, "KiB/s", getTimestampFormatForPeriod(networkStatsPeriod), new NetworkChartPeriodLinkListener(networkStatsPeriod), -1); + networkChartSection = createAreaChartSection(cluster.getAggregatedNetworkStats(), "Network Usage (Aggregated)", + 2, "KiB/s", getTimestampFormatForPeriod(networkStatsPeriod), + chartUtil.new NetworkChartPeriodLinkListener(null, networkStatsPeriod, toolkit), -1, 4); } private void createRunningTasksSection() { @@ -526,17 +380,15 @@ public class ClusterSummaryView extends ViewPart { } } - 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()) { + private void refreshChartSection(Composite section, ServerStats stats, String statsPeriod, String unit, + double maxValue, int columnCount, ChartPeriodLinkListener linkListener, int dataColumnIndex) { + 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); + chartUtil.createAreaChart(toolkit, section, stats, dataColumnIndex, unit, + getTimestampFormatForPeriod(statsPeriod), linkListener, maxValue, columnCount); 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 b2804fab..43495f31 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 @@ -33,6 +33,8 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -53,6 +55,7 @@ import com.gluster.storage.management.core.model.ClusterListener; import com.gluster.storage.management.core.model.DefaultClusterListener; import com.gluster.storage.management.core.model.Event; import com.gluster.storage.management.core.model.GlusterServer; +import com.gluster.storage.management.core.model.NetworkInterface; import com.gluster.storage.management.core.model.Server.SERVER_STATUS; import com.gluster.storage.management.core.model.ServerStats; import com.gluster.storage.management.core.model.ServerStatsRow; @@ -64,6 +67,7 @@ import com.gluster.storage.management.gui.NetworkInterfaceTableLabelProvider; import com.gluster.storage.management.gui.preferences.PreferenceConstants; import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; import com.gluster.storage.management.gui.utils.ChartUtil; +import com.gluster.storage.management.gui.utils.ChartUtil.ChartPeriodLinkListener; import com.gluster.storage.management.gui.utils.ChartViewerComposite; import com.gluster.storage.management.gui.utils.GUIHelper; import com.ibm.icu.util.Calendar; @@ -77,7 +81,9 @@ public class GlusterServerSummaryView extends ViewPart { private GlusterServer server; private ClusterListener serverChangedListener; private static final int CHART_WIDTH = 350; + private static final int CHART_HEIGHT = 250; private static final Logger logger = Logger.getLogger(GlusterServerSummaryView.class); + private static final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); public enum NETWORK_INTERFACE_TABLE_COLUMN_INDICES { INTERFACE, MODEL, SPEED, IP_ADDRESS, NETMASK, GATEWAY @@ -120,57 +126,10 @@ public class GlusterServerSummaryView extends ViewPart { 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; -// data.verticalAlignment = SWT.CENTER; -// data.grabExcessVerticalSpace = false; -// data.horizontalSpan = 5; -// data.verticalIndent = 0; -// data.verticalSpan = 1; + data.heightHint = CHART_HEIGHT; chartViewerComposite.setLayoutData(data); } - private void createMemoryUsageSection() { - IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); - String memStatsPeriod = preferenceStore.getString(PreferenceConstants.P_MEM_CHART_PERIOD); - - ServerStats stats; - try { - stats = new GlusterServersClient().getMemoryStats(server.getName(), memStatsPeriod); - // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. - //createAreaChartSection(stats, "Memory Usage", 2, "%"); - } catch(Exception e) { - logger.error("Couldn't fetch CPU usage statistics for server [" + server.getName() + "]", e); - return; - } - - Composite section = guiHelper.createSection(form, toolkit, "Memory Usage", null, 1, false); - // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. - ChartUtil chartUtil = ChartUtil.getInstance(); - chartUtil.createAreaChartSection(toolkit, section, stats, 0, "%", chartUtil - .getTimestampFormatForPeriod(memStatsPeriod), - chartUtil.new MemoryChartPeriodLinkListener(server.getName(), memStatsPeriod, toolkit), 100); - } - - private void createNetworkUsageSection() { - Composite section = guiHelper.createSection(form, toolkit, "Network Usage", null, 1, false); - - 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), - new CDateTime(1000l*1310470200), new CDateTime(1000l*1310470500), new CDateTime(1000l*1310470800), new CDateTime(1000l*1310471100), - new CDateTime(1000l*1310471400), new CDateTime(1000l*1310471700), new CDateTime(1000l*1310472000), new CDateTime(1000l*1310472300), - new CDateTime(1000l*1310472600), new CDateTime(1000l*1310472900), new CDateTime(1000l*1310473200), new CDateTime(1000l*1310473500), - new CDateTime(1000l*1310473800) }; - Double[] values = new Double[] { 32d, 31.23d, 27.92d, 48.69d, 58.62d, 49.11d, 72.43d, 69.31d, 87.39d, 78.46d, 60.44d, 56.28d, 33.51d, 27.53d, 12.21, 10d, 21.43d, 36.45d, 34.86d, 35.27d }; - - createAreaChart(section, timestamps, values, "Kib/s"); - - Composite graphComposite = createChartLinks(section, 5); - - CCombo interfaceCombo = new CCombo(graphComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER | SWT.FLAT); - interfaceCombo.setItems(new String[] {"eth0"}); - interfaceCombo.select(0); - } - private void extractChartData(ServerStats stats, List<Calendar> timestamps, List<Double> data, int dataColumnIndex) { for(ServerStatsRow row : stats.getRows()) { Double cpuUsage = row.getUsageData().get(dataColumnIndex); @@ -206,18 +165,69 @@ public class GlusterServerSummaryView extends ViewPart { createChartLinks(section, 4); } + private void createMemoryUsageSection() { + String memStatsPeriod = preferenceStore.getString(PreferenceConstants.P_MEM_CHART_PERIOD); + Composite section = guiHelper.createSection(form, toolkit, "Memory Usage", null, 1, false); + + ServerStats stats; + try { + guiHelper.setStatusMessage("Fetching server memory statistics..."); + stats = new GlusterServersClient().getMemoryStats(server.getName(), memStatsPeriod); + } catch(Exception e) { + logger.error("Couldn't fetch memory usage statistics for server [" + server.getName() + "]", e); + toolkit.createLabel(section, "Couldn't fetch memory usage statistics for server [" + server.getName() + "]! Error: [" + e.getMessage() + "]"); + return; + } + + guiHelper.setStatusMessage("Creating memory chart..."); + // in case of memory usage, there are four elements in usage data: user, free, cache, buffer and total. we use "user". + ChartUtil chartUtil = ChartUtil.getInstance(); + chartUtil.createAreaChart(toolkit, section, stats, 0, "%", chartUtil + .getTimestampFormatForPeriod(memStatsPeriod), + chartUtil.new MemoryChartPeriodLinkListener(server.getName(), memStatsPeriod, toolkit), 100, 4); + guiHelper.setStatusMessage(null); + } + private void createCPUUsageSection() { - IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); String cpuStatsPeriod = preferenceStore.getString(PreferenceConstants.P_CPU_CHART_PERIOD); + Composite section = guiHelper.createSection(form, toolkit, "CPU Usage", null, 1, false); + ServerStats stats; try { - ServerStats stats = new GlusterServersClient().getCpuStats(server.getName(), cpuStatsPeriod); - // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. - createAreaChartSection(stats, "CPU Usage", 2, "%"); + stats = new GlusterServersClient().getCpuStats(server.getName(), cpuStatsPeriod); } catch(Exception e) { logger.error("Couldn't fetch CPU usage statistics for server [" + server.getName() + "]", e); + toolkit.createLabel(section, "Couldn't fetch CPU usage statistics for server [" + server.getName() + "]! Error: [" + e.getMessage() + "]"); return; } + + // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. + ChartUtil chartUtil = ChartUtil.getInstance(); + chartUtil.createAreaChart(toolkit, section, stats, 0, "%", chartUtil + .getTimestampFormatForPeriod(cpuStatsPeriod), + chartUtil.new CpuChartPeriodLinkListener(server.getName(), cpuStatsPeriod, toolkit), 100, 4); + } + + private void createNetworkUsageSection() { + final String networkStatsPeriod = preferenceStore.getString(PreferenceConstants.P_NETWORK_CHART_PERIOD); + final Composite section = guiHelper.createSection(form, toolkit, "Network Usage", null, 1, false); + + String networkInterface = server.getNetworkInterfaces().get(0).getName(); + ServerStats stats; + try { + stats = new GlusterServersClient().getNetworkStats(server.getName(), networkInterface, networkStatsPeriod); + } catch(Exception e) { + logger.error("Couldn't fetch Network usage statistics for server [" + server.getName() + "] network interface [" + networkInterface + "]", e); + toolkit.createLabel(section, "Couldn't fetch CPU usage statistics for server [" + server.getName() + "]! Error: [" + e.getMessage() + "]"); + return; + } + + // in case of network usage, there are three elements in usage data: received, transmitted and total. we use total. + final ChartUtil chartUtil = ChartUtil.getInstance(); + final ChartPeriodLinkListener networkChartPeriodLinkListener = chartUtil.new NetworkChartPeriodLinkListener(server, networkStatsPeriod, toolkit); + Composite graphComposite = chartUtil.createAreaChart(toolkit, section, stats, 2, "%", chartUtil + .getTimestampFormatForPeriod(networkStatsPeriod), + networkChartPeriodLinkListener , -1, 5); } private Composite createChartLinks(Composite section, int columnCount) { |
