Java Code Examples for io.micrometer.core.instrument.Meter#Id

The following examples show how to use io.micrometer.core.instrument.Meter#Id . 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: AbstractRateLimiterMetrics.java    From resilience4j with Apache License 2.0 6 votes vote down vote up
private void registerMetrics(
    MeterRegistry meterRegistry, RateLimiter rateLimiter, List<Tag> customTags) {
    // Remove previous meters before register
    removeMetrics(meterRegistry, rateLimiter.getName());

    Set<Meter.Id> idSet = new HashSet<>();
    idSet.add(Gauge.builder(names.getAvailablePermissionsMetricName(), rateLimiter,
        rl -> rl.getMetrics().getAvailablePermissions())
        .description("The number of available permissions")
        .tag(TagNames.NAME, rateLimiter.getName())
        .tags(customTags)
        .register(meterRegistry).getId());
    idSet.add(Gauge.builder(names.getWaitingThreadsMetricName(), rateLimiter,
        rl -> rl.getMetrics().getNumberOfWaitingThreads())
        .description("The number of waiting threads")
        .tag(TagNames.NAME, rateLimiter.getName())
        .tags(customTags)
        .register(meterRegistry).getId());
    meterIdMap.put(rateLimiter.getName(), idSet);
}
 
Example 2
Source File: GraphiteHierarchicalNameMapper.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
public String toHierarchicalName(Meter.Id id, NamingConvention convention) {
    StringBuilder hierarchicalName = new StringBuilder();
    for (String tagKey : tagsAsPrefix) {
        String tagValue = id.getTag(tagKey);
        if (tagValue != null) {
            hierarchicalName.append(convention.tagValue(tagValue)).append(".");
        }
    }
    hierarchicalName.append(id.getConventionName(convention));
    for (Tag tag : id.getTagsAsIterable()) {
        if (!tagsAsPrefix.contains(tag.getKey())) {
            hierarchicalName.append('.').append(convention.tagKey(tag.getKey()))
                    .append('.').append(convention.tagValue(tag.getValue()));
        }
    }
    return hierarchicalName.toString();
}
 
Example 3
Source File: CommonMetricsFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * Filter for "[PREFIX]_*"
 *
 * @param id
 * @return MeterFilterReply
 */
public MeterFilterReply accept(Meter.Id id) {
    if (!k8sMetricsProperties.isEnableCommonMetricsFilter()) {
        return MeterFilter.super.accept(id);
    }

    String metricName = id.getName();

    Boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, null);
    if (enabled != null) {
        return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY;
    }

    if (whitelist.contains(metricName)) {
        return MeterFilterReply.NEUTRAL;
    }
    if (blacklist.contains(metricName)) {
        return MeterFilterReply.DENY;
    }

    for(String prefix: prefixes) {
        if (metricName.startsWith(prefix)) {
            return MeterFilterReply.ACCEPT;
        }
    }

    for(String key: tagRules.keySet()) {
        String expectedValue = tagRules.get(key);
        if (expectedValue != null) {
            if (expectedValue.equals(id.getTag(key))) {
                return MeterFilterReply.ACCEPT;
            }
        }
    }

    return MeterFilterReply.DENY;
}
 
Example 4
Source File: WavefrontMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void publishMetricWhenNanOrInfinityShouldNotAdd() {
    Meter.Id id = registry.counter("name").getId();
    registry.publishMetric(id, null, System.currentTimeMillis(), Double.NaN);
    registry.publishMetric(id, null, System.currentTimeMillis(), Double.POSITIVE_INFINITY);
    verifyNoInteractions(wavefrontSender);
}
 
Example 5
Source File: Metric.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link Metric} instance.
 * @param id Meter id
 * @param snapshot instance of HistogramSnapshot
 */
Metric(Meter.Id id, HistogramSnapshot snapshot) {
	this.timestamp = new Date();
	this.id = id;
	this.sum = snapshot.total(TimeUnit.MILLISECONDS);
	this.count = snapshot.count();
	this.mean = snapshot.mean(TimeUnit.MILLISECONDS);
	this.upper = snapshot.max(TimeUnit.MILLISECONDS);
	this.total = snapshot.total(TimeUnit.MILLISECONDS);
}
 
Example 6
Source File: HealthMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private boolean accept(Meter.Id id) {
    for (MeterFilter filter : serviceLevelObjectiveFilters) {
        MeterFilterReply reply = filter.accept(id);
        if (reply == MeterFilterReply.DENY) {
            return false;
        } else if (reply == MeterFilterReply.ACCEPT) {
            return true;
        }
    }
    return true;
}
 
