Search in sources :

Example 1 with DciDataRow

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

the class NXCSession method getCollectedDataInternal.

/**
 * Get collected DCI data from server. Please note that you should specify
 * either row count limit or time from/to limit.
 *
 * @param nodeId     Node ID
 * @param dciId      DCI ID
 * @param instance   instance value (for table DCI only)
 * @param dataColumn name of column to retrieve data from (for table DCI only)
 * @param from       Start of time range or null for no limit
 * @param to         End of time range or null for no limit
 * @param maxRows    Maximum number of rows to retrieve or 0 for no limit
 * @param includeRawValues if true raw DCI values will be included into set
 * @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
 */
private DciData getCollectedDataInternal(long nodeId, long dciId, String instance, String dataColumn, Date from, Date to, int maxRows, boolean includeRawValues) throws IOException, NXCException {
    NXCPMessage msg;
    if (// table DCI
    instance != null) {
        msg = newMessage(NXCPCodes.CMD_GET_TABLE_DCI_DATA);
        msg.setField(NXCPCodes.VID_INSTANCE, instance);
        msg.setField(NXCPCodes.VID_DATA_COLUMN, dataColumn);
    } else {
        msg = newMessage(NXCPCodes.CMD_GET_DCI_DATA);
    }
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setFieldInt32(NXCPCodes.VID_DCI_ID, (int) dciId);
    msg.setField(NXCPCodes.VID_INCLUDE_RAW_VALUES, includeRawValues);
    DciData data = new DciData(nodeId, dciId);
    int rowsReceived, rowsRemaining = maxRows;
    int timeFrom = (from != null) ? (int) (from.getTime() / 1000) : 0;
    int timeTo = (to != null) ? (int) (to.getTime() / 1000) : 0;
    do {
        msg.setMessageId(requestId.getAndIncrement());
        msg.setFieldInt32(NXCPCodes.VID_MAX_ROWS, maxRows);
        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 (((rowsRemaining == 0) || (rowsRemaining > MAX_DCI_DATA_ROWS)) && (rowsReceived == MAX_DCI_DATA_ROWS)) {
            // adjust boundaries for next request
            if (rowsRemaining > 0)
                rowsRemaining -= rowsReceived;
            // retrieve additional data, we should update timeTo limit
            if (to != null) {
                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);
    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)

Example 2 with DciDataRow

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

the class LineChart method updateParameter.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.charts.api.HistoricalDataChart#updateParameter(int, org.netxms.client.datacollection.DciData, boolean)
	 */
@Override
public void updateParameter(int index, DciData data, boolean updateChart) {
    if ((index < 0) || (index >= items.size()))
        return;
    final GraphItem item = items.get(index);
    final DciDataRow[] values = data.getValues();
    // Create series
    Date[] xSeries = new Date[values.length];
    double[] ySeries = new double[values.length];
    for (int i = 0; i < values.length; i++) {
        xSeries[i] = values[i].getTimestamp();
        ySeries[i] = values[i].getValueAsDouble();
    }
    ILineSeries series = addLineSeries(index, item.getDescription(), xSeries, ySeries, updateChart);
    applyItemStyle(index, series);
    if (updateChart) {
        if (adjustYAxis) {
            adjustYAxis(true);
        } else {
            redraw();
        }
    }
}
Also used : DciDataRow(org.netxms.client.datacollection.DciDataRow) ILineSeries(org.swtchart.ILineSeries) GraphItem(org.netxms.client.datacollection.GraphItem) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) DataPoint(org.netxms.ui.eclipse.charts.api.DataPoint)

Example 3 with DciDataRow

use of org.netxms.client.datacollection.DciDataRow 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 4 with DciDataRow

use of org.netxms.client.datacollection.DciDataRow 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 5 with DciDataRow

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

the class HistoricalDataComparator method compare.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
    */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    TableColumn sortColumn = ((TableViewer) viewer).getTable().getSortColumn();
    if (sortColumn == null)
        return 0;
    int rc;
    switch((Integer) sortColumn.getData("ID")) {
        case HistoricalDataView.COLUMN_TIME:
            rc = Long.signum(((DciDataRow) e1).getTimestamp().getTime() - ((DciDataRow) e2).getTimestamp().getTime());
            break;
        case HistoricalDataView.COLUMN_DATA:
            rc = NaturalOrderComparator.compare(((DciDataRow) e1).getValueAsString(), ((DciDataRow) e2).getValueAsString());
            break;
        default:
            rc = 0;
            break;
    }
    int dir = (((TableViewer) viewer).getTable().getSortDirection());
    return (dir == SWT.UP) ? rc : -rc;
}
Also used : DciDataRow(org.netxms.client.datacollection.DciDataRow) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

DciDataRow (org.netxms.client.datacollection.DciDataRow)10 DciData (org.netxms.client.datacollection.DciData)6 Date (java.util.Date)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 PartInitException (org.eclipse.ui.PartInitException)3 AccessPoint (org.netxms.client.objects.AccessPoint)3 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 DateFormat (java.text.DateFormat)2 List (java.util.List)2 Point (org.eclipse.swt.graphics.Point)2 NXCPMessage (org.netxms.base.NXCPMessage)2 GraphItem (org.netxms.client.datacollection.GraphItem)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 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1