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);
}
}
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);
}
}
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;
}
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();
}
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();
}
Aggregations