io.micrometer.core.instrument.TimeGauge Java Examples

The following examples show how to use io.micrometer.core.instrument.TimeGauge. 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: CaffeineCacheMetricsTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void reportExpectedGeneralMetrics() {
    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    verifyCommonCacheMetrics(registry, metrics);

    FunctionCounter evictionWeight = fetch(registry, "cache.eviction.weight").functionCounter();
    CacheStats stats = cache.stats();
    assertThat(evictionWeight.count()).isEqualTo(stats.evictionWeight());

    // specific to LoadingCache instance
    TimeGauge loadDuration = fetch(registry, "cache.load.duration").timeGauge();
    assertThat(loadDuration.value()).isEqualTo(stats.totalLoadTime());

    FunctionCounter successfulLoad = fetch(registry, "cache.load", Tags.of("result", "success")).functionCounter();
    assertThat(successfulLoad.count()).isEqualTo(stats.loadSuccessCount());

    FunctionCounter failedLoad = fetch(registry, "cache.load", Tags.of("result", "failure")).functionCounter();
    assertThat(failedLoad.count()).isEqualTo(stats.loadFailureCount());
}
 
Example #2
Source File: KafkaMetricMeterTypeBuilder.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Build and register a typed meter.
 *
 * @return Optional type of {@link Meter}
 */
