/** * 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)); }
private void padMetric(String metric, Bucket toPresent, int currentDataPoints) { final LinkedHashMap<Point, TimeStampedMetric> cachedPoints = getCachedMetric(metric); int toAdd = pointsToKeep - currentDataPoints; @SuppressWarnings({"unchecked","rawtypes"}) Entry<Point, TimeStampedMetric>[] cachedEntries = cachedPoints.entrySet().toArray(new Entry[0]); long nowMillis = System.currentTimeMillis(); for (int i = cachedEntries.length - 1; i >= 0 && toAdd > 0; --i) { Entry<Point, TimeStampedMetric> leastOld = cachedEntries[i]; if (leastOld.getValue().millis + MAX_AGE_MILLIS < nowMillis) { continue; } final Identifier id = new Identifier(metric, leastOld.getKey()); if (!toPresent.hasIdentifier(id)) { toPresent.put(id, leastOld.getValue().metric.pruneData()); --toAdd; } } }
@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)); }