/** * Returns a map of all the gauges in the registry and their names. * * @return all the gauges in the registry */ @SuppressWarnings("rawtypes") public SortedMap<String, Gauge> getGauges() { return getGauges(MetricFilter.ALL); }
/** * Registers a gauge if it has not been registered. * * @param name the gauge name * @param metric the gauge * @param <T> the type */ public static synchronized <T> void registerGaugeIfAbsent(String name, Gauge<T> metric) { if (!METRIC_REGISTRY.getGauges().containsKey(name)) { METRIC_REGISTRY.register(name, metric); } }
public static <T> SimpleGauge<T> gauge( T initialValue, String name, String topologyId, String componentId, Integer taskId, Integer port) { String metricName = metricName(name, topologyId, componentId, taskId, port); if (REGISTRY.getGauges().containsKey(metricName)) { return (SimpleGauge) REGISTRY.getGauges().get(metricName); } else { return REGISTRY.register(metricName, new SimpleGauge<>(initialValue)); } }
@Override public void removeGauge(String name) { try { gaugesLock.lock(); gauges.remove(name); // Metrics throws an Exception if we don't do this when the key already exists if (metricRegistry.getGauges().containsKey(name)) { metricRegistry.remove(name); } } finally { gaugesLock.unlock(); } }
private void addGaugeInternal(String name, Gauge gauge) { try { gaugesLock.lock(); gauges.put(name, gauge); // Metrics throws an Exception if we don't do this when the key already exists if (metricRegistry.getGauges().containsKey(name)) { LOGGER.warn("A Gauge with name [" + name + "] already exists. " + " The old gauge will be overwritten, but this is not recommended"); metricRegistry.remove(name); } metricRegistry.register(name, gauge); } finally { gaugesLock.unlock(); } }
private void addGaugeInternal(String name, Gauge gauge) { try { gaugesLock.lock(); gauges.put(name, gauge); // Metrics throws an Exception if we don't do this when the key already exists if (metricRegistry.getGauges().containsKey(name)) { LOGGER.warn("A Gauge with name [" + name + "] already exists. " + " The old gauge will be overwritten, but this is not recommended"); metricRegistry.remove(name); } metricRegistry.register(name, gauge); } finally { gaugesLock.unlock(); } }
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 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; }
@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()); } } }
public long getGaugeValue(final String name) { // Assume that the gauge value can be converted to type long. return (long) this.registry.getGauges().get(name).getValue(); } }
private Object getGauge(String name) { return MetricsSystem.METRIC_REGISTRY.getGauges().get(MetricsSystem.getMetricName(name)) .getValue(); } }
private Object getGauge(String name) { return MetricsSystem.METRIC_REGISTRY.getGauges().get(MetricsSystem.getMetricName(name)) .getValue(); } }
private Object getGauge(String name) { return MetricsSystem.METRIC_REGISTRY.getGauges().get(MetricsSystem.getClusterMetricName(name)) .getValue(); }
private Object getGauge(String metricName, String tagName, String tagValue) { return MetricsSystem.METRIC_REGISTRY.getGauges() .get(MetricsSystem .getClusterMetricName(Metric.getMetricNameWithTags(metricName, tagName, tagValue))) .getValue(); } }
@Test public void testCommandSuccess() throws InterruptedException { Command command = new Command(); command.execute(); Thread.sleep(1000); assertThat((Long) metricRegistry.getGauges().get("hystrix.testGroup.testCommand.countSuccess").getValue(), is(1L)); assertThat((Long) metricRegistry.getGauges().get("hystrix.HystrixThreadPool.threadGroup.totalTaskCount").getValue(), is(1L)); }
@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); }
/** * 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)); } }
@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)); }