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 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()); }
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()); }
private int go(String[] args) { m_parser.setUsageWidth(80); try { m_parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); printUsage(System.err); return 1; } if (m_needsHelp) { printUsage(System.out); return 0; } if (m_resource == null || m_metric == null) { System.err.println("Missing required argument(s)"); printUsage(System.err); return 1; } System.out.printf("timestamp,%s%n", m_metric); for (Results.Row<Sample> row : m_repository.select(Context.DEFAULT_CONTEXT, m_resource, timestamp(m_start), timestamp(m_end))) { System.out.printf("%s,%.2f%n", row.getTimestamp().asDate(), row.getElement(m_metric).getValue().doubleValue()); } return 0; }
ds.getHeartbeat(), current.getValue()) .accumlateAttrs(current.getAttributes());
@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(); } };
.value(SchemaConstants.F_COLLECTED, m.getTimestamp().asMillis()) .value(SchemaConstants.F_METRIC_NAME, m.getName()) .value(SchemaConstants.F_VALUE, ValueType.decompose(m.getValue()));