@Override public String toString() { return String.format( "%s[timestamp=%s, context=%s, resource=%s, name=%s, type=%s, value=%s]", getClass().getSimpleName(), getTimestamp(), getContext(), getResource(), getName(), getType(), getValue()); }
/** * Construct a new {@link DriverAdapter}. * * @param input * cassandra driver {@link ResultSet} * @param metrics * the set of result metrics to include; an empty set indicates that all metrics * should be included */ DriverAdapter(Iterator<com.datastax.driver.core.Row> input, Set<String> metrics) { m_results = checkNotNull(input, "input argument"); m_metrics = checkNotNull(metrics, "metrics argument"); if (m_results.hasNext()) { Sample m = getNextSample(); m_next = new Results.Row<>(m.getTimestamp(), m.getResource()); addSample(m_next, m); } }
private Sample getRate(Sample sample) { ValueType<?> value = NAN; Sample previous = m_prevSamples.get(sample.getName()); if (previous != null) { long elapsed = sample.getTimestamp().asSeconds() - previous.getTimestamp().asSeconds(); try { value = new Gauge(sample.getValue().delta(previous.getValue()).doubleValue() / elapsed); } catch (ArithmeticException e) { value = NAN; } } return new Sample(sample.getTimestamp(), sample.getResource(), sample.getName(), GAUGE, value, sample.getAttributes()); }
@Override public Results.Row<Sample> next() { if (!hasNext()) throw new NoSuchElementException(); Results.Row<Sample> nextNext = null; while (m_results.hasNext()) { Sample m = getNextSample(); if (m.getTimestamp().gt(m_next.getTimestamp())) { nextNext = new Results.Row<>(m.getTimestamp(), m.getResource()); addSample(nextNext, m); break; } addSample(m_next, m); } try { return m_next; } finally { m_next = nextNext; } }
@Override public Sample call(Sample s) { Timestamp oldTs = s.getTimestamp(); Timestamp newTs = Timestamp.fromEpochMillis(m_timeoffset + Math.round(oldTs.asMillis()/m_timescaleFactor)); return new Sample(newTs, s.getResource(), s.getName(), s.getType(), s.getValue()); }
if (intervalCeiling.lt(last.getTimestamp())) { break; Timestamp lowerBound = last.getTimestamp(); if (lastIntervalCeiling != null && lastIntervalCeiling.gt(lowerBound)) { lowerBound = lastIntervalCeiling; Timestamp upperBound = current.getTimestamp(); if (intervalCeiling.lt(upperBound)) { upperBound = intervalCeiling; Duration elapsedBetweenSamples = current.getTimestamp().minus(last.getTimestamp());
int ttl = m_ttl; if (calculateTimeToLive) { ttl -= (int) (now.asSeconds() - m.getTimestamp().asSeconds()); if (ttl <= 0) { LOG.debug("Skipping expired sample: {}", m); .value(SchemaConstants.F_PARTITION, m.getTimestamp().stepFloor(resourceShard).asSeconds()) .value(SchemaConstants.F_RESOURCE, m.getResource().getId()) .value(SchemaConstants.F_COLLECTED, m.getTimestamp().asMillis()) .value(SchemaConstants.F_METRIC_NAME, m.getName()) .value(SchemaConstants.F_VALUE, ValueType.decompose(m.getValue()));
@Override public String call(List<Sample> samples) { JSONBuilder bldr = new JSONBuilder(); for(Sample sample : samples) { if (isNaN(sample)) continue; //System.err.println("Importing: " + sample); bldr.newObject(); bldr.attr("timestamp", sample.getTimestamp().asMillis()); bldr.attr("resource", sample.getResource().getId()); bldr.attr("name", sample.getName()); bldr.attr("type", sample.getType().name()); if (sample.getType() == MetricType.GAUGE) { bldr.attr("value", sample.getValue().doubleValue()); } else { bldr.attr("value", sample.getValue().longValue()); } } return bldr.toString(); } };