Search in sources :

Example 6 with MetricType

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;
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) Hour(org.jfree.data.time.Hour) MetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType) ArrayList(java.util.ArrayList) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData) Date(java.util.Date) TimeType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType) Second(org.jfree.data.time.Second) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day)

Example 7 with MetricType

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();
}
Also used : StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) DbMetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.DbMetricType) MetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType) OsMetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.OsMetricType)

Aggregations

MetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType)7 StatisticType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType)2 TimeType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType)2 SingleHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem)1 StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)1 DbMetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.DbMetricType)1 OsMetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.OsMetricType)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Day (org.jfree.data.time.Day)1 Hour (org.jfree.data.time.Hour)1 Second (org.jfree.data.time.Second)1