Search in sources :

Example 1 with CounterFile

use of com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile in project cubrid-manager by CUBRID.

the class HistoryFileHelp method createOrOpenHistoryFile.

/**
	 * 
	 * Create or Open a history file when the history data should be restored.
	 * 
	 * @param typeNames the array of type names
	 * @return the instance of CounterFile
	 */
private CounterFile createOrOpenHistoryFile(String[] typeNames) {
    File counter = new File(historyPath);
    if (counter.exists() && counter.isFile()) {
        try {
            countFile = new BasicCounterFile(counter, null);
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    } else {
        List<CounterType> counterLst = new ArrayList<CounterType>();
        for (String type : typeNames) {
            CounterType counterType = new CounterType(type, true, false, RangeType.INT);
            counterLst.add(counterType);
        }
        CounterType[] types = counterLst.toArray(new CounterType[counterLst.size()]);
        Properties props = new Properties();
        try {
            countFile = new BasicCounterFile(counter, types, maxCount, interval, 0, props);
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    return countFile;
}
Also used : CounterType(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterType) BasicCounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) CounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile) BasicCounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile)

Example 2 with CounterFile

use of com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile in project cubrid-manager by CUBRID.

the class BrokerStatusHistoryViewPart method createPartControl.

/**
	 * Creates the SWT controls for this workbench part.
	 * 
	 * @param parent the parent control
	 * @see IWorkbenchPart
	 */
public void createPartControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.RESIZE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final HistoryComposite historyComposite = new HistoryComposite();
    historyComposite.loadTimeSelection(composite);
    Label sepWithResult = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_OUT);
    sepWithResult.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    BrokerDiagData brokerDiagData = new BrokerDiagData();
    ICubridNode selection = getCubridNode();
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    isNewBrokerDiag = CompatibleUtil.isNewBrokerDiag(serverInfo);
    TreeMap<String, String> map = convertMapKey(brokerDiagData.getDiagStatusResultMap());
    chartPart = new ChartCompositePart(composite, map);
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        ShowSetting showSetting = chartPart.getSettingMap().get(key);
        ShowSettingMatching.match(key, showSetting, MonitorType.BROKER, isNewBrokerDiag);
    }
    chartPart.setChartTitle(Messages.brokerHistoryChartTtl);
    String hostAddress = serverInfo.getHostAddress();
    int monPort = serverInfo.getHostMonPort();
    String historyFileName = HistoryComposite.BROKER_HISTORY_FILE_PREFIX + hostAddress + "_" + monPort + HistoryComposite.HISTORY_SUFFIX;
    chartPart.setHistoryFileName(historyFileName);
    IPath historyPath = CubridManagerCorePlugin.getDefault().getStateLocation();
    String sHistoryPath = historyPath.toOSString() + File.separator + historyFileName;
    chartPart.setHistoryPath(sHistoryPath);
    chartPart.loadContent();
    chartPart.addChartMouseListener();
    makeActions();
    historyComposite.getQueryBtn().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            String date = historyComposite.getDate();
            String fromTime = historyComposite.getFromTime();
            String toTime = historyComposite.getToTime();
            // check date/fromTime/toTime
            boolean timeOrder = historyComposite.checkTime(date, fromTime, toTime);
            if (!timeOrder) {
                CommonUITool.openErrorBox(Messages.errBrokerHistorySettingTime);
                return;
            }
            String[] ymd = date.split("-");
            int year = Integer.valueOf(ymd[0]);
            int month = Integer.valueOf(ymd[1]);
            int day = Integer.valueOf(ymd[2]);
            String[] fromHms = fromTime.split(":");
            int fromHour = Integer.valueOf(fromHms[0]);
            int fromMinute = Integer.valueOf(fromHms[1]);
            int fromSecond = Integer.valueOf(fromHms[2]);
            Calendar calFrom = Calendar.getInstance();
            calFrom.set(year, month, day, fromHour, fromMinute, fromSecond);
            final long millisFrom = calFrom.getTimeInMillis();
            String[] toHms = toTime.split(":");
            int toHour = Integer.valueOf(toHms[0]);
            int toMinute = Integer.valueOf(toHms[1]);
            int toSecond = Integer.valueOf(toHms[2]);
            Calendar calTo = Calendar.getInstance();
            calTo.set(year, month, day, toHour, toMinute, toSecond);
            final long millisTo = calTo.getTimeInMillis();
            XYPlot plot = (XYPlot) chartPart.getChart().getPlot();
            plot.getDomainAxis().setRange(millisFrom, millisTo);
            final CounterFile countFile = chartPart.openHistoryFile();
            if (countFile == null) {
                return;
            }
            final List<String> types = new ArrayList<String>();
            for (BrokerDiagEnum enumeration : BrokerDiagEnum.values()) {
                String type = enumeration.getName();
                types.add(type);
            }
            chartPart.executeQueryWithBusyCursor(countFile, types, millisFrom, millisTo);
            try {
                countFile.close();
            } catch (IOException e1) {
                LOGGER.error(e1.getMessage());
            }
        }

        public void widgetSelected(SelectionEvent ex) {
            widgetDefaultSelected(ex);
        }
    });
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Label(org.eclipse.swt.widgets.Label) BrokerDiagEnum(com.cubrid.cubridmanager.core.monitoring.model.BrokerDiagEnum) GridLayout(org.eclipse.swt.layout.GridLayout) ShowSetting(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ChartCompositePart(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart) ArrayList(java.util.ArrayList) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) HistoryComposite(com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite) IPath(org.eclipse.core.runtime.IPath) Calendar(java.util.Calendar) BrokerDiagData(com.cubrid.cubridmanager.core.monitoring.model.BrokerDiagData) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IOException(java.io.IOException) HistoryComposite(com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite) XYPlot(org.jfree.chart.plot.XYPlot) CounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile) GridData(org.eclipse.swt.layout.GridData) Map(java.util.Map) TreeMap(java.util.TreeMap) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with CounterFile

