use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType 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.StatisticParamUtil.MetricType in project cubrid-manager by CUBRID.
the class StatisticParamUtilTest method testStatisticParamUtil.
public void testStatisticParamUtil() {
assertNotNull(StatisticParamUtil.getDateTypes());
for (StatisticType type : StatisticType.values()) {
assertNotNull(type.getMessage());
assertNotNull(type.getMetricTypeSet());
assertNotNull(StatisticParamUtil.getSendMsgItems(type));
assertNotNull(StatisticParamUtil.getSupportedMetricTypes(type));
switch(type) {
case DB:
assertEquals(StatisticType.getEnumByMessage(Messages.msgDataDb), type);
break;
case DB_VOL:
assertEquals(StatisticType.getEnumByMessage(Messages.msgDataDbVol), type);
break;
case BROKER:
assertEquals(StatisticType.getEnumByMessage(Messages.msgDataBroker), type);
break;
case OS:
assertEquals(StatisticType.getEnumByMessage(Messages.msgDataOs), type);
break;
default:
}
for (MetricType metric : MetricType.values()) {
switch(type) {
case DB:
if (metric.getMetric().startsWith("db")) {
assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
} else {
assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
}
break;
case DB_VOL:
if (metric.getMetric().startsWith("vol")) {
assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
} else {
assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
}
break;
case BROKER:
if (metric.getMetric().startsWith("broker")) {
assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
} else {
assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
}
break;
case OS:
if (metric.getMetric().startsWith("os")) {
assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
} else {
assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
}
break;
default:
}
}
}
for (MetricType metric : MetricType.values()) {
assertNotNull(metric.getMessage());
assertNotNull(metric.getMetric());
assertNotNull(metric.getChartName());
assertEquals(MetricType.getEnumByMessage(metric.getMessage()), metric);
assertEquals(MetricType.getEnumByMetric(metric.getMetric()), metric);
Set<MetricType> metricSet = StatisticParamUtil.getCompatibleMetricsForDisplay(metric.getMetric());
assertNotNull(metricSet);
MetricType metric2 = metricSet.iterator().next();
assertTrue(StatisticParamUtil.isCompatibleMetricForDisplay(metric.getMetric(), metric2.getMetric()));
if (metric.getMetric().startsWith("db")) {
assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.DB);
assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.DB);
} else if (metric.getMetric().startsWith("vol")) {
assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.DB_VOL);
assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.DB_VOL);
} else if (metric.getMetric().startsWith("broker")) {
assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.BROKER);
assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.BROKER);
} else {
assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.OS);
assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.OS);
}
if (metric.getMetric().indexOf("cpu") > -1 || metric.getMetric().indexOf("ratio") > -1) {
assertTrue(StatisticParamUtil.isPercentageData(metric.getMetric()));
} else {
assertFalse(StatisticParamUtil.isPercentageData(metric.getMetric()));
}
if (metric.getMetric().indexOf("mem") > -1) {
assertTrue(StatisticParamUtil.isMemoryData(metric.getMetric()));
} else {
assertFalse(StatisticParamUtil.isMemoryData(metric.getMetric()));
}
if (metric.getMetric().indexOf("freespace") > -1 || metric.getMetric().indexOf("disk") > -1) {
assertTrue(StatisticParamUtil.isDiskData(metric.getMetric()));
} else {
assertFalse(StatisticParamUtil.isDiskData(metric.getMetric()));
}
}
testTimeType();
testDbMetricType();
testOsMetricType();
}
Aggregations