private ValueType<?> gauge(double val) { return ValueType.compose(val, MetricType.GAUGE); }
public static ByteBuffer decompose(ValueType<?> value) { ByteBuffer buffer; switch (value.getType()) { case ABSOLUTE: case COUNTER: case DERIVE: buffer = ByteBuffer.allocate(9); buffer.put(0, value.getType().getCode()); buffer.putLong(1, value.longValue()); buffer.rewind(); return buffer; case GAUGE: buffer = ByteBuffer.allocate(9); buffer.put(0, value.getType().getCode()); buffer.putDouble(1, value.doubleValue()); buffer.rewind(); return buffer; default: throw new IllegalArgumentException(String.format("Unknown metric type: %s", value.getType())); } }
private Double getAverage() { return isValid() ? m_value.divideBy(m_known).doubleValue() : Double.NaN; }
@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(); } };
public boolean isNan() { return Double.isNaN(doubleValue()); }
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 static Sample getSample(com.datastax.driver.core.Row row) { ValueType<?> value = getValue(row); return new Sample(getTimestamp(row), getResource(row), getMetricName(row), value.getType(), value, getAttributes(row)); }
.value(SchemaConstants.F_COLLECTED, m.getTimestamp().asMillis()) .value(SchemaConstants.F_METRIC_NAME, m.getName()) .value(SchemaConstants.F_VALUE, ValueType.decompose(m.getValue()));
private static boolean isNaN(Sample sample) { return (sample.getType() == MetricType.GAUGE) && Double.isNaN(sample.getValue().doubleValue()); }
private ValueType<?> counter(long count) { return ValueType.compose(count, MetricType.COUNTER); }
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; }
private ValueType<?> gauge(double val) { return ValueType.compose(val, MetricType.GAUGE); }
private ValueType<?> counter(long count) { return ValueType.compose(count, MetricType.COUNTER); }
private void reset() { m_known = m_unknown = 0; m_value = ValueType.compose(0, MetricType.GAUGE); m_attributes = Maps.newHashMap(); }
private static ValueType<?> getValue(com.datastax.driver.core.Row row) { return ValueType.compose(row.getBytes(SchemaConstants.F_VALUE)); }
private static Sample sample(Timestamp timestamp, Resource resource, String name, Double value) { return new Sample(timestamp, resource, name, MetricType.GAUGE, ValueType.compose(value, MetricType.GAUGE)); }
attrType.getName(), type, ValueType.compose(entry.getValue(), type)
attrType.getName(), type, ValueType.compose(entry.getValue(), type)
@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()); } };
@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()); } };