/** * Set a named dimension to an integer value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, long dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
/** utility method for testing */ public Point point(String dim, String val) { return pointBuilder().set(dim, val).build(); } }
@Override public void set(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.GAUGE)); }
void put(Sample x) { UntypedMetric value = get(x); Measurement m = x.getMeasurement(); switch (x.getMetricType()) { case GAUGE: value.put(m.getMagnitude()); break; case COUNTER: value.add(m.getMagnitude()); break; default: throw new IllegalArgumentException("Unsupported metric type: " + x.getMetricType()); } }
/** * Declare a counter metric without setting any default position. * * @param name * the name of the metric * @return a thread-safe counter */ public Counter declareCounter(String name) { return declareCounter(name, null); }
/** * Add to the dimension-less/zero-point value of this counter. * * @param n the amount by which to increase this counter */ public void add(long n) { add(n, defaultPosition); }
private UntypedMetric get(Sample sample) { Identifier dim = sample.getIdentifier(); UntypedMetric v = values.get(dim); if (v == null) { // please keep inside guard, as sample.getHistogramDefinition(String) touches a volatile v = new UntypedMetric(sample.getHistogramDefinition(dim.getName())); values.put(dim, v); } return v; }
/** * Create a PointBuilder instance with no default settings. PointBuilder * instances are not thread-safe. * * @return an "empty" point builder instance */ public PointBuilder pointBuilder() { return new PointBuilder(); }
@Override public Bucket update(Bucket current, Sample x) { hasBeenAccessed = true; return super.update(current, x); } }
/** * Helper method to wrap a long as a Value. The instance returned may or may * not be unique. * * @param value * the value to wrap * @return an immutable wrapper */ public static Value of(long value) { return new LongValue(value); }
/** * Build a fresh MetricSettings instance. * * @return a MetricSettings instance containing the values set in this * builder */ public MetricSettings build() { return new MetricSettings(histogram); } }
/** * Helper method to wrap a string as a Value. The instance returned may or * may not be unique. * * @param value * the value to wrap * @return an immutable wrapper */ public static Value of(String value) { return new StringValue(value); }
@Override public Bucket update(Bucket current, Sample x) { current.put(x); return current; }
@Override public void add(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.COUNTER)); }
/** * Set a named dimension to a string value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, String dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
/** * Create a PointBuilder with default dimension values as given when this * counter was declared. * * @return a PointBuilder reflecting the default dimension values of this * counter */ public PointBuilder builder() { return new PointBuilder(defaultPosition); } }
/** * Record a sample at the given position. * * @param x * sample value * @param p * position/dimension values for the sample */ public void sample(double x, Point p) { receiver.update(new Sample(new Measurement(Double.valueOf(x)), new Identifier(name, p), AssumedType.GAUGE)); }
/** * Set a named dimension to a floating point value. * * @param dimensionName the name of the dimension to set * @param dimensionValue to value for the given dimension * @return this, to facilitate chaining */ public PointBuilder set(String dimensionName, double dimensionValue) { return set(dimensionName, Value.of(dimensionValue)); }
/** * Add to this metric at the given point. * * @param n * the amount by which to increase this counter * @param p * the point in the metric space at which to add to the metric */ public void add(long n, Point p) { metricReceiver.update(new Sample(new Measurement(Long.valueOf(n)), new Identifier(name, p), AssumedType.COUNTER)); }