io.micrometer.core.instrument.binder.MeterBinder Java Examples

The following examples show how to use io.micrometer.core.instrument.binder.MeterBinder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsMasterMetricsModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  Multibinder<MeterBinder> meterMultibinder =
      Multibinder.newSetBinder(binder(), MeterBinder.class);

  meterMultibinder.addBinding().to(WorkspaceActivityMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceFailureMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceStartTrackerMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceStopTrackerMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceSuccessfulStartAttemptsMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceSuccessfulStopAttemptsMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceStartAttemptsMeterBinder.class);
  meterMultibinder.addBinding().to(UserMeterBinder.class);
  meterMultibinder.addBinding().to(RuntimeLogMeterBinder.class);
  meterMultibinder.addBinding().to(WorkspaceMeterBinder.class);
}
 
Example #2
Source File: MeterRegistryPostProcessor.java    From foremast with Apache License 2.0 6 votes vote down vote up
private MeterRegistryConfigurer getConfigurer() {
    if (this.configurer == null) {
        Collection<MeterBinder> meterBinders = Collections.emptyList();
        Collection<MeterFilter> meterFilters = Collections.emptyList();
        Collection<MeterRegistryCustomizer<?>> meterRegistryCustomizers = Collections.emptyList();
        MetricsProperties properties = beanFactory.getBean(MetricsProperties.class);
        if (beanFactory instanceof ListableBeanFactory) {
            ListableBeanFactory listableBeanFactory = (ListableBeanFactory)beanFactory;
            meterBinders = listableBeanFactory.getBeansOfType(MeterBinder.class).values();
            meterFilters = listableBeanFactory.getBeansOfType(MeterFilter.class).values();
            Map<String, MeterRegistryCustomizer> map = listableBeanFactory.getBeansOfType(MeterRegistryCustomizer.class);
            meterRegistryCustomizers = new ArrayList<>();
            for(MeterRegistryCustomizer c : map.values()) {
                meterRegistryCustomizers.add(c);
            }
        }
        this.configurer = new MeterRegistryConfigurer(
                meterBinders,
                meterFilters,
                meterRegistryCustomizers, properties.isUseGlobalRegistry());
    }
    return this.configurer;
}
 
Example #3
Source File: MeterRegistryPostProcessor.java    From foremast with Apache License 2.0 6 votes vote down vote up
private MeterRegistryConfigurer getConfigurer() {
    if (this.configurer == null) {
        Collection<MeterBinder> meterBinders = Collections.emptyList();
        Collection<MeterFilter> meterFilters = Collections.emptyList();
        Collection<MeterRegistryCustomizer<?>> meterRegistryCustomizers = Collections.emptyList();
        MetricsProperties properties = beanFactory.getBean(MetricsProperties.class);
        if (beanFactory instanceof ListableBeanFactory) {
            ListableBeanFactory listableBeanFactory = (ListableBeanFactory)beanFactory;
            meterBinders = listableBeanFactory.getBeansOfType(MeterBinder.class).values();
            meterFilters = listableBeanFactory.getBeansOfType(MeterFilter.class).values();
            Map<String, MeterRegistryCustomizer> map = listableBeanFactory.getBeansOfType(MeterRegistryCustomizer.class);
            meterRegistryCustomizers = new ArrayList<>();
            for(MeterRegistryCustomizer c : map.values()) {
                meterRegistryCustomizers.add(c);
            }
        }
        this.configurer = new MeterRegistryConfigurer(
                meterBinders,
                meterFilters,
                meterRegistryCustomizers, properties.isUseGlobalRegistry());
    }
    return this.configurer;
}
 
Example #4
Source File: MeterRegistryConfigurer.java    From foremast with Apache License 2.0 5 votes vote down vote up
MeterRegistryConfigurer(Collection<MeterBinder> binders,
                        Collection<MeterFilter> filters,
                        Collection<MeterRegistryCustomizer<?>> customizers,
                        boolean addToGlobalRegistry) {
    this.binders = (binders != null ? binders : Collections.emptyList());
    this.filters = (filters != null ? filters : Collections.emptyList());
    this.customizers = (customizers != null ? customizers : Collections.emptyList());
    this.addToGlobalRegistry = addToGlobalRegistry;
}
 
Example #5
Source File: KafkaBinderConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(MeterRegistry.class)
@ConditionalOnMissingBean(KafkaBinderMetrics.class)
public MeterBinder kafkaBinderMetrics(
		KafkaMessageChannelBinder kafkaMessageChannelBinder,
		KafkaBinderConfigurationProperties configurationProperties,
		MeterRegistry meterRegistry) {

	return new KafkaBinderMetrics(kafkaMessageChannelBinder,
			configurationProperties, null, meterRegistry);
}
 
