Search in sources :

Example 1 with DciData

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

the class PieChartElement method refresh.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
	 */
@Override
public void refresh() {
    final ChartDciConfig[] items = config.getDciList();
    if (items.length == 0)
        return;
    try {
        final DciData[] dciData = new DciData[items.length];
        for (int i = 0; i < dciData.length; i++) {
            dciData[i] = new DciData(0, 0);
            dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, null, null, 1);
        }
        post(new Runnable() {

            @Override
            public void run() {
                for (int i = 0; i < dciData.length; i++) {
                    dataset.set(i, items[i].getName(), dciData[i].getLastValue().getValueAsDouble());
                }
                chartView.repaint();
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Exception while reading data from server", e);
    }
}
Also used : ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData)

Example 2 with DciData

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

the class BarChartElement method refresh.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
	 */
@Override
public void refresh() {
    final ChartDciConfig[] items = config.getDciList();
    if (items.length == 0)
        return;
    try {
        final DciData[] dciData = new DciData[items.length];
        for (int i = 0; i < dciData.length; i++) {
            dciData[i] = new DciData(0, 0);
            dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, null, null, 1);
        }
        post(new Runnable() {

            @Override
            public void run() {
                XYMultipleSeriesDataset dataset = chart.getDataset();
                for (int i = 0; i < dciData.length; i++) {
                    dataset.removeSeries(i);
                    XYSeries series = new XYSeries(items[i].getName());
                    for (int j = 0; j < items.length; j++) {
                        series.add(j + 1, (i == j) ? dciData[i].getLastValue().getValueAsDouble() : 0);
                    }
                    dataset.addSeries(i, series);
                }
                chartView.repaint();
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Exception while reading data from server", e);
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData) XYMultipleSeriesDataset(org.achartengine.model.XYMultipleSeriesDataset)

Example 3 with DciData

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

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

the class LineChartElement method refreshData.

/**
 * Refresh graph's data
 */
private void refreshData() {
    if (updateInProgress)
        return;
    updateInProgress = true;
    ConsoleJob job = new ConsoleJob(Messages.get().LineChartElement_JobTitle, viewPart, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        private ChartDciConfig currentDci;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Date from = new Date(System.currentTimeMillis() - config.getTimeRangeMillis());
            final Date to = new Date(System.currentTimeMillis());
            final ChartDciConfig[] dciList = config.getDciList();
            final DciData[] data = new DciData[dciList.length];
            for (int i = 0; i < dciList.length; i++) {
                currentDci = dciList[i];
                if (currentDci.type == ChartDciConfig.ITEM)
                    data[i] = session.getCollectedData(currentDci.nodeId, currentDci.dciId, from, to, 0, false);
                else
                    data[i] = session.getCollectedTableData(currentDci.nodeId, currentDci.dciId, currentDci.instance, currentDci.column, from, to, 0);
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed()) {
                        dataCache.clear();
                        chart.setTimeRange(from, to);
                        for (int i = 0; i < data.length; i++) {
                            chart.updateParameter(i, data[i], false);
                            dataCache.add(new DataCacheElement(dciList[i], data[i]));
                        }
                        chart.refresh();
                        chart.clearErrors();
                    }
                    updateInProgress = false;
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().LineChartElement_JobError, session.getObjectName(currentDci.nodeId), currentDci.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) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 5 with DciData

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

the class HistoricalDataView method refreshData.

/**
 * Refresh data
 */
private void refreshData() {
    if (updateInProgress)
        return;
    updateInProgress = true;
    new ConsoleJob(Messages.get().HistoricalDataView_RefreshJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            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 String.format(Messages.get().HistoricalDataView_RefreshJobError, nodeName, dciId);
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciData(org.netxms.client.datacollection.DciData) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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