use of com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile in project cubrid-manager by CUBRID.

the class DbStatusHistoryViewPart method createPartControl.

/**
	 * Creates the SWT controls for this workbench part.
	 * 
	 * @param parent the parent control
	 * @see IWorkbenchPart
	 */
public void createPartControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.RESIZE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final HistoryComposite historyComposite = new HistoryComposite();
    historyComposite.loadTimeSelection(composite);
    serverInfo = cubridNode.getServer().getServerInfo();
    Label sepWithResult = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_OUT);
    sepWithResult.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    DbStatDumpData dbStatDumpData = new DbStatDumpData();
    TreeMap<String, String> map = new TreeMap<String, String>();
    for (Map.Entry<IDiagPara, String> entry : dbStatDumpData.getDiagStatusResultMap().entrySet()) {
        map.put(entry.getKey().getName(), entry.getValue());
    }
    chartPart = new ChartCompositePart(composite, map);
    dbCombo = new DbComboContribution("database");
    List<String> databaseLst = new ArrayList<String>();
    List<DatabaseInfo> databaseInfoLst = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
    if (null != databaseInfoLst && !databaseInfoLst.isEmpty()) {
        for (DatabaseInfo databaseInfo : databaseInfoLst) {
            databaseLst.add(databaseInfo.getDbName());
        }
        dbCombo.setDatabaseLst(databaseLst);
        if (!databaseLst.isEmpty()) {
            dbCombo.setSelectedDb(databaseLst.get(0));
        }
    }
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        ShowSetting showSetting = chartPart.getSettingMap().get(key);
        ShowSettingMatching.match(key, showSetting, MonitorType.DATABASE);
    }
    chartPart.setChartTitle(Messages.databaseHistoryChartTtl);
    String dbName = dbCombo.getSelectedDb();
    String hostAddress = serverInfo.getHostAddress();
    int monPort = serverInfo.getHostMonPort();
    String historyFileName = HistoryComposite.DB_HISTORY_FILE_PREFIX + dbName + "@" + hostAddress + "_" + monPort + HistoryComposite.HISTORY_SUFFIX;
    chartPart.setHistoryFileName(historyFileName);
    IPath historyPath = CubridManagerCorePlugin.getDefault().getStateLocation();
    String sHistoryPath = historyPath.toOSString() + File.separator + historyFileName;
    chartPart.setHistoryPath(sHistoryPath);
    chartPart.loadContent();
    chartPart.addChartMouseListener();
    makeActions();
    historyComposite.getQueryBtn().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            String date = historyComposite.getDate();
            String fromTime = historyComposite.getFromTime();
            String toTime = historyComposite.getToTime();
            // check date/fromTime/toTime
            boolean timeOrder = historyComposite.checkTime(date, fromTime, toTime);
            if (!timeOrder) {
                CommonUITool.openErrorBox(Messages.errDbHistorySettingTime);
                return;
            }
            String[] ymd = date.split("-");
            int year = Integer.valueOf(ymd[0]);
            int month = Integer.valueOf(ymd[1]);
            int day = Integer.valueOf(ymd[2]);
            String[] fromHms = fromTime.split(":");
            int fromHour = Integer.valueOf(fromHms[0]);
            int fromMinute = Integer.valueOf(fromHms[1]);
            int fromSecond = Integer.valueOf(fromHms[2]);
            Calendar calFrom = Calendar.getInstance();
            calFrom.set(year, month, day, fromHour, fromMinute, fromSecond);
            long millisFrom = calFrom.getTimeInMillis();
            String[] toHms = toTime.split(":");
            int toHour = Integer.valueOf(toHms[0]);
            int toMinute = Integer.valueOf(toHms[1]);
            int toSecond = Integer.valueOf(toHms[2]);
            Calendar calTo = Calendar.getInstance();
            calTo.set(year, month, day, toHour, toMinute, toSecond);
            long millisTo = calTo.getTimeInMillis();
            XYPlot plot = (XYPlot) chartPart.getChart().getPlot();
            plot.getDomainAxis().setRange(millisFrom, millisTo);
            CounterFile countFile = chartPart.openHistoryFile();
            if (countFile == null) {
                return;
            }
            List<String> types = new ArrayList<String>();
            for (DbStatDumpEnum diagName : DbStatDumpEnum.values()) {
                String type = diagName.getName();
                types.add(type);
            }
            chartPart.executeQueryWithBusyCursor(countFile, types, millisFrom, millisTo);
            try {
                countFile.close();
            } catch (IOException e1) {
                LOGGER.error(e1.getMessage());
            }
        }

        public void widgetSelected(SelectionEvent ex) {
            widgetDefaultSelected(ex);
        }
    });
}
Also used : DbStatDumpData(com.cubrid.cubridmanager.core.monitoring.model.DbStatDumpData) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) IDiagPara(com.cubrid.cubridmanager.core.monitoring.model.IDiagPara) GridLayout(org.eclipse.swt.layout.GridLayout) ShowSetting(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ChartCompositePart(com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart) ArrayList(java.util.ArrayList) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) HistoryComposite(com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite) IPath(org.eclipse.core.runtime.IPath) Calendar(java.util.Calendar) IOException(java.io.IOException) TreeMap(java.util.TreeMap) HistoryComposite(com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite) DbStatDumpEnum(com.cubrid.cubridmanager.core.monitoring.model.DbStatDumpEnum) XYPlot(org.jfree.chart.plot.XYPlot) CounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile) GridData(org.eclipse.swt.layout.GridData) Map(java.util.Map) TreeMap(java.util.TreeMap) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with CounterFile