Example #6
Source File: KafkaBinderConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Bean
public MeterBinder kafkaBinderMetrics(
		KafkaMessageChannelBinder kafkaMessageChannelBinder,
		KafkaBinderConfigurationProperties configurationProperties,
		ConfigurableApplicationContext context) {

	MeterRegistry meterRegistry = context.getBean("outerContext", ApplicationContext.class)
			.getBean(MeterRegistry.class);
	return new KafkaBinderMetrics(kafkaMessageChannelBinder,
			configurationProperties, null, meterRegistry);
}
 
Example #7
Source File: KafkaBinderActuatorTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
public void testKafkaBinderMetricsWhenNoMicrometer() {
	new ApplicationContextRunner().withUserConfiguration(KafkaMetricsTestConfig.class)
			.withClassLoader(new FilteredClassLoader("io.micrometer.core"))
			.run(context -> {
				assertThat(context.getBeanNamesForType(MeterRegistry.class))
						.isEmpty();
				assertThat(context.getBeanNamesForType(MeterBinder.class)).isEmpty();

				DirectFieldAccessor channelBindingServiceAccessor = new DirectFieldAccessor(
						context.getBean(BindingService.class));
				@SuppressWarnings("unchecked")
				Map<String, List<Binding<MessageChannel>>> consumerBindings =
					(Map<String, List<Binding<MessageChannel>>>) channelBindingServiceAccessor
						.getPropertyValue("consumerBindings");
				assertThat(new DirectFieldAccessor(
						consumerBindings.get("input").get(0)).getPropertyValue(
								"lifecycle.messageListenerContainer.beanName"))
										.isEqualTo("setByCustomizer:input");
				assertThat(new DirectFieldAccessor(
						consumerBindings.get("input").get(0)).getPropertyValue(
								"lifecycle.beanName"))
										.isEqualTo("setByCustomizer:input");
				assertThat(new DirectFieldAccessor(
						consumerBindings.get("source").get(0)).getPropertyValue(
								"lifecycle.beanName"))
										.isEqualTo("setByCustomizer:source");

				@SuppressWarnings("unchecked")
				Map<String, Binding<MessageChannel>> producerBindings =
					(Map<String, Binding<MessageChannel>>) channelBindingServiceAccessor
						.getPropertyValue("producerBindings");

				assertThat(new DirectFieldAccessor(
						producerBindings.get("output")).getPropertyValue(
						"lifecycle.beanName"))
						.isEqualTo("setByCustomizer:output");
			});
}
 
Example #8
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 5 votes vote down vote up
Instant(String name, Tags tags, @Nullable String baseUnit,
        @Nullable String failedMessage, Collection<MeterBinder> requires,
        Function<Search, Search> search, Function<Search, Double> toValue) {
    super(name, tags, baseUnit, failedMessage, requires);
    this.search = search;
    this.toValue = toValue;
}
 
Example #9
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 5 votes vote down vote up
NumericQuery(String name, Tags tags, @Nullable String baseUnit,
             @Nullable String failedMessage, Collection<MeterBinder> requires) {
    this.name = name;
    this.tags = tags;
    this.baseUnit = baseUnit;
    this.failedMessage = failedMessage;
    this.requires = requires;
}
 
Example #10
Source File: CommonResilienceHandler.java    From charon-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
void setupMetrics(Function<R, ? extends MeterBinder> metricsCreator) {
    if (meterRegistry == null) {
        return;
    }
    if (metrics == null) {
        metrics = metricsCreator.apply(registry);
        metrics.bindTo(meterRegistry);
    }
}
 
Example #11
Source File: MemcachedCacheIT.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD)
public void whenGettingBooksFromCacheThenReturnCorrectStatistics() {
    bookService.findAll();
    bookService.findAll();
    bookService.findAll();

    bookService.findByTitle("Spring Boot in Action");
    bookService.findByTitle("Spring Boot in Action");
    bookService.findByTitle("Kotlin");
    bookService.findByTitle("Kotlin");
    bookService.findByTitle("Kotlin");

    Cache books = cacheManager.getCache("books");

    Tags expectedTag = Tags.of("app", "test");
    MeterBinder metrics = provider.getMeterBinder(books, expectedTag);

    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    FunctionCounter hits = registry.get("cache.gets").tags(expectedTag).tag("result", "hit").functionCounter();
    FunctionCounter misses = registry.get("cache.gets").tags(expectedTag).tag("result", "miss").functionCounter();

    assertThat(hits.count()).isEqualTo(5);
    assertThat(misses.count()).isEqualTo(3);

    bookService.findAll();
    bookService.findByTitle("Kotlin");

    assertThat(hits.count()).isEqualTo(7);
    assertThat(misses.count()).isEqualTo(3);
}
 
