use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticData in project cubrid-manager by CUBRID.
the class MonitorStatisticChart method buildInvalidData.
/**
* Build TimeSeries for StatisticData which has no data. After build, each
* TimeSeries accompany with the StatisticData will have the same time
* series with ordinary TimeSeries, but all the values will be -1.
*
* @param dataset
* @param timeType
* @param dataItemWithoutDataList
* @param current
* @param interalMillisecs
*/
private void buildInvalidData(TimeSeriesCollection dataset, TimeType timeType, List<StatisticData> dataItemWithoutDataList, Date current, long interalMillisecs) {
for (StatisticData statisticData : dataItemWithoutDataList) {
TimeSeries series = null;
if (isDetailView) {
series = new TimeSeries(statisticData.getDescription(isMultiHost));
} else {
series = new TimeSeries(statisticData.getSimpleDescription(isMultiHost));
}
Date point = (Date) current.clone();
long curMillisecs = current.getTime();
for (int i = 0; i < dataSize; i++) {
point.setTime(curMillisecs - (dataSize - i) * interalMillisecs);
switch(timeType) {
case DAILY:
series.add(new Second(point), -1);
break;
case WEEKLY:
series.add(new Hour(point), -1);
break;
case MONTHLY:
series.add(new Hour(point), -1);
break;
case YEARLY:
series.add(new Day(point), -1);
break;
default:
break;
}
}
maxValueMap.put(statisticData, -1d);
minValueMap.put(statisticData, -1d);
dataset.addSeries(series);
}
}
use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticData in project cubrid-manager by CUBRID.
the class MonitorStatisticChart method createDataset.
private XYDataset createDataset() {
TimeSeriesCollection dataset = new TimeSeriesCollection();
if (statisticDataList == null) {
return dataset;
}
double maxForRang = 0;
List<StatisticData> dataItemWithoutDataList = new ArrayList<StatisticData>();
TimeType timeType = null;
Date current = new Date();
long interalMillisecs = 0;
for (StatisticData statisticData : statisticDataList) {
if (statisticData == null) {
continue;
}
MetricType metricType = MetricType.getEnumByMetric(statisticData.getMetric());
if (metricType == null) {
continue;
}
int size = statisticData.getData().size();
if (size == 0) {
dataItemWithoutDataList.add(statisticData);
continue;
} else if (dataSize == 0) {
//record data size for build invalid data
dataSize = size;
}
//check data type, record 'isHasValidData = true'
if (!isHasValidData) {
isHasValidData = true;
chartType = getChartType(statisticData.getMetric());
if (chartType == ChartType.PERCENT) {
rangMax = 100;
}
String dateType = statisticData.getDtype();
timeType = TimeType.getEnumByType(dateType);
//CMS return -1 for invalid data, so for invalid data(<0), display as -1.
switch(timeType) {
case DAILY:
interalMillisecs = 1000 * 60 * 60 * 24 / size;
break;
case WEEKLY:
interalMillisecs = 1000 * 60 * 60;
break;
case MONTHLY:
interalMillisecs = 1000 * 60 * 60;
break;
case YEARLY:
interalMillisecs = 1000 * 60 * 60 * 24;
break;
default:
break;
}
}
TimeSeries series = null;
if (isDetailView) {
series = new TimeSeries(statisticData.getDescription(isMultiHost));
} else {
series = new TimeSeries(statisticData.getSimpleDescription(isMultiHost));
}
Date point = (Date) current.clone();
long curMillisecs = current.getTime();
int count = 0;
int max = 0;
int min = 0;
boolean isInitMinVal = false;
for (int val : statisticData.getData()) {
point.setTime(curMillisecs - (size - count) * interalMillisecs);
switch(timeType) {
case DAILY:
if (val < 0) {
series.add(new Second(point), -1);
} else {
series.add(new Second(point), val / 100);
}
break;
case WEEKLY:
if (val < 0) {
series.add(new Hour(point), -1);
} else {
series.add(new Hour(point), val / 100);
}
break;
case MONTHLY:
if (val < 0) {
series.add(new Hour(point), -1);
} else {
series.add(new Hour(point), val / 100);
}
break;
case YEARLY:
if (val < 0) {
series.add(new Day(point), -1);
} else {
series.add(new Day(point), val / 100);
}
break;
default:
break;
}
if (chartType != ChartType.PERCENT && val > maxForRang) {
maxForRang = val;
}
if (!isInitMinVal && val >= 0) {
min = val;
isInitMinVal = true;
}
if (val > max) {
max = val;
}
if (val < min && val >= 0) {
min = val;
}
count++;
}
maxValueMap.put(statisticData, max / 100d);
minValueMap.put(statisticData, min / 100d);
dataset.addSeries(series);
}
if (!isHasValidData) {
return dataset;
}
if (chartType != ChartType.PERCENT) {
decideRangMax(maxForRang / 100);
}
/*[TOOLS-3742] Build invalid data for StatisticData which has no data*/
buildInvalidData(dataset, timeType, dataItemWithoutDataList, current, interalMillisecs);
if (isDetailView) {
chartTitle = Messages.monStatisticDetailChartTitle;
timeAxisLabel = Messages.lblChartTime;
valueAxisLabel = Messages.lblChartValue;
switch(chartType) {
case PERCENT:
valueAxisLabel += " (%)";
break;
case MEMORY:
case SPACE:
valueAxisLabel += " (MB)";
break;
case OTHERS:
break;
default:
break;
}
}
return dataset;
}
use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticData in project cubrid-manager by CUBRID.
the class LoadMonitorStatisticDataProgress method run.
/* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (statisticItemList == null) {
success = false;
return;
}
if (isMultiHost) {
for (StatisticChartItem chartItem : statisticItemList) {
if (!(chartItem instanceof MultiHostChartItem)) {
statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
continue;
}
MultiHostChartItem item = (MultiHostChartItem) chartItem;
if (item.getHostList() == null || item.getHostList().size() == 0) {
statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
continue;
}
List<StatisticData> dataList = new ArrayList<StatisticData>();
for (StatisticChartHost host : item.getHostList()) {
//build ServerInfo
ServerInfo serverInfo = buildServerInfo(host);
StatisticData statisticData = new StatisticData();
statisticData.setServerInfo(serverInfo);
GetMonitorStatisticDataTask<StatisticData> getStatisticDatatask = new GetMonitorStatisticDataTask<StatisticData>(serverInfo, StatisticParamUtil.getSendMsgItems(item.getType()), statisticData);
getStatisticDatatask.setMetric(host.getMetric());
getStatisticDatatask.setDateType(item.getDType());
/*[TOOLS-3742] Initial StatisticData for GetMonitorStatisticDataTask failure*/
statisticData.setMetric(host.getMetric());
statisticData.setDtype(item.getDType());
switch(item.getType()) {
case DB:
getStatisticDatatask.setDbName(host.getDbName());
statisticData.setDbName(host.getDbName());
break;
case DB_VOL:
getStatisticDatatask.setDbName(host.getDbName());
getStatisticDatatask.setVolName(host.getVolName());
statisticData.setDbName(host.getDbName());
statisticData.setVolName(host.getVolName());
break;
case BROKER:
getStatisticDatatask.setBrokerName(host.getBrokerName());
statisticData.setbName(host.getBrokerName());
break;
case OS:
break;
default:
break;
}
if (!serverInfo.isConnected()) {
disconnectedServerSet.add(serverInfo);
MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
serverInfo = monitoringTask.connectServer(Version.releaseVersion, 1000);
}
if (serverInfo.isConnected()) {
addServer(serverInfo);
getStatisticDatatask.execute();
if (getStatisticDatatask.isSuccess()) {
statisticData = getStatisticDatatask.getResultModel();
dataList.add(statisticData);
} else {
dataList.add(statisticData);
}
} else {
removeServer(serverInfo);
dataList.add(statisticData);
}
}
statisticDataMap.put(chartItem, dataList);
}
tearDownDisconnectedServer();
} else {
//for single host
for (StatisticChartItem chartItem : statisticItemList) {
if (!(chartItem instanceof SingleHostChartItem)) {
statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
continue;
}
SingleHostChartItem item = (SingleHostChartItem) chartItem;
if (item.getMetricList() == null || item.getMetricList().size() == 0) {
statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
continue;
}
List<StatisticData> dataList = new ArrayList<StatisticData>();
for (int i = 0; i < item.getMetricList().size(); i++) {
String metric = item.getMetricList().get(i);
StatisticData statisticData = new StatisticData();
statisticData.setServerInfo(serverInfo);
GetMonitorStatisticDataTask<StatisticData> task = new GetMonitorStatisticDataTask<StatisticData>(serverInfo, StatisticParamUtil.getSendMsgItems(item.getType()), statisticData);
task.setMetric(metric);
task.setDateType(item.getDType());
statisticData.setMetric(metric);
statisticData.setDtype(item.getDType());
switch(item.getType()) {
case DB:
task.setDbName(item.getDbName());
statisticData.setDbName(item.getDbName());
break;
case DB_VOL:
task.setDbName(item.getDbName());
task.setVolName(item.getVolName());
statisticData.setDbName(item.getDbName());
statisticData.setVolName(item.getVolName());
break;
case BROKER:
task.setBrokerName(item.getBrokerName());
statisticData.setbName(item.getBrokerName());
break;
case OS:
break;
default:
break;
}
task.execute();
if (task.isSuccess()) {
statisticData = task.getResultModel();
dataList.add(statisticData);
} else if (task.getErrorMsg() != null && (task.getErrorMsg().indexOf("invalid token") != -1 || !serverInfo.isConnected())) {
/*[TOOLS-3742] when invalid token or connect server failure, give out error message*/
errorMsg = task.getErrorMsg();
//build StatisticData with no data
for (; i < item.getMetricList().size(); i++) {
String metric2 = item.getMetricList().get(i);
StatisticData data = (StatisticData) statisticData.clone();
data.setMetric(metric2);
dataList.add(data);
}
break;
}
}
statisticDataMap.put(chartItem, dataList);
}
}
success = true;
}
use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticData in project cubrid-manager by CUBRID.
the class GetMonitorStatisticDataTaskTest method testExecute.
public void testExecute() {
StatisticType type = StatisticType.OS;
StatisticData statisticData = new StatisticData();
GetMonitorStatisticDataTask<StatisticData> task = new GetMonitorStatisticDataTask<StatisticData>(serverInfo930, StatisticParamUtil.getSendMsgItems(type), statisticData);
String metric = MetricType.OS_CPU_USER.getMetric();
String dType = TimeType.WEEKLY.getType();
task.setMetric(metric);
task.setDateType(dType);
statisticData.setMetric(metric);
statisticData.setDtype(dType);
task.execute();
assertNull(task.getErrorMsg());
statisticData = task.getResultModel();
assertNotNull(statisticData);
assertNotNull(statisticData.getData());
assertTrue(statisticData.getData().size() > 0);
}
Aggregations