public SemanticMetricsFactory(final SemanticMetricRegistry metricRegistry, Predicate<What> enabledMetrics, Set<Integer> precreateCodes, DurationThresholdConfig durationThresholdConfig) { this.metricRegistry = metricRegistry; this.metricId = MetricId.build(); this.enabledMetrics = enabledMetrics; this.precreateCodes = precreateCodes; this.durationThresholdConfig = durationThresholdConfig; }
public DurationThresholdTracker(MetricId id, SemanticMetricRegistry metricRegistry, Integer threshold) { final MetricId thresholdId = id.tagged("what", ENDPOINT_REQUEST_DURATION_THRESHOLD_RATE.tag()) .tagged("threshold", threshold.toString()); this.durationThresholdMeter = metricRegistry.meter(thresholdId); this.threshold = threshold; }
private void registerRatioGauge(MetricId metricId, String stat, Supplier<Ratio> ratioSupplier, SemanticMetricRegistry metricRegistry, What what) { metricRegistry.register( metricId.tagged("what", what.tag(), "stat", stat), new RatioGauge() { @Override protected Ratio getRatio() { return ratioSupplier.get(); } }); }
public InstrumentedExecutorService( ExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId) { MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); this.delegate = delegate; this.submitted = registry.meter(baseMetricIdWithUnit.tagged("what", "submitted")); this.running = registry.counter(baseMetricIdWithUnit.tagged("what", "running")); this.completed = registry.meter(baseMetricIdWithUnit.tagged("what", "completed")); this.idle = registry.timer(baseMetricId.tagged("what", "idle")); this.duration = registry.timer(baseMetricId.tagged("what", "duration")); }
@Override public ServiceMetrics createForService(String serviceName) { final MetricId id = metricId.tagged("service", serviceName); return new SemanticServiceMetrics(metricRegistry, id, precreateCodes, enabledMetrics, durationThresholdConfig); } }
@Provides @Singleton public SemanticMetricRegistry semanticMetricRegistry(MetricsConfig metricsConfig) { final SemanticMetricRegistry metricRegistry = new SemanticMetricRegistry( () -> new ReservoirWithTtl(metricsConfig.reservoirTtl())); metricRegistry.register(MetricId.EMPTY, new MemoryUsageGaugeSet()); metricRegistry.register(MetricId.EMPTY, new GarbageCollectorMetricSet()); metricRegistry.register(MetricId.EMPTY, new ThreadStatesMetricSet()); metricRegistry.register(MetricId.EMPTY, CpuGaugeSet.create()); metricRegistry.register(MetricId.EMPTY, new SemanticMetricSet() { private FileDescriptorRatioGauge fileDescriptorRatioGauge = new FileDescriptorRatioGauge();
/** * Creates a new {@link Timer} with a custom {@link Reservoir} and registers it under the given * name. * * @param name the name of the metric * @param reservoirSupplier a {@link Supplier} that returns an instance of {@link Reservoir} * @return a new {@link Timer} */ public Timer timer(final MetricId name, Supplier<Reservoir> reservoirSupplier) { return getOrAdd(name, SemanticMetricBuilderFactory.timerWithReservoir(reservoirSupplier)); }
/** * Creates a new {@link Histogram} and registers it under the given name. * * @param name the name of the metric * @return a new {@link Histogram} */ public Histogram histogram(final MetricId name) { return getOrAdd(name, SemanticMetricBuilderFactory.histogramWithReservoir(defaultReservoirSupplier)); }
private CachedMeters metersForEndpoint(String endpoint) { MetricId id = metricId.tagged("endpoint", endpoint);
/** * Creates a new {@link Timer} and registers it under the given name. * * @param name the name of the metric * @return a new {@link Timer} */ public Timer timer(final MetricId name) { return getOrAdd(name, SemanticMetricBuilderFactory.timerWithReservoir(defaultReservoirSupplier)); }
@Override public Map<MetricId, Metric> getMetrics() { final Map<MetricId, Metric> gauges = new HashMap<>(); final MetricId metricId = MetricId.build().tagged("what", "file-descriptor-ratio", "unit", "%"); gauges.put(metricId, (Gauge<Object>) () -> { try { return fileDescriptorRatioGauge.getValue(); } catch (final Exception ex) { LOG.debug("Failed to get metrics for FileDescriptorGaugeSet", ex); // This is what the upstream FileDescriptorRatioGauge returns when an exception occurs. return RatioGauge.Ratio.of(Double.NaN, Double.NaN); } }); return Collections.unmodifiableMap(gauges); } });