Example #12
Source File: MemcachedCacheMeterBinderProviderConfigurationTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenMemcachedCacheManagerBeanThenCacheStatisticsLoaded() {
    loadContext(CacheWithMemcachedCacheManagerConfiguration.class);

    CacheMeterBinderProvider provider = this.context.getBean(
            "memcachedCacheMeterBinderProvider", CacheMeterBinderProvider.class);

    assertThat(provider).isNotNull();

    CacheManager cacheManager = this.context.getBean(CacheManager.class);
    Cache books = cacheManager.getCache("books");

    MeterBinder metrics = provider.getMeterBinder(books, expectedTag);

    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    FunctionCounter hits = registry.get("cache.gets").tags(expectedTag).tag("result", "hit").functionCounter();
    FunctionCounter misses = registry.get("cache.gets").tags(expectedTag).tag("result", "miss").functionCounter();
    FunctionCounter puts = registry.get("cache.puts").tags(expectedTag).functionCounter();
    double availableServersCount = registry.get("available_servers_count").gauge().value();

    assertThat(hits.count()).isEqualTo(0);
    assertThat(misses.count()).isEqualTo(0);
    assertThat(puts.count()).isEqualTo(0);
    assertThat(availableServersCount).isEqualTo(1.0);

    getCacheKeyValues(books, "a", "b", "b", "c", "d", "c", "a", "a", "a", "d");

    assertThat(hits.count()).isEqualTo(6);
    assertThat(misses.count()).isEqualTo(4);
    assertThat(puts.count()).isEqualTo(0);
    assertThat(availableServersCount).isEqualTo(1.0);
}
 
Example #13
Source File: MeterRegistryConfigurer.java    From foremast with Apache License 2.0 5 votes vote down vote up
MeterRegistryConfigurer(Collection<MeterBinder> binders,
                        Collection<MeterFilter> filters,
                        Collection<MeterRegistryCustomizer<?>> customizers,
                        boolean addToGlobalRegistry) {
    this.binders = (binders != null ? binders : Collections.emptyList());
    this.filters = (filters != null ? filters : Collections.emptyList());
    this.customizers = (customizers != null ? customizers : Collections.emptyList());
    this.addToGlobalRegistry = addToGlobalRegistry;
}
 
Example #14
Source File: RemoteInfinispanCacheMeterBinderProvider.java    From infinispan-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public MeterBinder getMeterBinder(Cache cache, Iterable<Tag> tags) {

   if (cache.getNativeCache() instanceof RemoteCache) {
      return new RemoteInfinispanCacheMeterBinder((RemoteCache) cache.getNativeCache(), tags);
   } else {
      return new RemoteInfinispanCacheMeterBinder(null, tags);
   }
}
 
Example #15
Source File: InfinispanCacheMeterBinderProvider.java    From infinispan-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public MeterBinder getMeterBinder(Cache cache, Iterable<Tag> tags) {
   Object nativeCache = cache.getNativeCache();
   MeterBinder meterBinder = null;
   if (nativeCache instanceof org.infinispan.Cache) {
      meterBinder = new InfinispanCacheMeterBinder((org.infinispan.Cache) nativeCache, tags);
   } else {
      if (nativeCache instanceof javax.cache.Cache){ // for caches like org.infinispan.jcache.embedded.JCache
         meterBinder = new JCacheMetrics((javax.cache.Cache) nativeCache, tags);
      }
   }
   return meterBinder;
}
 
Example #16
Source File: InfrastructureMetricsModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  Multibinder<MeterBinder> meterMultibinder =
      Multibinder.newSetBinder(binder(), MeterBinder.class);

  meterMultibinder.addBinding().to(CurrentLogwatchersMeterBinder.class);
}
 
