@Override public Gauge getOrCreateGauge(final String name, final Context... tags) { final List<io.micrometer.core.instrument.Tag> tagList = new ArrayList<>(); tagList.addAll(TagUtil.convertTags(tags)); tagList.addAll(TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts())); final AtomicReference<Double> internalValue = new AtomicReference<Double>(0d); io.micrometer.core.instrument.Gauge gauge = io.micrometer.core.instrument.Gauge .builder("name", internalValue, r -> Optional.ofNullable(r.get()).orElse(0d)) .tags(tagList) .register(registry.get()); return new Gauge() { @Override public void setValue(final double value) { internalValue.set(value); } @Override public String getName() { return name; } @Override public List<Context> getContext() { return Collections.unmodifiableList(Arrays.asList(tags)); } @Override public void close() throws Exception { } }; }
@Override public void bindTo(MeterRegistry registry) { for (FileStore fileStore : FileSystems.getDefault().getFileStores()) { LOG.debug("Add gauge metric for {}", fileStore.name()); Iterable<Tag> tagsWithPath = Tags.concat(Tags.empty(), "path", fileStore.toString()); Gauge.builder("disk.free", fileStore, exceptionToNonWrapper(FileStore::getUnallocatedSpace)) .tags(tagsWithPath) .description("Unallocated space for file store") .baseUnit("bytes") .strongReference(true) .register(registry); Gauge.builder("disk.total", fileStore, exceptionToNonWrapper(FileStore::getTotalSpace)) .tags(tagsWithPath) .description("Total space for file store") .baseUnit("bytes") .strongReference(true) .register(registry); Gauge.builder("disk.usable", fileStore, exceptionToNonWrapper(FileStore::getUsableSpace)) .tags(tagsWithPath) .description("Usable space for file store") .baseUnit("bytes") .strongReference(true) .register(registry); } }
@Override public void bindTo(MeterRegistry registry) { for (Map.Entry<String, KafkaMessageChannelBinder.TopicInformation> topicInfo : this.binder.getTopicsInUse() .entrySet()) { if (!topicInfo.getValue().isConsumerTopic()) { continue; } String topic = topicInfo.getKey(); String group = topicInfo.getValue().getConsumerGroup(); Gauge.builder(METRIC_NAME, this, (o) -> computeUnconsumedMessages(topic, group)) .tag("group", group) .tag("topic", topic) .description("Unconsumed messages for a particular group and topic") .register(registry); } }
.description("count of spans per message") .tag("transport", transport) .register(registryInstance); this.messageBytes = new AtomicInteger(0); Gauge.builder("zipkin_collector.message_bytes", messageBytes, AtomicInteger::get) .description("size of a message containing serialized spans") .tag("transport", transport) .baseUnit("bytes") .register(registryInstance);
.tags(tags) .description("thread state NEW count") .register(registry); Gauge.builder("jvm.thread.RUNNABLE.sum", threadStateBean, ThreadStateBean::getThreadStatusRUNNABLECount) .tags(tags) .description("thread state RUNNABLE count") .register(registry); .tags(tags) .description("thread state BLOCKED count") .register(registry); .tags(tags) .description("thread state WAITING count") .register(registry); .tags(tags) .description("thread state TIMED_WAITING count") .register(registry); .tags(tags) .description("thread state TERMINATED count") .register(registry);
.tags(tags) .description("thread state NEW count") .register(registry); Gauge.builder("jvm.thread.RUNNABLE.sum", threadStateBean, ThreadStateBean::getThreadStatusRUNNABLECount) .tags(tags) .description("thread state RUNNABLE count") .register(registry); .tags(tags) .description("thread state BLOCKED count") .register(registry); .tags(tags) .description("thread state WAITING count") .register(registry); .tags(tags) .description("thread state TIMED_WAITING count") .register(registry); .tags(tags) .description("thread state TERMINATED count") .register(registry);
private void addHandlerMetrics(MeterRegistry registry) { for (String handler : configurer.getHandlerNames()) { MessageHandlerMetrics handlerMetrics = configurer.getHandlerMetrics(handler); Iterable<Tag> tagsWithHandler = Tags.concat(tags, "handler", handler); TimeGauge.builder("spring.integration.handler.duration.max", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMaxDuration) .tags(tagsWithHandler) .description("The maximum handler duration") .register(registry); TimeGauge.builder("spring.integration.handler.duration.min", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMinDuration) .tags(tagsWithHandler) .description("The minimum handler duration") .register(registry); TimeGauge.builder("spring.integration.handler.duration.mean", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMeanDuration) .tags(tagsWithHandler) .description("The mean handler duration") .register(registry); Gauge.builder("spring.integration.handler.activeCount", handlerMetrics, MessageHandlerMetrics::getActiveCount) .tags(tagsWithHandler) .description("The number of active handlers") .register(registry); } }
private void monitor(MeterRegistry registry, ThreadPoolExecutor tp) { FunctionCounter.builder(name + ".completed", tp, ThreadPoolExecutor::getCompletedTaskCount) .tags(tags) .description("The approximate total number of tasks that have completed execution") .register(registry); Gauge.builder(name + ".active", tp, ThreadPoolExecutor::getActiveCount) .tags(tags) .description("The approximate number of threads that are actively executing tasks") .register(registry); Gauge.builder(name + ".queued", tp, tpRef -> tpRef.getQueue().size()) .tags(tags) .description("The approximate number of threads that are queued for execution") .register(registry); Gauge.builder(name + ".pool", tp, ThreadPoolExecutor::getPoolSize) .tags(tags) .description("The current number of threads in the pool") .register(registry); } }
private void averages(MeterRegistry registry) { Gauge.builder("cache.puts.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageWriteTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache puts") .register(registry); Gauge.builder("cache.gets.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageReadTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache gets") .register(registry); Gauge.builder("cache.removes.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageRemoveTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache removes") .register(registry); } }
private void nearCacheMetrics(MeterRegistry registry) { if (isNearCacheEnabled()) { Gauge.builder("cache.near.requests", cache, cache -> cache.clientStatistics().getNearCacheHits()) .tags(getTagsWithCacheName()).tag("result", "hit") .description("The number of hits (reads) of near cache entries owned by this client") .register(registry); Gauge.builder("cache.near.requests", cache, cache -> cache.clientStatistics().getNearCacheMisses()) .tags(getTagsWithCacheName()).tag("result", "miss") .description("The number of hits (reads) of near cache entries owned by this client") .register(registry); Gauge.builder("cache.near.invalidations", cache, cache -> cache.clientStatistics().getNearCacheInvalidations()) .tags(getTagsWithCacheName()) .description("The number of invalidations of near cache entries owned by this client") .register(registry); Gauge.builder("cache.near.size", cache, cache -> cache.clientStatistics().getNearCacheSize()) .tags(getTagsWithCacheName()) .description("The size of the near cache owned by this client") .register(registry); } }
private void averages(MeterRegistry registry) { Gauge.builder("cache.puts.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageWriteTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache puts") .register(registry); Gauge.builder("cache.gets.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageReadTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache gets") .register(registry); Gauge.builder("cache.removes.latency", cache, cache -> cache.getAdvancedCache().getStats().getAverageRemoveTime()) .baseUnit(TimeUnit.MILLISECONDS.name()) .tags(getTagsWithCacheName()) .description("Cache removes") .register(registry); } }
@Override protected void bindImplementationSpecificMetrics(MeterRegistry registry) { if (cache == null) return; Gauge.builder("cache.start", cache, cache -> cache.getAdvancedCache().getStats().getTimeSinceStart()) .baseUnit(TimeUnit.SECONDS.name()) .tags(getTagsWithCacheName()) .description("Time elapsed since start") .register(registry); Gauge.builder("cache.reset", cache, cache -> cache.getAdvancedCache().getStats().getTimeSinceReset()) .baseUnit(TimeUnit.SECONDS.name()) .tags(getTagsWithCacheName()) .description("Time elapsed since the last statistics reset") .register(registry); memory(registry); averages(registry); }
private void memory(MeterRegistry registry) { Gauge.builder("cache.memory.size", cache, cache -> cache.getAdvancedCache().getStats().getCurrentNumberOfEntriesInMemory()) .tags(getTagsWithCacheName()) .description("Number of entries currently in the cache, excluding passivated entries") .register(registry); if (cache.getCacheConfiguration().memory().evictionStrategy().isEnabled()) { Gauge.builder("cache.memory.used", cache, cache -> cache.getAdvancedCache().getStats().getDataMemoryUsed()) .tags(getTagsWithCacheName()) .description("Provides how much memory the current eviction algorithm estimates is in use for data") .register(registry); } Gauge.builder("cache.memory.offHeap", cache, cache -> cache.getAdvancedCache().getStats().getOffHeapMemoryUsed()) .tags(getTagsWithCacheName()) .description("The amount of off-heap memory used by this cache") .register(registry); }
@Override public void bindTo(MeterRegistry registry) { for (Map.Entry<String, KafkaMessageChannelBinder.TopicInformation> topicInfo : this.binder.getTopicsInUse() .entrySet()) { if (!topicInfo.getValue().isConsumerTopic()) { continue; } String topic = topicInfo.getKey(); String group = topicInfo.getValue().getConsumerGroup(); Gauge.builder(METRIC_NAME, this, (o) -> computeUnconsumedMessages(topic, group)) .tag("group", group) .tag("topic", topic) .description("Unconsumed messages for a particular group and topic") .register(registry); } }
@Override public void bindTo(MeterRegistry registry) { Gauge.builder("spring.integration.channelNames", configurer, c -> c.getChannelNames().length) .tags(tags) .description("The number of spring integration channels") .register(registry); Gauge.builder("spring.integration.handlerNames", configurer, c -> c.getHandlerNames().length) .tags(tags) .description("The number of spring integration handlers") .register(registry); Gauge.builder("spring.integration.sourceNames", configurer, c -> c.getSourceNames().length) .tags(tags) .description("The number of spring integration sources") .register(registry); registries.add(registry); }
private void memory(MeterRegistry registry) { Gauge.builder("cache.memory.size", cache, cache -> cache.getAdvancedCache().getStats().getCurrentNumberOfEntriesInMemory()) .tags(getTagsWithCacheName()) .description("Number of entries currently in the cache, excluding passivated entries") .register(registry); if (cache.getCacheConfiguration().memory().evictionStrategy().isEnabled()) { Gauge.builder("cache.memory.used", cache, cache -> cache.getAdvancedCache().getStats().getDataMemoryUsed()) .tags(getTagsWithCacheName()) .description("Provides how much memory the current eviction algorithm estimates is in use for data") .register(registry); } Gauge.builder("cache.memory.offHeap", cache, cache -> cache.getAdvancedCache().getStats().getOffHeapMemoryUsed()) .tags(getTagsWithCacheName()) .description("The amount of off-heap memory used by this cache") .register(registry); }
@Override protected void bindImplementationSpecificMetrics(MeterRegistry registry) { if (cache == null) return; Gauge.builder("cache.start", cache, cache -> cache.getAdvancedCache().getStats().getTimeSinceStart()) .baseUnit(TimeUnit.SECONDS.name()) .tags(getTagsWithCacheName()) .description("Time elapsed since start") .register(registry); Gauge.builder("cache.reset", cache, cache -> cache.getAdvancedCache().getStats().getTimeSinceReset()) .baseUnit(TimeUnit.SECONDS.name()) .tags(getTagsWithCacheName()) .description("Time elapsed since the last statistics reset") .register(registry); memory(registry); averages(registry); }
private void averages(MeterRegistry registry) { Gauge.builder("cache.puts.latency", cache, cache -> cache.clientStatistics().getAverageRemoteStoreTime()) .tags(getTagsWithCacheName()) .description("Cache puts") .register(registry); Gauge.builder("cache.gets.latency", cache, cache -> cache.clientStatistics().getAverageRemoteReadTime()) .tags(getTagsWithCacheName()) .description("Cache gets") .register(registry); Gauge.builder("cache.removes.latency", cache, cache -> cache.clientStatistics().getAverageRemoteRemovesTime()) .tags(getTagsWithCacheName()) .description("Cache removes") .register(registry); }
public synchronized T get(String... values) { // This method is synchronized to make sure the "T" built via supplier will match the one passed to Gauge // since it is stored as WeakReference in Micrometer DefaultGauge, it must not be lost. T t = tSupplier.get(); // Register this gauge if necessary // Note: we need here to go through the process of Gauge creation, even if it already exists, // in order to get the Gauge ID. This ID generation is not trivial since it may involves attached MetricFilters. // Micrometer will not register the gauge twice if it was already created. Gauge g = Gauge.builder(name, t, dGetter) .description(description) .tags(Labels.toTags(keys, values)) .register(registry); return gauges.computeIfAbsent(g.getId(), v -> t); } }