/** * Returns a map of all the meters in the registry and their names. * * @return all the meters in the registry */ public SortedMap<String, Meter> getMeters() { return getMeters(MetricFilter.ALL); }
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; }
final SortedMap<String, ? extends Counting> streamMeters = metricRegistry.getMeters(streamMetricFilter);
@Override public void report() { // we do not need to lock here, because the dropwizard registry is // internally a concurrent map @SuppressWarnings("rawtypes") final SortedMap<String, com.codahale.metrics.Gauge> gauges = registry.getGauges(); final SortedMap<String, com.codahale.metrics.Counter> counters = registry.getCounters(); final SortedMap<String, com.codahale.metrics.Histogram> histograms = registry.getHistograms(); final SortedMap<String, com.codahale.metrics.Meter> meters = registry.getMeters(); final SortedMap<String, com.codahale.metrics.Timer> timers = registry.getTimers(); this.reporter.report(gauges, counters, histograms, meters, timers); }
public void reportRegistry(MetricRegistry registry) { Map<String, String> tags = Maps.newHashMap(); if (registry instanceof MetricContext) { tags = Maps.transformValues(((MetricContext) registry).getTagMap(), new Function<Object, String>() { @Override public String apply(Object input) { return input.toString(); } }); } report(registry.getGauges(this.filter), registry.getCounters(this.filter), registry.getHistograms(this.filter), registry.getMeters(this.filter), registry.getTimers(this.filter), tags); }
@VisibleForTesting void reportOnce() { // resolve the additional attributes once per report additionalAttributes = additionalAttributesSupplier.get(); if (additionalAttributes == null) { additionalAttributes = Collections.emptyMap(); } metricRegistry.getGauges().forEach(this::reportGauge); metricRegistry.getCounters().forEach(this::reportCounter); metricRegistry.getMeters().forEach(this::reportMeter); metricRegistry.getHistograms().forEach(this::reportHistogram); metricRegistry.getTimers().forEach(this::reportTimer); }
@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); }
@GET @Produces("application/json") @Path("/meters") public Map<String, Long> meters() { return (MapX) MapX.fromMap(metrics.getMeters()) .bimap(k -> k, v -> v.getCount()); }
/** * Report the current values of all metrics in the registry. */ public void report() { synchronized (this) { report(registry.getGauges(filter), registry.getCounters(filter), registry.getHistograms(filter), registry.getMeters(filter), registry.getTimers(filter)); } }
metrics.put("histograms", histograms); Map<String, Object> meters = meters(registry.getMeters(filter), rateUnitLabel, rateFactor, durationUnitLabel, durationFactor); if (meters.size() > 0) {
@Test public void normal() throws Exception { makeRequest("world"); makeRequest("world"); makeRequest("space"); makeRequest("world"); makeRequest("space"); makeRequest("space"); makeRequest("world"); await().untilAsserted(() -> { assertThat(dropwizardRegistry.getMeters() .get(clientMetricNameWithStatusAndResult("requests", 200, "failure")) .getCount()).isEqualTo(3L); assertThat(dropwizardRegistry.getMeters() .get(serverMetricNameWithStatusAndResult("requests", 200, "failure")) .getCount()).isEqualTo(3L); assertThat(dropwizardRegistry.getMeters() .get(clientMetricNameWithStatusAndResult("requests", 200, "success")) .getCount()).isEqualTo(4L); assertThat(dropwizardRegistry.getMeters() .get(serverMetricNameWithStatusAndResult("requests", 200, "success")) .getCount()).isEqualTo(4L); assertTimer("requestDuration", 7); assertHistogram("requestLength", 7); assertTimer("responseDuration", 7); assertHistogram("responseLength", 7); assertTimer("totalDuration", 7); }); }
public TimelockServiceStatus getStatus() { Map<String, Meter> meters = metricRegistry.getMeters(); if (!meters.containsKey(AtlasDbMetricNames.TIMELOCK_SUCCESSFUL_REQUEST) || !meters.containsKey(AtlasDbMetricNames.TIMELOCK_FAILED_REQUEST)) { throw new IllegalStateException("Timelock client metrics is not properly set"); } double successfulRequestRate = meters.get(AtlasDbMetricNames.TIMELOCK_SUCCESSFUL_REQUEST).getFiveMinuteRate(); double failedRequestRate = meters.get(AtlasDbMetricNames.TIMELOCK_FAILED_REQUEST).getFiveMinuteRate(); if (successfulRequestRate >= failedRequestRate) { return TimelockServiceStatus.HEALTHY; } else { return TimelockServiceStatus.UNHEALTHY; } } }
@Override public List<MetricFamilySamples> collect() { Map<String, MetricFamilySamples> mfSamplesMap = new HashMap<String, MetricFamilySamples>(); for (SortedMap.Entry<String, Gauge> entry : registry.getGauges().entrySet()) { addToMap(mfSamplesMap, fromGauge(entry.getKey(), entry.getValue())); } for (SortedMap.Entry<String, Counter> entry : registry.getCounters().entrySet()) { addToMap(mfSamplesMap, fromCounter(entry.getKey(), entry.getValue())); } for (SortedMap.Entry<String, Histogram> entry : registry.getHistograms().entrySet()) { addToMap(mfSamplesMap, fromHistogram(entry.getKey(), entry.getValue())); } for (SortedMap.Entry<String, Timer> entry : registry.getTimers().entrySet()) { addToMap(mfSamplesMap, fromTimer(entry.getKey(), entry.getValue())); } for (SortedMap.Entry<String, Meter> entry : registry.getMeters().entrySet()) { addToMap(mfSamplesMap, fromMeter(entry.getKey(), entry.getValue())); } return new ArrayList<MetricFamilySamples>(mfSamplesMap.values()); }
SortedMap<String, Meter> meters = metricRegistry.getMeters(); if (meters.size() > 0) { writeMeters(meters, writer);
@Test public void registersMeters() { metricsManager.registerOrGetMeter(LIST_CLASS, RUNTIME, METER_NAME); assertThat(registry.getMeters().keySet()).containsExactly( MetricRegistry.name(LIST_CLASS, RUNTIME, METER_NAME)); }
/** * Returns a map of all the meters in the registry and their names. * * @return all the meters in the registry */ public SortedMap<String, Meter> getMeters() { return getMeters(MetricFilter.ALL); }
1); Assert.assertEquals( HelixKafkaMirrorMakerMetricsReporter.get().getRegistry().getMeters().get("testMeter0") .getCount(), 1);
@RolesAllowed(AdminModule.RESTX_ADMIN_ROLE) @GET("/@/metrics") public Map metrics() { return ImmutableMap.of( "gauges", metrics.getGauges(), "timers", metrics.getTimers(), "meters", metrics.getMeters(), "counters", metrics.getCounters(), "histograms", metrics.getHistograms() ); }
/** * Report the current values of all metrics in the registry. */ public void report() { report(registry.getGauges(filter), registry.getCounters(filter), registry.getHistograms(filter), registry.getMeters(filter), registry.getTimers(filter)); }
public static BsonDocument generateMetricsBson(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit) { MetricsJsonGenerator generator = new MetricsJsonGenerator(rateUnit, durationUnit); return new BsonDocument() .append("version", new BsonString("3.0.0")) .append("gauges", generator.toBson(registry.getGauges(), generator::generateGauge)) .append("counters", generator.toBson(registry.getCounters(), generator::generateCounter)) .append("histograms", generator.toBson(registry.getHistograms(), generator::generateHistogram)) .append("meters", generator.toBson(registry.getMeters(), generator::generateMeter)) .append("timers", generator.toBson(registry.getTimers(), generator::generateTimer)); } private final String singularRateUnitString;