Example #17
Source File: MetricsModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(MetricsServer.class).asEagerSingleton();
  bind(MetricsBinder.class).asEagerSingleton();
  bind(CollectorRegistry.class).toInstance(CollectorRegistry.defaultRegistry);
  bind(PrometheusMeterRegistry.class)
      .toProvider(PrometheusMeterRegistryProvider.class)
      .asEagerSingleton();
  bind(MeterRegistry.class).to(PrometheusMeterRegistry.class);

  Multibinder<MeterBinder> meterMultibinder =
      Multibinder.newSetBinder(binder(), MeterBinder.class);
  meterMultibinder.addBinding().to(ClassLoaderMetrics.class);
  meterMultibinder.addBinding().to(JvmMemoryMetrics.class);
  meterMultibinder.addBinding().to(JvmGcMetrics.class);
  meterMultibinder.addBinding().to(JvmThreadMetrics.class);
  meterMultibinder.addBinding().to(LogbackMetrics.class);
  meterMultibinder.addBinding().to(FileDescriptorMetrics.class);
  meterMultibinder.addBinding().to(ProcessorMetrics.class);
  meterMultibinder.addBinding().to(UptimeMetrics.class);
  meterMultibinder.addBinding().to(FileStoresMeterBinder.class);
  meterMultibinder.addBinding().to(ApiResponseCounter.class);
  meterMultibinder.addBinding().to(ProcessMemoryMetrics.class);
  meterMultibinder.addBinding().to(ProcessThreadMetrics.class);

  bind(EventListener.class).toProvider(OkHttpMetricsEventListenerProvider.class);
}
 
Example #18
Source File: MetricsServletModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configureServlets() {
  Multibinder<MeterBinder> meterMultibinder =
      Multibinder.newSetBinder(binder(), MeterBinder.class);
  meterMultibinder.addBinding().toProvider(TomcatMetricsProvider.class);

  bind(Manager.class).toInstance(getManager(getServletContext()));
  filter("/*").through(ApiResponseMetricFilter.class);
}
 
Example #19
Source File: RedissonCacheMeterBinderProvider.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public MeterBinder getMeterBinder(RedissonCache cache, Iterable<Tag> tags) {
    return new RedissonCacheMetrics(cache, tags);
}
 
Example #20
Source File: ManualConfiguration.java    From riptide with MIT License 4 votes vote down vote up
@Bean
public MeterBinder executorServiceMetrics(final ExecutorService executor) {
    return new ExecutorServiceMetrics(executor, "http-example", singleton(Tag.of("clientId", "example")));
}
 
Example #21
Source File: MetricsBinder.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public void bindToRegistry(
    PrometheusMeterRegistry meterRegistry, Set<MeterBinder> meterBinderList) {
  meterBinderList.forEach(e -> e.bindTo(meterRegistry));
}
 
Example #22
Source File: HealthCheckedEndpointGroup.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a newly-created {@link MeterBinder} which binds the stats about this
 * {@link HealthCheckedEndpointGroup} with the default meter names.
 */
public MeterBinder newMeterBinder(String groupName) {
    return newMeterBinder(new MeterIdPrefix(Flags.useLegacyMeterNames() ? "armeria.client.endpointGroup"
                                                                        : "armeria.client.endpoint.group",
                                            "name", groupName));
}
 
Example #23
Source File: MetricsConfiguration.java    From hedera-mirror-node with Apache License 2.0 4 votes vote down vote up
@Bean
public MeterBinder processMemoryMetrics() {
    return new ProcessMemoryMetrics();
}
 
Example #24
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MeterBinder> getRequires() {
    return delegate.getRequires();
}
 
Example #25
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MeterBinder> getRequires() {
    return Arrays.stream(objectives)
            .flatMap(o -> o.getRequires().stream())
            .collect(Collectors.toList());
}
 
Example #26
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 4 votes vote down vote up
Builder(String name, @Nullable String failedMessage, Collection<MeterBinder> requires) {
    this.name = name;
    this.failedMessage = failedMessage;
    this.requires = requires;
}
 
Example #27
Source File: ServiceLevelObjective.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<MeterBinder> getRequires() {
    return requires;
}
 
Example #28
Source File: PipelineRouteDefiner.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
private void addMetric(MeterBinder meterBinder,MeterRegistry registry) {
    MetricsBinderRendererAdapter metricsBinderRendererAdapter = new MetricsBinderRendererAdapter(meterBinder);
    metricsBinderRendererAdapter.bindTo(registry);
    metricsRenderers.add(metricsBinderRendererAdapter);
}
 
Example #29
Source File: MultiLabelMetricsConfig.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
@SneakyThrows
@Override
public Class<? extends MeterBinder> metricsBinderImplementation() {
    return (Class<? extends MeterBinder>) Class.forName("ai.konduit.serving.metrics.MultiLabelMetrics");
}
 
Example #30
Source File: RegressionMetricsConfig.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
@Override
@SneakyThrows
public Class<? extends MeterBinder> metricsBinderImplementation() {
    return (Class<? extends MeterBinder>) Class.forName("ai.konduit.serving.metrics.RegressionMetrics");
}