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; }
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()); } }
/** * Update a metric. This API is not intended for clients for the * simplemetrics API, declare a Counter or a Gauge using * {@link #declareCounter(String)}, {@link #declareCounter(String, Point)}, * {@link #declareGauge(String)}, or {@link #declareGauge(String, Point)} * instead. * * @param s * a single simple containing all meta data necessary to update a * metric */ public void update(Sample s) { // pass around the receiver instead of histogram settings to avoid reading any volatile if unnecessary s.setReceiver(this); metricsCollection.update(s); }
/** * 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)); }
/** * 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)); }
@Override public void set(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.GAUGE)); }
@Override public void add(String key, Number val, Context ctx) { receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.COUNTER)); }