private Optional<Meter> droppedRequests(MetricId id) { return enabledMetrics.test(DROPPED_REQUEST_RATE) ? Optional.of(metricRegistry.meter( id.tagged( "what", DROPPED_REQUEST_RATE.tag(), "unit", "request" ))) : Optional.empty(); }
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(); } }); }
private Optional<Timer> requestDurationTimer(MetricId id) { return enabledMetrics.test(ENDPOINT_REQUEST_DURATION) ? Optional.of(metricRegistry .timer(id.tagged("what", ENDPOINT_REQUEST_DURATION.tag()))) : Optional.empty(); }
@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();
/** * Wraps an {@link java.util.concurrent.ScheduledExecutorService} with an explicit name. * * @param delegate {@link java.util.concurrent.ScheduledExecutorService} to wrap. * @param registry {@link SemanticMetricRegistry} that will contain the metrics. * @param baseMetricId base metric id for this executor service. */ public InstrumentedScheduledExecutorService( ScheduledExecutorService delegate, SemanticMetricRegistry registry, MetricId baseMetricId ) { this.delegate = delegate; MetricId baseMetricIdWithUnit = baseMetricId.tagged("unit", "task"); 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.duration = registry.timer(baseMetricIdWithUnit.tagged("what", "duration")); this.scheduledOnce = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.once")); this.scheduledRepetitively = registry.meter(baseMetricIdWithUnit.tagged("what", "scheduled.repetitively")); this.scheduledOverrun = registry.counter(baseMetricIdWithUnit.tagged("what", "scheduled.overrun")); this.percentOfPeriod = registry.histogram(baseMetricIdWithUnit.tagged("what", "scheduled.percent-of-period")); }
private void report( @SuppressWarnings("rawtypes") SortedMap<MetricId, Gauge> gauges, SortedMap<MetricId, Counter> counters, SortedMap<MetricId, Histogram> histograms, SortedMap<MetricId, Meter> meters, SortedMap<MetricId, Timer> timers, SortedMap<MetricId, DerivingMeter> derivingMeters ) { for (@SuppressWarnings("rawtypes") Map.Entry<MetricId, Gauge> entry : gauges.entrySet()) { reportGauge(entry.getKey(), entry.getValue()); } for (Map.Entry<MetricId, Counter> entry : counters.entrySet()) { reportCounter(entry.getKey(), entry.getValue()); } for (Map.Entry<MetricId, Histogram> entry : histograms.entrySet()) { reportHistogram(entry.getKey(), entry.getValue()); } for (Map.Entry<MetricId, Meter> entry : meters.entrySet()) { reportMetered(entry.getKey(), entry.getValue()); } for (Map.Entry<MetricId, Timer> entry : timers.entrySet()) { reportTimer(entry.getKey(), entry.getValue()); } for (Map.Entry<MetricId, DerivingMeter> entry : derivingMeters.entrySet()) { reportDerivingMeter(entry.getKey(), entry.getValue()); } }
this.gets = registry.timer(getId); this.getHits = registry.meter(getMetersId.tagged("result", "success", "cache-result", "hit")); this.getMisses = registry.meter(getMetersId.tagged("result", "success", "cache-result", "miss")); this.getFailures = registry.meter(getMetersId.tagged("result", "failure")); registry.register(getId.tagged("what", "memcache-hit-ratio", "unit", "%"), hitRatio); this.sets = registry.timer(setId); MetricId setMetersId = MetricId.join(setId, meterId); this.setSuccesses = registry.meter(setMetersId.tagged("result", "success")); this.setFailures = registry.meter(setMetersId.tagged("result", "failure")); this.multigets = registry.timer(multigetId); MetricId multigetMetersId = MetricId.join(multigetId, meterId); this.multigetSuccesses = registry.meter(multigetMetersId.tagged("result", "success")); this.multigetFailures = registry.meter(multigetMetersId.tagged("result", "failure")); this.deletes = registry.timer(deleteId); MetricId deleteMetersId = MetricId.join(deleteId, meterId); this.deleteSuccesses = registry.meter(deleteMetersId.tagged("result", "success")); this.deleteFailures = registry.meter(deleteMetersId.tagged("result", "failure")); this.incrDecrs = registry.timer(incrDecrId); MetricId incrDecrMetersId = MetricId.join(incrDecrId, meterId); this.incrDecrSuccesses = registry.meter(incrDecrMetersId.tagged("result", "success")); this.incrDecrFailures = registry.meter(incrDecrMetersId.tagged("result", "failure"));
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")); }
registry.meter(m.tagged("what", "sent-metrics", "unit", "metric")); private final Meter sentEvents = registry.meter(m.tagged("what", "sent-events", "unit", "event")); private final Meter sentBatches = registry.meter(m.tagged("what", "sent-batches", "unit", "batches")); registry.meter(m.tagged("what", "sent-total", "unit", "count")); registry.meter(m.tagged("what", "batched-into-batches", "unit", "count")); registry.getOrAdd(m.tagged("what", "write-batch-size"), HISTOGRAM_BUILDER); registry.counter(m.tagged("what", "total-enqueued", "unit", "count")); registry.counter(m.tagged("what", "pending-writes", "unit", "count")); registry.getOrAdd(m.tagged("what", "write-latency"), HISTOGRAM_BUILDER); registry.meter(m.tagged("what", "metrics-dropped-by-filter", "unit", "metric")); private final Meter eventsDroppedByFilter = registry.meter(m.tagged("what", "events-dropped-by-filter", "unit", "event"));
static Metrics create(final SemanticMetricRegistry registry, final MetricId metricId) { final MetricId predictDurationId = metricId.tagged("what", PREDICT_DURATION.tag()); final MetricId predictRateId = metricId.tagged("what", PREDICT_RATE.tag()); final MetricId extractDuration = metricId.tagged("what", FEATURE_EXTRACT_DURATION.tag()); final MetricId extractRate = metricId.tagged("what", FEATURE_EXTRACT_RATE.tag()); final Timer predictTimer = registry.timer(predictDurationId); final Meter predictMeter = registry.meter(predictRateId); final Timer extractTimer = registry.timer(extractDuration); final Meter extractMeter = registry.meter(extractRate); return new AutoValue_SemanticPredictorMetrics_Metrics( predictTimer, predictMeter, extractTimer, extractMeter); } }
public MetricsStats(SemanticMetricRegistry registry, Time time) { this.registry = Objects.requireNonNull(registry); this.time = Objects.requireNonNull(time, "time"); this.submitToRunning = registry.getOrAdd(TRANSITIONING_DURATION, HISTOGRAM); this.pullImageErrorMeter = registry.meter(PULL_IMAGE_ERROR_RATE); this.naturalTrigger = registry.meter(NATURAL_TRIGGER_RATE); this.terminationLogMissing = registry.meter(TERMINATION_LOG_MISSING); this.terminationLogInvalid = registry.meter(TERMINATION_LOG_INVALID); this.exitCodeMismatch = registry.meter(EXIT_CODE_MISMATCH); this.workflowConsumerErrorMeter = registry.meter(WORKFLOW_CONSUMER_ERROR_RATE); this.counterCacheHitMeter = registry.meter(COUNTER_CACHE_RATE.tagged(COUNTER_CACHE_RESULT, COUNTER_CACHE_HIT)); this.counterCacheMissMeter = registry.meter(COUNTER_CACHE_RATE.tagged(COUNTER_CACHE_RESULT, COUNTER_CACHE_MISS)); this.storageOperationHistograms = new ConcurrentHashMap<>(); this.storageOperationMeters = new ConcurrentHashMap<>(); this.dockerOperationHistograms = new ConcurrentHashMap<>(); this.dockerOperationMeters = new ConcurrentHashMap<>(); this.exitCodeMeters = new ConcurrentHashMap<>(); this.dockerOperationErrorMeters = new ConcurrentHashMap<>(); this.resourceConfiguredHistograms = new ConcurrentHashMap<>(); this.resourceUsedHistograms = new ConcurrentHashMap<>(); this.resourceDemandedHistograms = new ConcurrentHashMap<>(); this.eventConsumerErrorMeters = new ConcurrentHashMap<>(); this.eventConsumerMeters = new ConcurrentHashMap<>(); this.publishingMeters = new ConcurrentHashMap<>(); this.publishingErrorMeters = new ConcurrentHashMap<>(); this.workflowConsumerMeters = new ConcurrentHashMap<>(); this.tickHistograms = new ConcurrentHashMap<>(); this.datastoreOperationMeters = new ConcurrentHashMap<>(); }
/** * Creates a new {@link Counter} and registers it under the given name. * * @param name the name of the metric * @return a new {@link Counter} */ public Counter counter(final MetricId name) { return getOrAdd(name, SemanticMetricBuilder.COUNTERS); }
private void createConnectionCounterGauge() { final MetricId gaugeId = id.tagged("what", "global-connections", "unit", "connections"); // registry doesn't allow duplicate registrations, so remove the metric if already existing synchronized (registry) { registry.remove(gaugeId); registry.register(gaugeId, (Gauge<Integer>) Utils::getGlobalConnectionCount); } } }
protected void registerAll(final MetricId prefix, final SemanticMetricSet metrics) throws IllegalArgumentException { for (final Map.Entry<MetricId, Metric> entry : metrics.getMetrics().entrySet()) { if (entry.getValue() instanceof SemanticMetricSet) { registerAll(MetricId.join(prefix, entry.getKey()), (SemanticMetricSet) entry.getValue()); } else { register(MetricId.join(prefix, entry.getKey()), entry.getValue()); } } }
/** * Returns a map of all the counters in the registry and their names. * * @return all the counters in the registry */ public SortedMap<MetricId, Counter> getCounters() { return getCounters(SemanticMetricFilter.ALL); }
/** * Returns a map of all the meters in the registry and their names. * * @return all the meters in the registry */ public SortedMap<MetricId, Meter> getMeters() { return getMeters(SemanticMetricFilter.ALL); }
/** * Returns a map of all the histograms in the registry and their names. * * @return all the histograms in the registry */ public SortedMap<MetricId, Histogram> getHistograms() { return getHistograms(SemanticMetricFilter.ALL); }
/** * Returns a map of all the timers in the registry and their names. * * @return all the timers in the registry */ public SortedMap<MetricId, Timer> getTimers() { return getTimers(SemanticMetricFilter.ALL); }
/** * Returns a map of all the gauges in the registry and their names. * * @return all the gauges in the registry */ @SuppressWarnings("rawtypes") public SortedMap<MetricId, Gauge> getGauges() { return getGauges(SemanticMetricFilter.ALL); }
/** * A counter is just a gauge for an AtomicLong instance. You can increment or decrement its * value. We want a more efficient way of measuring the pending job in a queue */ private static void reportCounter() { // Create or fetch (if it is already created) the metric. final Counter counter = registry.counter(APP_PREFIX.tagged("what", "job-count")); // Somewhere in your code where you are adding new jobs to the queue you increment the // counter as well counter.inc(); // Oh look! Another job! counter.inc(); // Somewhere in your code the job is going to be removed from the queue you decrement the // counter counter.dec(); // That's it! The rest will be automatically done inside semantic metrics library. The // reported measurements will be kept in the registry. // Every time the reporter wants to report, the current value of the counter will be read // and // a datapoint will be created and reported. }