public Optional<Meter> build() {
    if (!isValid()) {
        return Optional.empty();
    }

    if (StringUtils.isEmpty(name)) {
        name = kafkaMetric.metricName().name();
    }

    KafkaMetricMeterType kafkaMetricMeterType = kafkaMetricMeterTypeRegistry.lookup(this.name);

    if (kafkaMetricMeterType.getMeterType() == MeterType.GAUGE && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(Gauge.builder(getMetricName(), () -> (Double) kafkaMetric.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .baseUnit(kafkaMetricMeterType.getBaseUnit())
                .register(meterRegistry));
    } else if (kafkaMetricMeterType.getMeterType() == MeterType.FUNCTION_COUNTER && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(FunctionCounter.builder(getMetricName(), kafkaMetric, value -> (Double) value.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .baseUnit(kafkaMetricMeterType.getBaseUnit())
                .register(meterRegistry));
    } else if (kafkaMetricMeterType.getMeterType() == MeterType.TIME_GAUGE && this.kafkaMetric.metricValue() instanceof Double) {
        return Optional.of(TimeGauge.builder(getMetricName(), kafkaMetric, kafkaMetricMeterType.getTimeUnit(), value -> (Double) value.metricValue())
                .tags(tagFunction.apply(kafkaMetric.metricName()))
                .description(kafkaMetricMeterType.getDescription())
                .register(meterRegistry));
    }

    return Optional.empty();
}
 
Example #3
Source File: KafkaProducerMetricsBinder.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private void registerTimeGaugeForObject(MeterRegistry registry, ObjectName o, String jmxMetricName,
    String meterName, Tags allTags, String description) {
    TimeGauge
        .builder(METRIC_NAME_PREFIX + meterName, getMBeanServer(), TimeUnit.MILLISECONDS,
            s -> safeDouble(() -> s.getAttribute(o, jmxMetricName)))
        .description(description).tags(allTags).register(registry);
}
 
Example #4
Source File: KafkaConsumerMetrics.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private void registerTimeGaugeForObject(MeterRegistry registry, ObjectName o, String jmxMetricName,
    String meterName, Tags allTags, String description) {
    TimeGauge
        .builder(METRIC_NAME_PREFIX + meterName, mBeanServer, TimeUnit.MILLISECONDS,
            s -> safeDouble(() -> s.getAttribute(o, jmxMetricName)))
        .description(description).tags(allTags).register(registry);
}
 
Example #5
Source File: UptimeMetrics.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public void bindTo(MeterRegistry registry) {
    TimeGauge.builder("process.uptime", runtimeMXBean, TimeUnit.MILLISECONDS, RuntimeMXBean::getUptime)
        .tags(tags)
        .description("The uptime of the Java virtual machine")
        .register(registry);

    TimeGauge.builder("process.start.time", runtimeMXBean, TimeUnit.MILLISECONDS, RuntimeMXBean::getStartTime)
        .tags(tags)
        .description("Start time of the process since unix epoch.")
        .register(registry);
}
 
Example #6
Source File: CompositeTimeGauge.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
TimeGauge registerNewMeter(MeterRegistry registry) {
    final T obj = ref.get();
    if (obj == null) {
        return null;
    }

    return TimeGauge.builder(getId().getName(), obj, fUnit, f)
        .tags(getId().getTagsAsIterable())
        .description(getId().getDescription())
        .register(registry);
}
 
Example #7
Source File: GuavaCacheMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void reportExpectedMetrics() {
    MeterRegistry registry = new SimpleMeterRegistry();
    metrics.bindTo(registry);

    verifyCommonCacheMetrics(registry, metrics);

    // common metrics
    Gauge cacheSize = fetch(registry, "cache.size").gauge();
    assertThat(cacheSize.value()).isEqualTo(cache.size());

    FunctionCounter hitCount = fetch(registry, "cache.gets", Tags.of("result", "hit")).functionCounter();
    assertThat(hitCount.count()).isEqualTo(metrics.hitCount());

    FunctionCounter missCount = fetch(registry, "cache.gets", Tags.of("result", "miss")).functionCounter();
    assertThat(missCount.count()).isEqualTo(metrics.missCount().doubleValue());

    FunctionCounter cachePuts = fetch(registry, "cache.puts").functionCounter();
    assertThat(cachePuts.count()).isEqualTo(metrics.putCount());

    FunctionCounter cacheEviction = fetch(registry, "cache.evictions").functionCounter();
    assertThat(cacheEviction.count()).isEqualTo(metrics.evictionCount().doubleValue());

    CacheStats stats = cache.stats();
    TimeGauge loadDuration = fetch(registry, "cache.load.duration").timeGauge();
    assertThat(loadDuration.value()).isEqualTo(stats.totalLoadTime());

    FunctionCounter successfulLoad = fetch(registry, "cache.load", Tags.of("result", "success")).functionCounter();
    assertThat(successfulLoad.count()).isEqualTo(stats.loadSuccessCount());

    FunctionCounter failedLoad = fetch(registry, "cache.load", Tags.of("result", "failure")).functionCounter();
    assertThat(failedLoad.count()).isEqualTo(stats.loadExceptionCount());
}
 
Example #8
Source File: MeterPool.java    From data-highway with Apache License 2.0 4 votes vote down vote up
public MeterPool(MeterRegistry registry) {
  counterPool = new KeyedSharedObjectPool<NameAndTags, Counter>() {
    @Override
    protected Counter constructValue(NameAndTags key) {
      return registry.counter(key.getName(), key.getTags());
    }

    @Override
    protected void destroyValue(NameAndTags key, Counter value) {
      registry.remove(value);
    }
  };

  timeGaugePool = new KeyedSharedObjectPool<NameAndTags, SettableTimeGauge>() {
    @Override
    protected SettableTimeGauge constructValue(NameAndTags key) {
      AtomicLong value = new AtomicLong();
      TimeGauge timeGauge = registry
          .more()
          .timeGauge(key.getName(), key.getTags(), value, MILLISECONDS, AtomicLong::doubleValue);
      return new SettableTimeGauge(timeGauge, value);
    }

    @Override
    protected void destroyValue(NameAndTags key, SettableTimeGauge value) {
      registry.remove(value);
    }
  };

  timerPool = new KeyedSharedObjectPool<NameAndTags, Timer>() {
    @Override
    protected Timer constructValue(NameAndTags key) {
      return registry.timer(key.getName(), key.getTags());
    }

    @Override
    protected void destroyValue(NameAndTags key, Timer value) {
      registry.remove(value);
    }
  };

  gaugePool = new KeyedSharedObjectPool<MeterPool.NameAndTags, SettableGauge>() {
    @Override
    protected SettableGauge constructValue(NameAndTags key) {
      AtomicLong value = new AtomicLong();
      Gauge gauge = Gauge.builder(key.getName(), value, AtomicLong::doubleValue).tags(key.getTags()).register(registry);
      return new SettableGauge(gauge, value);
    }

    @Override
    protected void destroyValue(NameAndTags key, SettableGauge value) {
      registry.remove(value);
    }
  };
}
 
Example #9
Source File: CompositeTimeGauge.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
TimeGauge newNoopMeter() {
    return new NoopTimeGauge(getId());
}
 
Example #10
Source File: NewRelicClientProvider.java    From micrometer with Apache License 2.0 votes vote down vote up
Object writeTimeGauge(TimeGauge gauge);