private QueryResponse queryInt(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException { QueryRequest request = new QueryRequest(); request.setRelaxed(relaxed); request.setStart(start); request.setEnd(end); request.setStep(step); Source source = new Source(); source.setAggregation(aggregation); source.setTransient(false); source.setAttribute(attribute); source.setResourceId(resource); source.setLabel(attribute); request.setSources(Collections.singletonList(source)); return measurementsService.query(request); } }
final ResourceId resourceId; try { resourceId = ResourceId.fromString(source.getResourceId()); } catch (final IllegalArgumentException ex) { if (relaxed) continue; LOG.error("Ill-formed resource id: {}", source.getResourceId(), ex); return null; if (resource == null) { if (relaxed) continue; LOG.error("No resource with id: {}", source.getResourceId()); return null; RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) { LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute()); source.setAttribute(source.getFallbackAttribute()); source.setFallbackAttribute(null); rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); LOG.error("No attribute with name: {}", source.getAttribute()); return null; Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
final Source source = entry.getKey(); final String rrdFile = entry.getValue(); dproc.addDatasource(source.getLabel(), rrdFile, source.getEffectiveDataSource(), source.getAggregation()); columns.put(source.getLabel(), dproc.getValues(source.getLabel()));
@Override public Collection<Row<Measurement>> call() throws Exception { ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval()); for (Source source : listOfSources) { // Use the datasource as the metric name if set, otherwise use the name of the attribute final String metricName = source.getDataSource() != null ? source.getDataSource() : source.getAttribute(); final String name = source.getLabel(); final AggregationFunction fn = toAggregationFunction(source.getAggregation()); resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn); resultDescriptor.export(name); } LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor); Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback); Collection<Row<Measurement>> rows = results.getRows(); LOG.debug("Found {} rows.", rows.size()); return rows; } };
if (source.getResourceId() == null || source.getAttribute() == null || source.getLabel() == null || source.getAggregation() == null) { throw new ValidationException("Query source fields must be set: {}", source); if (labels.containsKey(source.getLabel())) { throw new ValidationException("Query source label '{}' conflict: source with that label is already defined.", source.getLabel()); } else { labels.put(source.getLabel(), "source");
Source source = new Source(attribute, resourceId, attribute, attribute, false); source.setFallbackAttribute(fallbackAttribute); source.setAggregation(aggregation); request.setSources(Lists.newArrayList(source));
if (source.getTransient()) { columns.remove(source.getLabel());
/** * Enrich the <code>fetchResults</code> with NaN values for all <code>sources</code> which do not have values in the <code>fetchResults</code>. * * @param fetchResults * @param sources */ public static void fillMissingValues(FetchResults fetchResults, List<Source> sources) { Objects.requireNonNull(fetchResults); Objects.requireNonNull(sources); final int rowCount = fetchResults.getTimestamps().length; for (Source eachSource : sources) { if (!fetchResults.getColumns().containsKey(eachSource.getLabel())) { fetchResults.getColumns().put(eachSource.getLabel(), createNaNArray(rowCount)); } } }
private OnmsNode getNode(final OnmsResource resource, final Source source) { OnmsNode node = null; try { node = ResourceTypeUtils.getNodeFromResourceRoot(resource); } catch (final ObjectRetrievalFailureException e) { } if (node == null) { final OnmsResource otherResource = m_resourceDao.getResourceById(ResourceId.fromString(source.getResourceId()).getParent()); node = ResourceTypeUtils.getNodeFromResource(otherResource); } return node; }
if (source.getResourceId() == null || source.getAttribute() == null || source.getLabel() == null || source.getAggregation() == null) { throw new ValidationException("Query source fields must be set: {}", source); if (labels.containsKey(source.getLabel())) { throw new ValidationException("Query source label '{}' conflict: source with that label is already defined.", source.getLabel()); } else { labels.put(source.getLabel(), "source");
@Override public Collection<Row<Measurement>> call() throws Exception { ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval()); for (Source source : listOfSources) { // Use the datasource as the metric name if set, otherwise use the name of the attribute final String metricName = source.getDataSource() != null ? source.getDataSource() : source.getAttribute(); final String name = source.getLabel(); final AggregationFunction fn = toAggregationFunction(source.getAggregation()); resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn); resultDescriptor.export(name); } LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor); Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback); Collection<Row<Measurement>> rows = results.getRows(); LOG.debug("Found {} rows.", rows.size()); return rows; } };
if (source.getTransient()) { columns.remove(source.getLabel());
/** * Enrich the <code>fetchResults</code> with NaN values for all <code>sources</code> which do not have values in the <code>fetchResults</code>. * * @param fetchResults * @param sources */ public static void fillMissingValues(FetchResults fetchResults, List<Source> sources) { Objects.requireNonNull(fetchResults); Objects.requireNonNull(sources); final int rowCount = fetchResults.getTimestamps().length; for (Source eachSource : sources) { if (!fetchResults.getColumns().containsKey(eachSource.getLabel())) { fetchResults.getColumns().put(eachSource.getLabel(), createNaNArray(rowCount)); } } }
private QueryResponse queryInt(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException { QueryRequest request = new QueryRequest(); request.setRelaxed(relaxed); request.setStart(start); request.setEnd(end); request.setStep(step); Source source = new Source(); source.setAggregation(aggregation); source.setTransient(false); source.setAttribute(attribute); source.setResourceId(resource); source.setLabel(attribute); request.setSources(Collections.singletonList(source)); return measurementsService.query(request); } }
final ResourceId resourceId; try { resourceId = ResourceId.fromString(source.getResourceId()); } catch (final IllegalArgumentException ex) { if (relaxed) continue; LOG.error("Ill-formed resource id: {}", source.getResourceId(), ex); resources.add(null); return null; LOG.error("No resource with id: {}", source.getResourceId()); resources.add(null); return null; RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) { LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute()); source.setAttribute(source.getFallbackAttribute()); source.setFallbackAttribute(null); rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); LOG.error("No attribute with name: {}", source.getAttribute()); return null; Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
final String rrdFile = entry.getValue(); final String tempLabel = Integer.toString(++k); labelMap.put(tempLabel, source.getLabel()); tempLabel, Utils.escapeColons(rrdFile), Utils.escapeColons(source.getEffectiveDataSource()), source.getAggregation())); argv.add(String.format("XPORT:%s:%s", tempLabel, tempLabel));
request.setStep(step); Source sourceIn = new Source(); sourceIn.setAggregation(aggregation); sourceIn.setTransient(true); sourceIn.setAttribute("ifHCInOctets"); sourceIn.setFallbackAttribute("ifInOctets"); sourceIn.setResourceId(resource); sourceIn.setLabel("ifInOctets"); Source sourceOut = new Source(); sourceOut.setAggregation(aggregation); sourceOut.setTransient(true); sourceOut.setAttribute("ifHCOutOctets"); sourceOut.setFallbackAttribute("ifOutOctets"); sourceOut.setResourceId(resource); sourceOut.setLabel("ifOutOctets");
.collect(Collectors.groupingBy((source) -> ResourceId.fromString(source.getResourceId()))); for (Source source : entry.getValue()) { Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants); RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) { LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute()); source.setAttribute(source.getFallbackAttribute()); source.setFallbackAttribute(null); rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute()); LOG.error("No attribute with name: {}", source.getAttribute()); return null;
final String rrdFile = entry.getValue(); final String tempLabel = Integer.toString(++k); labelMap.put(tempLabel, source.getLabel()); tempLabel, Utils.escapeColons(rrdFile), Utils.escapeColons(source.getEffectiveDataSource()), source.getAggregation())); argv.add(String.format("XPORT:%s:%s", tempLabel, tempLabel));
request.setStep(step); Source sourceIn = new Source(); sourceIn.setAggregation(aggregation); sourceIn.setTransient(true); sourceIn.setAttribute("ifHCInOctets"); sourceIn.setFallbackAttribute("ifInOctets"); sourceIn.setResourceId(resource); sourceIn.setLabel("ifInOctets"); Source sourceOut = new Source(); sourceOut.setAggregation(aggregation); sourceOut.setTransient(true); sourceOut.setAttribute("ifHCOutOctets"); sourceOut.setFallbackAttribute("ifOutOctets"); sourceOut.setResourceId(resource); sourceOut.setLabel("ifOutOctets");