use of com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile in project cubrid-manager by CUBRID.

the class ChartCompositePart method storageData.

/**
	 *
	 * Storage the data into the local file.
	 *
	 * @param <T> the generic type which is the sub type of IDiagPara
	 * @param updateMap a instance of TreeMap which include all the data that
	 *        will be storage.
	 * @param ts a generic array, for instance
	 *        BrokerDiagEnum.values(),DbStatDumpEnum.values()
	 * @param dbName the database name, this value can be set null
	 */
public <T extends IDiagPara> void storageData(Map<String, String> updateMap, T[] ts, String dbName) {
    CounterFile countFile = getHistoryFile(ts, dbName);
    long time = System.currentTimeMillis();
    for (T diagName : ts) {
        try {
            String type = diagName.getName();
            long value = Long.valueOf(updateMap.get(diagName.getName()));
            if (dbName != null) {
                type = dbName + "_" + type;
            }
            countFile.updateData(time, type, value);
        } catch (NumberFormatException e) {
            LOGGER.error(e.getMessage());
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : SWT(org.eclipse.swt.SWT) CounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile) BasicCounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile) IOException(java.io.IOException)

Example 5 with CounterFile

use of com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile in project cubrid-manager by CUBRID.

the class ChartCompositePart method createOrOpenHistoryFile.

/**
	 * Create or Open a history file when the history data should be restored.
	 *
	 *
	 * @param <T> the generic type which is the sub type of IDiagPara
	 * @param ts the instance of generic array
	 * @param dbName the database name
	 * @return the instance of CounterFile
	 */
private <T extends IDiagPara> CounterFile createOrOpenHistoryFile(T[] ts, String dbName) {
    File counter = new File(historyPath);
    if (counter.exists() && counter.isFile()) {
        try {
            countFile = new BasicCounterFile(counter, null);
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    } else {
        List<CounterType> counterLst = new ArrayList<CounterType>();
        for (T diagName : ts) {
            String type = diagName.getName();
            if (dbName != null) {
                type = dbName + "_" + type;
            }
            CounterType counterType = new CounterType(type, true, false, RangeType.INT);
            counterLst.add(counterType);
        }
        CounterType[] types = counterLst.toArray(new CounterType[counterLst.size()]);
        Properties props = new Properties();
        try {
            countFile = new BasicCounterFile(counter, types, 36000, 3, 0, props);
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
    return countFile;
}
Also used : CounterType(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterType) SWT(org.eclipse.swt.SWT) BasicCounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) CounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile) File(java.io.File) BasicCounterFile(com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile)

Aggregations

CounterFile (com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterFile)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 BasicCounterFile (com.cubrid.cubridmanager.ui.monitoring.editor.count.BasicCounterFile)3 CounterType (com.cubrid.cubridmanager.ui.monitoring.editor.count.CounterType)2 ChartCompositePart (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart)2 HistoryComposite (com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite)2 ShowSetting (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting)2 File (java.io.File)2 Calendar (java.util.Calendar)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 TreeMap (java.util.TreeMap)2 IPath (org.eclipse.core.runtime.IPath)2 SWT (org.eclipse.swt.SWT)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2