private static boolean isNaN(Sample sample) { return (sample.getType() == MetricType.GAUGE) && Double.isNaN(sample.getValue().doubleValue()); }
@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()); }
@Override public Row<Sample> next() { if (!hasNext()) throw new NoSuchElementException(); Row<Sample> working = m_input.next(); Row<Sample> result = new Row<>(working.getTimestamp(), working.getResource()); for (String metricName : m_metrics) { Sample sample = working.getElement(metricName); if (sample == null) { continue; } // Use rate as result if one of counter types, else pass through as-is. result.addElement(COUNTERS.contains(sample.getType()) ? getRate(sample) : sample); m_prevSamples.put(sample.getName(), sample); } return result; }
@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()); }
@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(); } };