Search in sources :

Example 1 with StatisticData

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

Example 2 with StatisticData

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;
}
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 3 with StatisticData

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;
}
Also used : SingleHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData) MultiHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem) GetMonitorStatisticDataTask(com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Example 4 with StatisticData

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

Aggregations

StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Day (org.jfree.data.time.Day)2 Hour (org.jfree.data.time.Hour)2 Second (org.jfree.data.time.Second)2 TimeSeries (org.jfree.data.time.TimeSeries)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 MultiHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem)1 SingleHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem)1 StatisticChartHost (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)1 StatisticChartItem (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem)1 MetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType)1 StatisticType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType)1 TimeType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType)1 GetMonitorStatisticDataTask (com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask)1 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)1