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