Search in sources :

Example 11 with DciData

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

the class LineChartElement method refresh.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
	 */
@Override
public void refresh() {
    final ChartDciConfig[] items = config.getDciList();
    Log.v(TAG, "refresh(): " + items.length + " items to load");
    if (items.length == 0)
        return;
    final long endTime = System.currentTimeMillis();
    final long startTime = endTime - config.getTimeRangeMillis();
    graphView.setCustomLabelFormatter(new CustomLabel(Integer.parseInt(sp.getString("global.multipliers", "1")), (endTime - startTime) > 86400 * 1000));
    try {
        final DciData[] dciData = new DciData[items.length];
        for (int i = 0; i < dciData.length; i++) {
            dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, new Date(startTime), new Date(endTime), 0);
        }
        Log.v(TAG, "refresh(): data retrieved from server");
        post(new Runnable() {

            @Override
            public void run() {
                graphView.removeAllSeries();
                for (int i = 0; i < dciData.length && i < Colors.DEFAULT_ITEM_COLORS.length; i++) {
                    DciDataRow[] dciDataRow = dciData[i].getValues();
                    GraphViewData[] gvData = new GraphViewData[dciDataRow.length];
                    for (int j = dciDataRow.length - 1, k = 0; j >= 0; j--, k++) // dciData are reversed!
                    gvData[k] = new GraphViewData(dciDataRow[j].getTimestamp().getTime(), dciDataRow[j].getValueAsDouble());
                    int color = items[i].getColorAsInt();
                    color = color == -1 ? Colors.DEFAULT_ITEM_COLORS[i] : swapRGB(color);
                    GraphViewSeries series = new GraphViewSeries(items[i].getName(), new GraphViewSeriesStyle(color | 0xFF000000, 3), gvData);
                    graphView.addSeries(series);
                }
                graphView.setViewPort(startTime, endTime - startTime + 1);
                Log.v(TAG, "refresh(): " + dciData.length + " series added; viewport set to " + startTime + "/" + (endTime - startTime + 1));
                if (getChildCount() == 0)
                    addView(graphView);
                else
                    graphView.redrawAll();
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Exception while reading data from server", e);
    }
}
Also used : CustomLabel(org.netxms.ui.android.helpers.CustomLabel) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData) Date(java.util.Date) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries) GraphViewSeriesStyle(com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData)

Example 12 with DciData

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

the class ComparisonChartElement method refreshData.

/**
 * Refresh graph's data
 */
protected void refreshData(final ChartDciConfig[] dciList) {
    if (updateInProgress)
        return;
    updateInProgress = true;
    ConsoleJob job = new ConsoleJob(Messages.get().ComparisonChartElement_JobTitle, viewPart, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

                @Override
                public void run() {
                    if (!((Widget) chart).isDisposed()) {
                        for (int i = 0; i < data.length; i++) {
                            DciDataRow lastValue = data[i].getLastValue();
                            chart.updateParameter(i, (lastValue != null) ? lastValue : new DciDataRow(new Date(), 0.0), data[i].getDataType(), false);
                            if (updateThresholds)
                                chart.updateParameterThresholds(i, thresholds[i]);
                        }
                        chart.refresh();
                        chart.clearErrors();
                    }
                    updateInProgress = false;
                }
            });
        }

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

        @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 : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciDataRow(org.netxms.client.datacollection.DciDataRow) Widget(org.eclipse.swt.widgets.Widget) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciData(org.netxms.client.datacollection.DciData) Point(org.eclipse.swt.graphics.Point) Date(java.util.Date)

Example 13 with DciData

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

the class HistoricalData method get.

/* (non-Javadoc)
    * @see org.netxms.websvc.handlers.AbstractHandler#get(java.lang.String)
    */
