/** * @summary get the worker metrics * @return the response object */ @GET @Path(GET_METRICS) @ReturnType("java.util.SortedMap<String, Long>") public Response getMetrics() { MetricRegistry metricRegistry = mWorker.getWorkerMetricsSystem().getMetricRegistry(); // Get all counters. Map<String, Counter> counters = metricRegistry.getCounters(); // Only the gauge for cached blocks is retrieved here, other gauges are statistics of free/used // spaces, those statistics can be gotten via other REST apis. String blocksCachedProperty = CommonUtils.argsToString( ".", WorkerContext.getWorkerSource().getName(), WorkerSource.BLOCKS_CACHED); @SuppressWarnings("unchecked") Gauge<Integer> blocksCached = (Gauge<Integer>) metricRegistry.getGauges().get(blocksCachedProperty); // Get values of the counters and gauges and put them into a metrics map. SortedMap<String, Long> metrics = new TreeMap<>(); for (Map.Entry<String, Counter> counter : counters.entrySet()) { metrics.put(counter.getKey(), counter.getValue().getCount()); } metrics.put(blocksCachedProperty, blocksCached.getValue().longValue()); return RestUtils.createResponse(metrics); }