public static final Sample ValueB = new Sample() { @Override public String getValue(){ return "B"; } public void doSomething(){ } };
private boolean inRange() { if (m_working == null || m_nextOut == null) { return false; } Timestamp rangeUpper = m_nextOut.getTimestamp(); Timestamp rangeLower = m_nextOut.getTimestamp().minus(m_resolution); return m_working.getTimestamp().lte(rangeUpper) && m_working.getTimestamp().gt(rangeLower); }
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 Sample apply(SampleDTO input) { return new Sample( Timestamp.fromEpochMillis(input.getTimestamp()), input.getContext(), new Resource(input.getResource().getId(), wrapMap(input.getResource().getAttributes())), input.getName(), input.getType(), ValueType.compose(input.getValue(), input.getType()), input.getAttributes()); } };
public void addElement(T sample) { Row<T> row = m_rows.get(sample.getTimestamp()); if (row == null) { row = new Row<>(sample.getTimestamp(), sample.getResource()); addRow(row); } row.addElement(sample); }
private Measurement getNan(String name) { return new Measurement(m_current.getTimestamp(), m_current.getResource(), name, Double.NaN); }
private Accumulation accumulateValue(Duration elapsedWithinInterval, Duration elapsedBetweenSamples, Duration heartbeat, ValueType<?> value) { if (elapsedBetweenSamples.lt(heartbeat)) { m_known += elapsedWithinInterval.asMillis(); m_value = m_value.plus(value.times(elapsedWithinInterval.asMillis())); } else { m_unknown += elapsedWithinInterval.asMillis(); } return this; }
public Timestamp stepFloor(Duration d) { return stepFloor(d.getDuration(), d.getUnit()); }
@Override public Sample apply(SampleDTO input) { return new Sample( Timestamp.fromEpochMillis(input.getTimestamp()), input.getContext(), new Resource(input.getResource().getId(), wrapMap(input.getResource().getAttributes())), input.getName(), input.getType(), ValueType.compose(input.getValue(), input.getType()), input.getAttributes()); } };
/** * Creates a sample used to index string attributes. * * These should only be index and not be persisted. */ public static Sample createSampleForIndexingStrings(Context context, Resource resource) { return new Sample(EPOCH, context, resource, "strings", MetricType.GAUGE, ZERO); }
var samples = []; /* If you have no data to put in yet. */ /* Later, probably in a callback method with computed data */ /* replacing the constants. */ samples.push(new Sample(1, 2, 3)); /* Assuming Sample is an object. */ /* or */ samples.push({id: 23, chemical: "NO2", ppm: 1.4}); /* Object literal. */
/** * Creates a sample used to index string attributes. * * These should only be index and not be persisted. */ public static Sample createSampleForIndexingStrings(Context context, Resource resource) { return new Sample(EPOCH, context, resource, "strings", MetricType.GAUGE, ZERO); }