/** * Add an RPC processing time sample * @param name of the RPC call * @param processingTime the processing time */ //@Override // some instrumentation interface public void addProcessingTime(String name, int processingTime) { rates.add(name, processingTime); }
public synchronized MutableRatesWithAggregation newRatesWithAggregation( String name) { checkMetricName(name); MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); metricsMap.put(name, rates); return rates; }
@Override public void run() { synchronized (parent) { final MetricsCollectorImpl mc = new MetricsCollectorImpl(); final MetricsRecordBuilder rb = mc.addRecord("RatesRoller"); /** * snapshot all metrics regardless of being changed or not, in case no * ops since last snapshot, we will get 0. */ parent.innerMetrics.snapshot(rb, true); Preconditions.checkState(mc.getRecords().size() == 1, "There must be only one record and it's named with 'RatesRoller'"); parent.currentSnapshot = parent.innerMetrics.getGlobalMetrics(); parent.rollOverAvgs(); } parent.setChanged(); } }
@Test public void testMutableRatesWithAggregationSingleThread() { MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); rates.add("foo", 1); rates.add("bar", 5); MetricsRecordBuilder rb = mockMetricsRecordBuilder(); rates.snapshot(rb, false); assertCounter("FooNumOps", 1L, rb); assertGauge("FooAvgTime", 1.0, rb); assertCounter("BarNumOps", 1L, rb); assertGauge("BarAvgTime", 5.0, rb); rates.add("foo", 1); rates.add("foo", 3); rates.add("bar", 6); rb = mockMetricsRecordBuilder(); rates.snapshot(rb, false); assertCounter("FooNumOps", 3L, rb); assertGauge("FooAvgTime", 2.0, rb); assertCounter("BarNumOps", 2L, rb); assertGauge("BarAvgTime", 6.0, rb); }
@Test public void testMutableRatesWithAggregationInit() { MetricsRecordBuilder rb = mockMetricsRecordBuilder(); MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); rates.init(TestProtocol.class); rates.snapshot(rb, false); assertCounter("FooNumOps", 0L, rb); assertGauge("FooAvgTime", 0.0, rb); assertCounter("BarNumOps", 0L, rb); assertGauge("BarAvgTime", 0.0, rb); }
@Test public void testMutableRatesWithAggregationManyThreads() throws InterruptedException { final MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); opTotalTime[i] = 0; rates.add("metric" + i, 0);
/** * Initialize the registry with all the methods in a protocol * so they all show up in the first snapshot. * Convenient for JMX implementations. * @param protocol the protocol class */ public void init(Class<?> protocol) { if (protocolCache.contains(protocol)) { return; } protocolCache.add(protocol); for (Method method : protocol.getDeclaredMethods()) { String name = method.getName(); LOG.debug(name); addMetricIfNotExists(name); } }
private static void snapshotMutableRatesWithAggregation( MutableRatesWithAggregation rates, long[] opCount, double[] opTotalTime) { MetricsRecordBuilder rb = mockMetricsRecordBuilder(); rates.snapshot(rb, true); for (int i = 0; i < opCount.length; i++) { long prevOpCount = opCount[i]; long newOpCount = getLongCounter("Metric" + i + "NumOps", rb); opCount[i] = newOpCount; double avgTime = getDoubleGauge("Metric" + i + "AvgTime", rb); opTotalTime[i] += avgTime * (newOpCount - prevOpCount); } }
/** * Aggregates the thread's local samples into the global metrics. The caller * should ensure its thread safety. */ private void aggregateLocalStatesToGlobalMetrics( final ConcurrentMap<String, ThreadSafeSampleStat> localStats) { for (Map.Entry<String, ThreadSafeSampleStat> entry : localStats .entrySet()) { String name = entry.getKey(); MutableRate globalMetric = addMetricIfNotExists(name); entry.getValue().snapshotInto(globalMetric); } }
rates.snapshot(rb, true);
/** * @param name * name of metric * @param value * value of metric */ public void add(final String name, final long value) { innerMetrics.add(name, value); }
/** * Initialize the registry with all the methods in a protocol * so they all show up in the first snapshot. * Convenient for JMX implementations. * @param protocol the protocol class */ public void init(Class<?> protocol) { if (protocolCache.contains(protocol)) { return; } protocolCache.add(protocol); for (Method method : protocol.getDeclaredMethods()) { String name = method.getName(); LOG.debug(name); addMetricIfNotExists(name); } }
public synchronized MutableRatesWithAggregation newRatesWithAggregation( String name) { checkMetricName(name); MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); metricsMap.put(name, rates); return rates; }
/** * Initialize the metrics for JMX with protocol methods * @param protocol the protocol class */ public void init(Class<?> protocol) { rates.init(protocol); }
public void addDeferredProcessingTime(String name, long processingTime) { deferredRpcRates.add(name, processingTime); }
/** * Initialize the registry with all the methods in a protocol * so they all show up in the first snapshot. * Convenient for JMX implementations. * @param protocol the protocol class */ public void init(Class<?> protocol) { if (protocolCache.contains(protocol)) { return; } protocolCache.add(protocol); for (Method method : protocol.getDeclaredMethods()) { String name = method.getName(); LOG.debug(name); addMetricIfNotExists(name); } }
public synchronized MutableRatesWithAggregation newRatesWithAggregation( String name) { checkMetricName(name); MutableRatesWithAggregation rates = new MutableRatesWithAggregation(); metricsMap.put(name, rates); return rates; }
/** * Initialize the metrics for JMX with protocol methods * @param protocol the protocol class */ public void init(Class<?> protocol) { rates.init(protocol); }
/** * Add the lock hold time for a recent operation to the metrics. * @param operationName Name of the operation for which to record the time * @param value Length of time the lock was held (nanoseconds) */ private void addMetric(String operationName, long value, boolean isWrite) { if (metricsEnabled) { String opMetric = getMetricName(operationName, isWrite); detailedHoldTimeMetrics.add(opMetric, value); String overallMetric = getMetricName(OVERALL_METRIC_NAME, isWrite); detailedHoldTimeMetrics.add(overallMetric, value); } }