Search in sources :

Example 6 with DciData

use of org.netxms.client.datacollection.DciData in project netxms by netxms.

the class HistoricalDataView method deleteDciEntry.

private void deleteDciEntry() {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() == 0)
        return;
    new ConsoleJob("Delete DCI entry", null, Activator.PLUGIN_ID, null) {

        @SuppressWarnings("unchecked")
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            List<DciDataRow> list = selection.toList();
            for (DciDataRow r : list) // Convert back to seconds
            session.deleteDciEntry(nodeId, dciId, r.getTimestamp().getTime() / 1000);
            final DciData data;
            if (subparts != null)
                data = session.getCollectedTableData(nodeId, dciId, instance, column, timeFrom, timeTo, recordLimit);
            else
                data = session.getCollectedData(nodeId, dciId, timeFrom, timeTo, recordLimit, true);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(data.getValues());
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot delete DCI entry";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciDataRow(org.netxms.client.datacollection.DciDataRow) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciData(org.netxms.client.datacollection.DciData) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with DciData

use of org.netxms.client.datacollection.DciData in project netxms by netxms.

the class DataComparisonView method updateChart.

/**
 * Get DCI data from server
 */
private void updateChart() {
    if (updateInProgress)
        return;
    updateInProgress = true;
    ConsoleJob job = new ConsoleJob(Messages.get().DataComparisonView_JobName, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataComparisonView_JobError;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final double[] values = new double[items.size()];
            for (int i = 0; i < items.size(); i++) {
                GraphItem item = items.get(i);
                DciData data = (item.getType() == DataCollectionObject.DCO_TYPE_ITEM) ? session.getCollectedData(item.getNodeId(), item.getDciId(), null, null, 1, false) : session.getCollectedTableData(item.getNodeId(), item.getDciId(), item.getInstance(), item.getDataColumn(), null, null, 1);
                DciDataRow value = data.getLastValue();
                values[i] = (value != null) ? value.getValueAsDouble() : 0.0;
            }
            final Threshold[][] thresholds = new Threshold[items.size()][];
            if (chartType == DataComparisonChart.GAUGE_CHART) {
                for (int i = 0; i < items.size(); i++) {
                    GraphItem item = items.get(i);
                    thresholds[i] = session.getThresholds(item.getNodeId(), item.getDciId());
                }
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (chartType == DataComparisonChart.GAUGE_CHART)
                        for (int i = 0; i < thresholds.length; i++) chart.updateParameterThresholds(i, thresholds[i]);
                    setChartData(values);
                    chart.clearErrors();
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected IStatus createFailureStatus(final Exception e) {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    chart.addError(getErrorMessage() + " (" + e.getLocalizedMessage() + ")");
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciDataRow(org.netxms.client.datacollection.DciDataRow) GraphItem(org.netxms.client.datacollection.GraphItem) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciData(org.netxms.client.datacollection.DciData) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Threshold(org.netxms.client.datacollection.Threshold)

Example 8 with DciData

use of org.netxms.client.datacollection.DciData in project netxms by netxms.

the class HistoricalGraphView method getDataFromServer.

/**
 * Get DCI data from server
 */
private void getDataFromServer() {
    final ChartDciConfig[] dciList = settings.getDciList();
    // Request data from server
    ConsoleJob job = new ConsoleJob(Messages.get().HistoricalGraphView_JobName, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        private ChartDciConfig currentItem;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(getName(), dciList.length);
            final DciData[] data = new DciData[dciList.length];
            final Threshold[][] thresholds = new Threshold[dciList.length][];
            for (int i = 0; i < dciList.length; i++) {
                currentItem = dciList[i];
                if (currentItem.type == ChartDciConfig.ITEM) {
                    data[i] = session.getCollectedData(currentItem.nodeId, currentItem.dciId, settings.getTimeFrom(), settings.getTimeTo(), 0, false);
                    thresholds[i] = session.getThresholds(currentItem.nodeId, currentItem.dciId);
                } else {
                    data[i] = session.getCollectedTableData(currentItem.nodeId, currentItem.dciId, currentItem.instance, currentItem.column, settings.getTimeFrom(), settings.getTimeTo(), 0);
                    thresholds[i] = null;
                }
                monitor.worked(1);
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed()) {
                        chart.setTimeRange(settings.getTimeFrom(), settings.getTimeTo());
                        setChartData(data);
                        chart.clearErrors();
                    }
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().HistoricalGraphView_JobError, session.getObjectName(currentItem.nodeId), currentItem.name);
        }

        @Override
        protected void jobFailureHandler() {
            updateInProgress = false;
            super.jobFailureHandler();
        }

        @Override
        protected IStatus createFailureStatus(final Exception e) {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    chart.addError(getErrorMessage() + " (" + e.getLocalizedMessage() + ")");
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) Widget(org.eclipse.swt.widgets.Widget) DciData(org.netxms.client.datacollection.DciData) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Threshold(org.netxms.client.datacollection.Threshold)

Example 9 with DciData

use of org.netxms.client.datacollection.DciData in project netxms by netxms.

the class PerfTabGraph method refreshData.

/**
 * Refresh graph's data
 */
public void refreshData() {
    if (updateInProgress)
        return;
    updateInProgress = true;
    chart.clearErrors();
    ConsoleJob job = new ConsoleJob(Messages.get().PerfTabGraph_JobTitle, null, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        private PerfTabDci currentDci;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Date from = new Date(System.currentTimeMillis() - timeInterval);
            final Date to = new Date(System.currentTimeMillis());
            synchronized (items) {
                final DciData[] data = new DciData[items.size()];
                for (int i = 0; i < data.length; i++) {
                    currentDci = items.get(i);
                    data[i] = session.getCollectedData(nodeId, currentDci.getId(), from, to, 0, false);
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (!((Widget) chart).isDisposed()) {
                            chart.setTimeRange(from, to);
                            for (int i = 0; i < data.length; i++) chart.updateParameter(i, data[i], true);
                        }
                        updateInProgress = false;
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().PerfTabGraph_JobError, currentDci.getId(), currentDci.getDescription());
        }

        @Override
        protected void jobFailureHandler() {
            updateInProgress = false;
            super.jobFailureHandler();
        }

        @Override
        protected IStatus createFailureStatus(Exception e) {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed())
                        chart.addError(getErrorMessage());
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Widget(org.eclipse.swt.widgets.Widget) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciData(org.netxms.client.datacollection.DciData) PerfTabDci(org.netxms.client.datacollection.PerfTabDci) Date(java.util.Date) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with DciData

use of org.netxms.client.datacollection.DciData in project netxms by netxms.

the class NXCSession method getPredictedData.

/**
 * Get predicted DCI data from server.
 *
 * @param nodeId     Node ID
 * @param dciId      DCI ID
 * @param from       Start of time range
 * @param to         End of time range
 * @return DCI data set
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public DciData getPredictedData(long nodeId, long dciId, Date from, Date to) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_PREDICTED_DATA);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setFieldInt32(NXCPCodes.VID_DCI_ID, (int) dciId);
    DciData data = new DciData(nodeId, dciId);
    int rowsReceived;
    int timeFrom = (int) (from.getTime() / 1000);
    int timeTo = (int) (to.getTime() / 1000);
    do {
        msg.setMessageId(requestId.getAndIncrement());
        msg.setFieldInt32(NXCPCodes.VID_TIME_FROM, timeFrom);
        msg.setFieldInt32(NXCPCodes.VID_TIME_TO, timeTo);
        sendMessage(msg);
        waitForRCC(msg.getMessageId());
        NXCPMessage response = waitForMessage(NXCPCodes.CMD_DCI_DATA, msg.getMessageId());
        if (!response.isBinaryMessage())
            throw new NXCException(RCC.INTERNAL_ERROR);
        rowsReceived = parseDataRows(response.getBinaryData(), data);
        if (rowsReceived == MAX_DCI_DATA_ROWS) {
            // Rows goes in newest to oldest order, so if we need to
            // retrieve additional data, we should update timeTo limit
            DciDataRow row = data.getLastValue();
            if (row != null) {
                // There should be only one value per second, so we set
                // last row's timestamp - 1 second as new boundary
                timeTo = (int) (row.getTimestamp().getTime() / 1000) - 1;
            }
        }
    } while ((rowsReceived == MAX_DCI_DATA_ROWS) && (timeTo > timeFrom));
    return data;
}
Also used : DciDataRow(org.netxms.client.datacollection.DciDataRow) NXCPMessage(org.netxms.base.NXCPMessage) DciData(org.netxms.client.datacollection.DciData) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Aggregations

DciData (org.netxms.client.datacollection.DciData)14 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)7 Date (java.util.Date)6 DciDataRow (org.netxms.client.datacollection.DciDataRow)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 PartInitException (org.eclipse.ui.PartInitException)5 Widget (org.eclipse.swt.widgets.Widget)4 ChartDciConfig (org.netxms.ui.android.main.activities.helpers.ChartDciConfig)3 Point (org.eclipse.swt.graphics.Point)2 NXCPMessage (org.netxms.base.NXCPMessage)2 NXCException (org.netxms.client.NXCException)2 ChartDciConfig (org.netxms.client.datacollection.ChartDciConfig)2 Threshold (org.netxms.client.datacollection.Threshold)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1