public DataSourcePoolMetrics(DataSource dataSource, DataSourcePoolMetadataProvider metadataProvider, String name, Iterable<Tag> tags) { Assert.notNull(dataSource, "DataSource must not be null"); Assert.notNull(metadataProvider, "MetadataProvider must not be null"); this.dataSource = dataSource; this.metadataProvider = new CachingDataSourcePoolMetadataProvider( metadataProvider); this.tags = Tags.concat(tags, "name", name); }
private void addSourceMetrics(MeterRegistry registry) { for (String source : configurer.getSourceNames()) { MessageSourceMetrics sourceMetrics = configurer.getSourceMetrics(source); Iterable<Tag> tagsWithSource = Tags.concat(tags, "source", source); FunctionCounter.builder("spring.integration.source.messages", sourceMetrics, MessageSourceMetrics::getMessageCount) .tags(tagsWithSource) .description("The number of successful handler calls") .register(registry); } }
@SuppressWarnings("ConstantConditions") @Override protected io.micrometer.core.instrument.DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) { com.netflix.spectator.api.DistributionSummary internalSummary; if (distributionStatisticConfig.isPercentileHistogram()) { // This doesn't report the normal count/totalTime/max stats, so we treat it as additive internalSummary = PercentileDistributionSummary.get(registry, spectatorId(id)); } else { internalSummary = registry.distributionSummary(spectatorId(id)); } SpectatorDistributionSummary summary = new SpectatorDistributionSummary(id, internalSummary, clock, distributionStatisticConfig, scale); HistogramGauges.register(summary, this, percentile -> id.getName(), percentile -> Tags.concat(id.getTagsAsIterable(), "percentile", DoubleFormat.decimalOrNan(percentile.percentile())), ValueAtPercentile::value, bucket -> id.getName(), bucket -> Tags.concat(id.getTagsAsIterable(), "sla", DoubleFormat.decimalOrWhole(bucket.bucket()))); return summary; }
@SuppressWarnings("ConstantConditions") @Override protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) { com.netflix.spectator.api.Timer internalTimer; if (distributionStatisticConfig.isPercentileHistogram()) { // This doesn't report the normal count/totalTime/max stats, so we treat it as additive internalTimer = PercentileTimer.get(registry, spectatorId(id)); } else { internalTimer = registry.timer(spectatorId(id)); } SpectatorTimer timer = new SpectatorTimer(id, internalTimer, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit()); HistogramGauges.register(timer, this, percentile -> id.getName(), percentile -> Tags.concat(id.getTagsAsIterable(), "percentile", DoubleFormat.decimalOrNan(percentile.percentile())), percentile -> percentile.value(timer.baseTimeUnit()), bucket -> id.getName(), bucket -> Tags.concat(id.getTagsAsIterable(), "sla", DoubleFormat.decimalOrWhole(bucket.bucket(timer.baseTimeUnit())))); return timer; }
@Override public void process(Exchange exchange) { Message in = exchange.getIn(); String defaultMetricsName = simple(exchange, getEndpoint().getMetricsName(), String.class); String finalMetricsName = getStringHeader(in, HEADER_METRIC_NAME, defaultMetricsName); Iterable<Tag> defaultTags = getEndpoint().getTags(); Iterable<Tag> headerTags = getTagHeader(in, HEADER_METRIC_TAGS, Tags.empty()); Iterable<Tag> finalTags = Tags.concat(defaultTags, headerTags).stream() .map(tag -> Tag.of( simple(exchange, tag.getKey(), String.class), simple(exchange, tag.getValue(), String.class))) .reduce(Tags.empty(), Tags::and, Tags::and) .and(Tags.of( CAMEL_CONTEXT_TAG, getEndpoint().getCamelContext().getName())); try { doProcess(exchange, finalMetricsName, finalTags); } catch (Exception e) { exchange.setException(e); } finally { clearMetricsHeaders(in); } }
@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); } }
private void addChannelMetrics(MeterRegistry registry) { for (String channel : configurer.getChannelNames()) { MessageChannelMetrics channelMetrics = configurer.getChannelMetrics(channel); Iterable<Tag> tagsWithChannel = Tags.concat(tags, "channel", channel); FunctionCounter.builder("spring.integration.channel.sendErrors", channelMetrics, MessageChannelMetrics::getSendErrorCount) .tags(tagsWithChannel) .description("The number of failed sends (either throwing an exception or rejected by the channel)") .register(registry); FunctionCounter.builder("spring.integration.channel.sends", channelMetrics, MessageChannelMetrics::getSendCount) .tags(tagsWithChannel) .description("The number of successful sends") .register(registry); if (channelMetrics instanceof PollableChannelManagement) { FunctionCounter.builder("spring.integration.receives", (PollableChannelManagement) channelMetrics, PollableChannelManagement::getReceiveCount) .tags(tagsWithChannel) .description("The number of messages received") .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); } }