Refine search
private Map<String, Long> getMetricsInternal() { MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY; // 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 = MetricsSystem.getMetricName(DefaultBlockWorker.Metrics.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 metrics; }
@Override protected void reportInContext(MetricContext context, SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { Gauge gauge = entry.getValue(); if (gauge.getValue() instanceof Long || gauge.getValue() instanceof Integer || gauge.getValue() instanceof Short || gauge.getValue() instanceof Byte) reportValue(context, entry.getKey(), ((Number) gauge.getValue()).longValue()); } for (Map.Entry<String, Counter> entry : counters.entrySet()) { reportCount(context, entry.getKey(), entry.getValue().getCount()); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { reportCount(context, entry.getKey(), entry.getValue().getCount()); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { reportCount(context, entry.getKey(), entry.getValue().getCount()); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { reportCount(context, entry.getKey(), entry.getValue().getCount()); } }
@Test public void queriesIntervalCounterInc() { catcher.requestStart(new AddQuery( RequestData.builder() .correlationId(10l) .type("test") .build())); assertThat(registry.getGauges().size(), equalTo(2)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-started-interval-count").getValue(), equalTo(1l)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-started-test-interval-count").getValue(), equalTo(1l)); }
.get(MetricsSystem.getMetricName(DefaultBlockMaster.Metrics.CAPACITY_TOTAL)).getValue(); Long masterCapacityUsed = (Long) mr.getGauges() .get(MetricsSystem.getMetricName(DefaultBlockMaster.Metrics.CAPACITY_USED)).getValue(); (Long) mr.getGauges().get(MetricsSystem.getMetricName(MasterMetrics.UFS_CAPACITY_TOTAL)) .getValue(); .getValue(); .get(MetricsSystem.getClusterMetricName(ClientMetrics.BYTES_READ_LOCAL)).getValue(); Long bytesReadRemote = (Long) mr.getGauges() .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_READ_ALLUXIO)).getValue(); Long bytesReadUfs = (Long) mr.getGauges() .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_READ_UFS_ALL)).getValue(); response.setTotalBytesReadLocal(FormatUtils.getSizeFromBytes(bytesReadLocal)) .setTotalBytesReadRemote(FormatUtils.getSizeFromBytes(bytesReadRemote)) .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_WRITTEN_ALLUXIO)).getValue(); Long bytesWrittenUfs = (Long) mr.getGauges() .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_WRITTEN_UFS_ALL)).getValue(); response.setTotalBytesWrittenAlluxio(FormatUtils.getSizeFromBytes(bytesWrittenAlluxio)) .setTotalBytesWrittenUfs(FormatUtils.getSizeFromBytes(bytesWrittenUfs)); .getValue(); .getValue(); .getValue(); response
Map.Entry<String, Gauge> dropwizardEntry = registry.getMetricRegistry().getGauges().entrySet().iterator().next(); assertEquals("test", stagemonitorEntry.getKey().getName()); assertEquals(1, stagemonitorEntry.getValue().getValue()); dropwizardEntry.getValue().getValue()); assertEquals(0, registry.getMetricRegistry().getGauges().size());
@GET @Timed @RequiresPermissions(RestPermissions.THROUGHPUT_READ) @ApiOperation(value = "Current throughput of this node in messages per second") @Produces(MediaType.APPLICATION_JSON) public Throughput total() { final SortedMap<String, Gauge> gauges = metricRegistry.getGauges(MetricUtils.filterSingleMetric( GlobalMetricNames.OUTPUT_THROUGHPUT_RATE)); final Gauge gauge = Iterables.getOnlyElement(gauges.values(), null); if (gauge == null || !(gauge.getValue() instanceof Number)) { return Throughput.create(0); } else { return Throughput.create(((Number) gauge.getValue()).longValue()); } } }
/** * {@inheritDoc} */ @Override public Object getValue(Integer window) { return this.gauge.getValue(); } }
@Test(dependsOnMethods = "testQueueStats") public void testRegisterAll() { MetricRegistry metricRegistry = new MetricRegistry(); this.boundedBlockingRecordQueue.stats().get().registerAll(metricRegistry, METRIC_NAME_PREFIX); @SuppressWarnings("rawtypes") Map<String, Gauge> gauges = metricRegistry.getGauges(); Assert.assertEquals(gauges.size(), 2); Assert.assertEquals(gauges .get(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.QUEUE_SIZE)).getValue(), 2); Assert.assertEquals(gauges .get(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.FILL_RATIO)).getValue(), 1d); Assert.assertEquals(metricRegistry.getMeters().size(), 2); Assert.assertEquals(metricRegistry .meter(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.GET_ATTEMPT_RATE)) .getCount(), 7); Assert.assertEquals(metricRegistry .meter(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.PUT_ATTEMPT_RATE)) .getCount(), 8); }
@SuppressWarnings("rawtypes") private static Map<String, Object> gauges(final SortedMap<String, Gauge> gauges) { Map<String, Object> result = new TreeMap<>(); gauges.forEach((name, gauge) -> { try { result.put(name, gauge.getValue()); } catch (Exception ex) { result.put(name, ex.toString()); } }); return result; }
private Map<String, Long> getMetricsInternal() { MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY; // Get all counters. Map<String, Counter> counters = metricRegistry.getCounters(); // Only the gauge for pinned files is retrieved here, other gauges are statistics of // free/used // spaces, those statistics can be gotten via other REST apis. String filesPinnedProperty = MetricsSystem.getMetricName(MasterMetrics.FILES_PINNED); @SuppressWarnings("unchecked") Gauge<Integer> filesPinned = (Gauge<Integer>) MetricsSystem.METRIC_REGISTRY.getGauges().get(filesPinnedProperty); // 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(filesPinnedProperty, filesPinned.getValue().longValue()); return metrics; }
private static List<Metric> allMetrics(MetricsSystem.InstanceType instanceType) { List<Metric> metrics = new ArrayList<>(); for (Entry<String, Gauge> entry : METRIC_REGISTRY.getGauges().entrySet()) { if (entry.getKey().startsWith(instanceType.toString())) { Object value = entry.getValue().getValue(); if (!(value instanceof Number)) { LOG.warn( "The value of metric {} of type {} is not sent to metrics master," + " only metrics value of number can be collected", entry.getKey(), entry.getValue().getClass().getSimpleName()); continue; } metrics.add(Metric.from(entry.getKey(), ((Number) value).longValue())); } } for (Entry<String, Counter> entry : METRIC_REGISTRY.getCounters().entrySet()) { metrics.add(Metric.from(entry.getKey(), entry.getValue().getCount())); } for (Entry<String, Meter> entry : METRIC_REGISTRY.getMeters().entrySet()) { // TODO(yupeng): From Meter's implementation, getOneMinuteRate can only report at rate of at // least seconds. if the client's duration is too short (i.e. < 1s), then getOneMinuteRate // would return 0 metrics.add(Metric.from(entry.getKey(), entry.getValue().getOneMinuteRate())); } for (Entry<String, Timer> entry : METRIC_REGISTRY.getTimers().entrySet()) { metrics.add(Metric.from(entry.getKey(), entry.getValue().getCount())); } return metrics; }
@Test public void queriesIntervalCounterDec() { catcher.requestComplete(new RemoveQuery( RequestData.builder() .correlationId(10l) .type("test") .build())); assertThat(registry.getGauges().size(), equalTo(2)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-interval-count").getValue(), equalTo(1l)); assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-test-interval-count").getValue(), equalTo(1l)); }
@Override public T getValue() { return this.gauge.getValue(); }
@Override public void getMetrics(GetMetricsPOptions options, StreamObserver<GetMetricsPResponse> responseObserver) { RpcUtils.call(LOG, (RpcUtils.RpcCallableThrowsIOException<GetMetricsPResponse>) () -> { MetricRegistry mr = MetricsSystem.METRIC_REGISTRY; Map<String, alluxio.grpc.MetricValue> metricsMap = new HashMap<>(); for (Map.Entry<String, Counter> entry : mr.getCounters().entrySet()) { metricsMap.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), alluxio.grpc.MetricValue .newBuilder().setLongValue(entry.getValue().getCount()).build()); } for (Map.Entry<String, Gauge> entry : mr.getGauges().entrySet()) { Object value = entry.getValue().getValue(); if (value instanceof Integer) { metricsMap.put(entry.getKey(), alluxio.grpc.MetricValue.newBuilder() .setLongValue(Long.valueOf((Integer) value)).build()); } else if (value instanceof Long) { metricsMap.put(entry.getKey(), alluxio.grpc.MetricValue.newBuilder() .setLongValue(Long.valueOf((Long) value)).build()); } else if (value instanceof Double) { metricsMap.put(entry.getKey(), alluxio.grpc.MetricValue.newBuilder().setDoubleValue((Double) value).build()); } } return GetMetricsPResponse.newBuilder().putAllMetrics(metricsMap).build(); }, "getConfiguration", "options=%s", responseObserver, options); } }
Iterator<Entry<String, Gauge>> gaugeIterator = dropwizardGauges.entrySet().iterator(); while (gaugeIterator.hasNext()) { @SuppressWarnings("rawtypes") Entry<String, Gauge> gauge = gaugeIterator.next(); final MetricsInfo info = Interns.info(gauge.getKey(), EMPTY_STRING); final Object o = gauge.getValue().getValue(); Iterator<Entry<String, Counter>> counterIterator = dropwizardCounters.entrySet().iterator(); while (counterIterator.hasNext()) { Entry<String, Counter> counter = counterIterator.next(); Iterator<Entry<String, Histogram>> histogramIterator = dropwizardHistograms.entrySet().iterator(); while (histogramIterator.hasNext()) { final Entry<String, Histogram> entry = histogramIterator.next();