Example 7
Source File: NewRelicClientProvider.java    From micrometer with Apache License 2.0 5 votes vote down vote up
default String getEventType(Meter.Id id, NewRelicConfig config, NamingConvention namingConvention) {
    if (config.meterNameEventTypeEnabled()) {
        //meter/metric name event type
        return id.getConventionName(namingConvention);
    } else {
        //static eventType "category"
        return config.eventType();
    }
}
 
Example 8
Source File: GraphiteDimensionalNameMapper.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public String toHierarchicalName(Meter.Id id, NamingConvention convention) {
    StringBuilder hierarchicalName = new StringBuilder();
    hierarchicalName.append(id.getConventionName(convention));
    for (Tag tag : id.getTagsAsIterable()) {
        hierarchicalName.append(';').append(convention.tagKey(tag.getKey()))
                .append('=').append(convention.tagValue(tag.getValue()));
    }
    return hierarchicalName.toString();
}
 
Example 9
Source File: OnlyOnceLoggingDenyMeterFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
@Override
public MeterFilterReply accept(Meter.Id id) {
    if (logger.isWarnEnabled()
            && this.alreadyWarned.compareAndSet(false, true)) {
        logger.warn(this.message.get());
    }
    return MeterFilterReply.DENY;
}
 
Example 10
Source File: MyRegistryCustomizer.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
    if (types.contains(id.getType())) {
        return DistributionStatisticConfig.builder().percentiles(getPercentiles()).build().merge(config);
    }
    return config;
}
 
Example 11
Source File: MetricsPluginTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void checkMetric(Map<Meter.Id, Double> metrics, String metric, String tag, String tagValue, Double expectedValue, boolean enabled) {
   OptionalDouble actualValue = metrics.entrySet().stream()
           .filter(entry -> metric.equals(entry.getKey().getName()))
           .filter(entry -> tagValue.equals(entry.getKey().getTag(tag)))
           .mapToDouble(Map.Entry::getValue)
           .findFirst();

   if (enabled) {
      assertTrue(metric + " for " + tag + " " + tagValue + " not present", actualValue.isPresent());
      assertEquals(metric + " not equal", expectedValue, actualValue.getAsDouble(), 0);
   } else {
      assertFalse(metric + " for " + tag + " " + tagValue + " present", actualValue.isPresent());
   }
}
 
Example 12
Source File: CommonMetricsFilter.java    From foremast with Apache License 2.0 4 votes vote down vote up
private <T> T lookup(Map<String, T> values, Meter.Id id, T defaultValue) {
    if (values.isEmpty()) {
        return defaultValue;
    }
    return doLookup(values, id, () -> defaultValue);
}
 
Example 13
Source File: LogbackMetricsTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
protected Counter newCounter(Meter.Id id) {
    return new LoggingCounter(id);
}
 
Example 14
Source File: DefaultMeter.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public DefaultMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) {
    super(id);
    this.type = type;
    this.measurements = measurements;
}
 
Example 15
Source File: MetricsPluginTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void checkMetric(Map<Meter.Id, Double> metrics, String metric, String tag, String tagValue, Double expectedValue) {
   checkMetric(metrics, metric, tag, tagValue, expectedValue, true);
}
 
Example 16
Source File: SkywalkingMeterRegistry.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
protected DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
    final MeterId meterId = convertId(id);
    return new SkywalkingDistributionSummary(id, meterId, config, clock, distributionStatisticConfig, scale, true);
}
 
Example 17
Source File: DropwizardGauge.java    From micrometer with Apache License 2.0 4 votes vote down vote up
DropwizardGauge(Meter.Id id, com.codahale.metrics.Gauge<Double> impl) {
    super(id);
    this.impl = impl;
}
 
Example 18
Source File: NoopMeterRegistry.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> Gauge newGauge(final Meter.Id id, final T obj, final ToDoubleFunction<T> valueFunction) {
    return new NoopGauge(id);
}
 
Example 19
Source File: OpStatsLoggerImpl.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public Meter.Id getId() {
    return this.success.getId();
}
 
Example 20
Source File: SkywalkingMeterRegistry.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, T obj, ToDoubleFunction<T> valueFunction) {
    final MeterId meterId = convertId(id);
    MeterFactory.gauge(meterId, () -> valueFunction.applyAsDouble(obj)).build();
    return new DefaultGauge<>(id, obj, valueFunction);
}