/** * Add sample to a stat metric by name. * @param name of the metric * @param value of the snapshot to add */ public void add(String name, long value) { MutableMetric m = metricsMap.get(name); if (m != null) { if (m instanceof MutableStat) { ((MutableStat) m).add(value); } else { throw new MetricsException("Unsupported add(value) for metric "+ name); } } else { metricsMap.put(name, newRate(name)); // default is a rate metric add(name, value); } }
/** * Create a mutable metric with stats * @param name of the metric * @param desc metric description * @param sampleName of the metric (e.g., "Ops") * @param valueName of the metric (e.g., "Time" or "Latency") * @param extended produce extended stat (stdev, min/max etc.) if true. * @return a new mutable stat metric object */ public MutableStat newStat(String name, String desc, String sampleName, String valueName, boolean extended) { MutableStat ret = new MutableStat(name, desc, sampleName, valueName, extended); return addNewMetricIfAbsent(name, ret, MutableStat.class); }
@Override public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { numSamples += intervalStat.numSamples(); builder.addCounter(numInfo, numSamples) .addGauge(avgInfo, lastStat().mean()); if (extended) { builder.addGauge(stdevInfo, lastStat().stddev()) .addGauge(iMinInfo, lastStat().min()) .addGauge(iMaxInfo, lastStat().max()) .addGauge(minInfo, minMax.min()) .addGauge(maxInfo, minMax.max()) .addGauge(iNumInfo, lastStat().numSamples()); } if (changed()) { if (numSamples > 0) { intervalStat.copyTo(prevStat); intervalStat.reset(); } clearChanged(); } } }
registry.newGauge("g1", "int gauge", 3); registry.newGauge("g2", "long gauge", 4L); registry.newStat("s1", "stat", "Ops", "Time", true).add(0); registry.newRate("s2", "stat", false).add(0); s2.snapshot(mb, true); // should get the same back. s2.add(1); s2.snapshot(mb, true); // should get new interval values back
replicationQueueTimeStat.resetMinMax(); long diff = Math.max(0, currentTime - modTime); replicationQueueTimeQuantiles.add(diff); replicationQueueTimeStat.add(diff);
/** * Add a number of samples and their sum to the running stat * * Note that although use of this method will preserve accurate mean values, * large values for numSamples may result in inaccurate variance values due * to the use of a single step of the Welford method for variance calculation. * @param numSamples number of samples * @param sum of the samples */ public synchronized void add(long numSamples, long sum) { intervalStat.add(numSamples, sum); setChanged(); }
/** * Return a SampleStat object that supports * calls like StdDev and Mean. * @return SampleStat */ public SampleStat lastStat() { return changed() ? intervalStat : prevStat; }
@Override public String toString() { return lastStat().toString(); } }
registry.newGauge("g1", "int gauge", 3); registry.newGauge("g2", "long gauge", 4L); registry.newStat("s1", "stat", "Ops", "Time", true).add(0); registry.newRate("s2", "stat", false).add(0); s2.snapshot(mb, true); // should get the same back. s2.add(1); s2.snapshot(mb, true); // should get new interval values back
replicationQueueTimeStat.resetMinMax(); long diff = Math.max(0, currentTime - modTime); replicationQueueTimeQuantiles.add(diff); replicationQueueTimeStat.add(diff);
/** * Add a snapshot to the metric * @param value of the metric */ public synchronized void add(long value) { intervalStat.add(value); minMax.add(value); setChanged(); }
/** * Return a SampleStat object that supports * calls like StdDev and Mean. * @return SampleStat */ public SampleStat lastStat() { return changed() ? intervalStat : prevStat; }
@Override public String toString() { return lastStat().toString(); } }
/** * Add sample to a stat metric by name. * @param name of the metric * @param value of the snapshot to add */ public synchronized void add(String name, long value) { MutableMetric m = metricsMap.get(name); if (m != null) { if (m instanceof MutableStat) { ((MutableStat) m).add(value); } else { throw new MetricsException("Unsupported add(value) for metric "+ name); } } else { metricsMap.put(name, newRate(name)); // default is a rate metric add(name, value); } }
public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) { if (all || changed()) { numSamples += intervalStat.numSamples(); builder.addCounter(numInfo, numSamples) .addGauge(avgInfo, lastStat().mean()); if (extended) { builder.addGauge(stdevInfo, lastStat().stddev()) .addGauge(iMinInfo, lastStat().min()) .addGauge(iMaxInfo, lastStat().max()) .addGauge(minInfo, minMax.min()) .addGauge(maxInfo, minMax.max()); } if (changed()) { if (numSamples > 0) { intervalStat.copyTo(prevStat); intervalStat.reset(); } clearChanged(); } } }
/** * Create a mutable metric with stats * @param name of the metric * @param desc metric description * @param sampleName of the metric (e.g., "Ops") * @param valueName of the metric (e.g., "Time" or "Latency") * @param extended produce extended stat (stdev, min/max etc.) if true. * @return a new mutable stat metric object */ public synchronized MutableStat newStat(String name, String desc, String sampleName, String valueName, boolean extended) { checkMetricName(name); MutableStat ret = new MutableStat(name, desc, sampleName, valueName, extended); metricsMap.put(name, ret); return ret; }
/** * Add a number of samples and their sum to the running stat * @param numSamples number of samples * @param sum of the samples */ public synchronized void add(long numSamples, long sum) { intervalStat.add(numSamples, sum); setChanged(); }
/** * Return a SampleStat object that supports * calls like StdDev and Mean. * @return SampleStat */ public SampleStat lastStat() { return changed() ? intervalStat : prevStat; }
/** * Publish a metrics snapshot to all the sinks * @param buffer the metrics snapshot to publish * @param immediate indicates that we should publish metrics immediately * instead of using a separate thread. */ synchronized void publishMetrics(MetricsBuffer buffer, boolean immediate) { int dropped = 0; for (MetricsSinkAdapter sa : sinks.values()) { long startTime = Time.monotonicNow(); boolean result; if (immediate) { result = sa.putMetricsImmediate(buffer); } else { result = sa.putMetrics(buffer, logicalTime); } dropped += result ? 0 : 1; publishStat.add(Time.monotonicNow() - startTime); } droppedPubAll.incr(dropped); }