@Override
protected Object get(String id, Map<String, String> query) throws Exception {
    NXCSession session = getSession();
    AbstractObject obj = getObject();
    long dciId = 0;
    try {
        dciId = Long.parseLong(id);
    } catch (NumberFormatException e) {
        dciId = session.dciNameToId(obj.getObjectId(), id);
    }
    if (obj == null || dciId == 0 || !(obj instanceof DataCollectionTarget))
        throw new NXCException(RCC.INVALID_OBJECT_ID);
    String timeFrom = query.get("from");
    String timeTo = query.get("to");
    String timeInteval = query.get("timeInterval");
    String itemCount = query.get("itemCount");
    DciData data = null;
    if (timeFrom != null || timeTo != null) {
        data = session.getCollectedData(obj.getObjectId(), dciId, new Date(parseLong(timeFrom, 0) * 1000), new Date(parseLong(timeTo, System.currentTimeMillis() / 1000) * 1000), parseInt(itemCount, 0), false);
    } else if (timeInteval != null) {
        Date now = new Date();
        long from = now.getTime() - parseLong(timeInteval, 0) * 1000;
        data = session.getCollectedData(obj.getObjectId(), dciId, new Date(from), new Date(), parseInt(itemCount, 0), false);
    } else if (itemCount != null) {
        data = session.getCollectedData(obj.getObjectId(), dciId, null, null, parseInt(itemCount, 0), false);
    } else {
        Date now = new Date();
        // one hour
        long from = now.getTime() - 3600000;
        data = session.getCollectedData(obj.getObjectId(), dciId, new Date(from), now, parseInt(itemCount, 0), false);
    }
    return new ResponseContainer("values", data);
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) DataCollectionTarget(org.netxms.client.objects.DataCollectionTarget) DciData(org.netxms.client.datacollection.DciData) ResponseContainer(org.netxms.websvc.json.ResponseContainer) NXCException(org.netxms.client.NXCException) Date(java.util.Date)

Example 14 with DciData

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

the class GrafanaDataCollection method getGraphData.

/**
 * Get query data
 *
 * @param query
 * @return data
 * @throws Exception
 */
private JsonArray getGraphData(Map<String, String> query) throws Exception {
    JsonParser parser = new JsonParser();
    JsonElement element = parser.parse(query.get("targets"));
    if (!element.isJsonArray())
        return new JsonArray();
    JsonArray targets = element.getAsJsonArray();
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    Date from = format.parse(query.get("from").substring(1, query.get("from").length() - 1));
    Date to = format.parse(query.get("to").substring(1, query.get("to").length() - 1));
    JsonObject root, dciTarget, dci;
    JsonArray result = new JsonArray();
    for (JsonElement e : targets) {
        if (!e.getAsJsonObject().has("dciTarget") || !e.getAsJsonObject().has("dci"))
            continue;
        dciTarget = e.getAsJsonObject().getAsJsonObject("dciTarget");
        dci = e.getAsJsonObject().getAsJsonObject("dci");
        if (dciTarget.size() == 0 || dci.size() == 0)
            continue;
        DciData data = getSession().getCollectedData(Long.parseLong(dciTarget.get("id").getAsString()), Long.parseLong(dci.get("id").getAsString()), from, to, 0, false);
        root = new JsonObject();
        JsonArray datapoints = new JsonArray();
        JsonArray datapoint;
        DciDataRow[] values = data.getValues();
        for (int i = values.length - 1; i >= 0; i--) {
            DciDataRow r = values[i];
            log.debug(r.toString());
            datapoint = new JsonArray();
            datapoint.add(r.getValueAsDouble());
            datapoint.add(r.getTimestamp().getTime());
            datapoints.add(datapoint);
        }
        if (e.getAsJsonObject().has("legend") && !e.getAsJsonObject().get("legend").getAsString().equals(""))
            root.addProperty("target", e.getAsJsonObject().get("legend").getAsString());
        else
            root.addProperty("target", dci.get("name").getAsString());
        root.add("datapoints", datapoints);
        result.add(root);
    }
    return result;
}
Also used : JsonArray(com.google.gson.JsonArray) DciDataRow(org.netxms.client.datacollection.DciDataRow) JsonElement(com.google.gson.JsonElement) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JsonObject(com.google.gson.JsonObject) DciData(org.netxms.client.datacollection.DciData) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JsonParser(com.google.gson.JsonParser)

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