diff options
Diffstat (limited to 'src')
2 files changed, 19 insertions, 61 deletions
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 3a9ff740..51b8f4da 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 @@ -24,6 +24,7 @@ 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; @@ -53,9 +54,11 @@ 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; 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.ChartViewerComposite; import com.gluster.storage.management.gui.utils.GUIHelper; import com.ibm.icu.util.Calendar; @@ -246,31 +249,24 @@ public class ClusterSummaryView extends ViewPart { parent.layout(); // IMP: lays out the form properly } - private void createCPUUsageSection() { - ServerStats stats; - try { - stats = new GlusterServersClient().getAggregatedCPUStats(); - } catch(Exception e) { + private void createAreaChartSection(ServerStats stats, String sectionTitle, int dataColumnIndex, String unit) { + Composite section = guiHelper.createSection(form, toolkit, sectionTitle, null, 1, false); + + 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 Please check if all services are running properly on the cluster servers."); return; } - - Composite section = guiHelper.createSection(form, toolkit, "CPU Usage (aggregated)", null, 1, false); + 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; } - List<Calendar> timestamps = new ArrayList<Calendar>(); - List<Double> data = new ArrayList<Double>(); - for(ServerStatsRow row : stats.getRows()) { - // in case of CPU usage, there are three elements in usage data: user, system and total. we use total. - Double cpuUsage = row.getUsageData().get(2); - if(!cpuUsage.isNaN()) { - timestamps.add(new CDateTime(row.getTimestamp() * 1000)); - data.add(cpuUsage); - } - } - createLineChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), "%"); + createLineChart(section, timestamps.toArray(new Calendar[0]), data.toArray(new Double[0]), unit); // 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), @@ -284,6 +280,11 @@ public class ClusterSummaryView extends ViewPart { createChartLinks(section, 4); } + private void createCPUUsageSection() { + // 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, "%"); + } + private void extractChartData(ServerStats stats, List<Calendar> timestamps, List<Double> data, int dataColumnIndex) { for(ServerStatsRow row : stats.getRows()) { Double cpuUsage = row.getUsageData().get(dataColumnIndex); diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java index 609b4f65..e4d37ad8 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java @@ -224,49 +224,6 @@ public class ServerUtil { return (Status) executeOnServer(true, serverName, REMOTE_SCRIPT_GET_DISK_FOR_DIR + " " + brickDir, Status.class); } - public ServerStats fetchCPUUsageData(String serverName) { - Object output = executeOnServer(true, serverName, "get_rrd_cpu_details.py 1d", ServerStats.class); - //String cpuUsageData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <xport> <meta> <start>1310468100</start> <step>300</step> <end>1310471700</end> <rows>13</rows> <columns>3</columns> <legend> <entry>user</entry> <entry>system</entry> <entry>total</entry> </legend> </meta> <data> <row><t>1310468100</t><v>2.23802952e-1</v><v>4.3747778209e-01</v><v>6.6128073384e-01</v></row> <row><t>1310468400</t><v>2.3387347338e-01</v><v>4.4642717442e-01</v><v>6.8030064780e-01</v></row> <row><t>1310468700</t><v>5.5043873220e+00</v><v>6.2462376636e+00</v><v>1.1750624986e+01</v></row> <row><t>1310469000</t><v>2.4350593653e+01</v><v>2.6214585217e+01</v><v>5.0565178869e+01</v></row> <row><t>1310469300</t><v>4.0786489953e+01</v><v>4.6784713828e+01</v><v>8.7571203781e+01</v></row> <row><t>1310469600</t><v>4.1459955508e+01</v><v>5.2546309044e+01</v><v>9.4006264551e+01</v></row> <row><t>1310469900</t><v>4.2312286165e+01</v><v>5.2390588332e+01</v><v>9.4702874497e+01</v></row> <row><t>1310470200</t><v>4.2603794982e+01</v><v>5.1598861493e+01</v><v>9.4202656475e+01</v></row> <row><t>1310470500</t><v>3.8238751290e+01</v><v>4.5312089966e+01</v><v>8.3550841256e+01</v></row> <row><t>1310470800</t><v>1.7949961224e+01</v><v>2.1282058418e+01</v><v>3.9232019642e+01</v></row> <row><t>1310471100</t><v>1.2330371421e-01</v><v>4.6347832868e-01</v><v>5.8678204289e-01</v></row> <row><t>1310471400</t><v>1.6313260492e-01</v><v>5.4088119561e-01</v><v>7.0401380052e-01</v></row> <row><t>1310471700</t><v>NaN</v><v>NaN</v><v>NaN</v></row> </data> </xport>"; - //Object output = unmarshal(ServerStats.class, cpuUsageData, false); - if(output instanceof Status) { - throw new GlusterRuntimeException(((Status)output).toString()); - } - return (ServerStats) output; - } - - private ServerStats getFirstOnlineServerCPUStats(List<String> serverNames, boolean removeServerOnError, boolean removeOnlineServer) { - for(int i = serverNames.size() - 1; i >= 0; i--) { - String serverName = serverNames.get(i); - try { - ServerStats stats = fetchCPUUsageData(serverName); - if(removeOnlineServer) { - serverNames.remove(serverName); - } - return stats; - } catch(Exception e) { - // server might be offline - continue with next one - logger.warn("Couldn't fetch CPU stats from server [" + serverName + "]!", e); - if(removeServerOnError) { - serverNames.remove(serverName); - } - continue; - } - } - throw new GlusterRuntimeException("All servers offline!"); - } - - public ServerStats fetchAggregatedCPUStats(List<String> serverNames) { - if(serverNames == null || serverNames.size() == 0) { - throw new GlusterRuntimeException("No server names passed to fetchAggregaredCPUUsageData!"); - } - - ServerStats firstServerStats = getFirstOnlineServerCPUStats(serverNames, true, true); - - ServerStats aggregatedStats = new ServerStats(firstServerStats); - aggregateCPUStats(serverNames, aggregatedStats); - return aggregatedStats; - } - public static void main(String[] args) { // ServerStats stats = new ServerUtil().fetchCPUUsageData("s1", "1d"); // for(ServerStatsRow row : stats.getRows()) { |
