use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.
the class MetricSchemaCompatibilityTest method backwardCompatibleMetricTypes.
/**
* Assuring that when the configuration flag useSemanticMetricTypes is NOT set,
* created metric types match the old behavior.
*/
@Test
void backwardCompatibleMetricTypes() {
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DOUBLE)), registry.createGauge(batch, Gauge.builder("gauge", () -> 1).register(registry)));
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DOUBLE)), registry.createCounter(batch, Counter.builder("counter").register(registry)));
assertSchemaCompatibility(Arrays.asList(new Pair(GAUGE, DISTRIBUTION), new Pair(GAUGE, DOUBLE), new Pair(GAUGE, INT64)), registry.createTimer(batch, Timer.builder("timer").register(registry)));
assertSchemaCompatibility(Arrays.asList(new Pair(GAUGE, DISTRIBUTION), new Pair(GAUGE, DOUBLE), new Pair(GAUGE, INT64)), registry.createSummary(batch, DistributionSummary.builder("summary").register(registry)));
assertSchemaCompatibility(Arrays.asList(new Pair(GAUGE, INT64), new Pair(GAUGE, DOUBLE)), registry.createLongTaskTimer(batch, LongTaskTimer.builder("longTaskTimer").register(registry)));
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DOUBLE)), registry.createTimeGauge(batch, TimeGauge.builder("timeGauge", () -> 1, TimeUnit.SECONDS).register(registry)));
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DOUBLE)), registry.createFunctionCounter(batch, FunctionCounter.builder("functionCounter", 1, value -> 1).register(registry)));
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DISTRIBUTION)), registry.createFunctionTimer(batch, FunctionTimer.builder("functionTimer", 1, value -> 1, value -> 1, TimeUnit.SECONDS).register(registry)));
assertSchemaCompatibility(Collections.singletonList(new Pair(GAUGE, DOUBLE)), registry.createMeter(batch, Meter.builder("gauge", Meter.Type.OTHER, Collections.singletonList(new Measurement(() -> 1.0, Statistic.UNKNOWN))).register(registry)));
}
use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.
the class KairosMeterRegistryTest method writeGaugeShouldDropInfiniteValues.
@Test
void writeGaugeShouldDropInfiniteValues() {
meterRegistry.gauge("my.gauge", Double.POSITIVE_INFINITY);
Gauge gauge = meterRegistry.find("my.gauge").gauge();
assertThat(meterRegistry.writeGauge(gauge)).isEmpty();
meterRegistry.gauge("my.gauge", Double.NEGATIVE_INFINITY);
gauge = meterRegistry.find("my.gauge").gauge();
assertThat(meterRegistry.writeGauge(gauge)).isEmpty();
}
use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.
the class JCacheMetricsTest method reportExpectedMetrics.
@Test
void reportExpectedMetrics() {
MeterRegistry meterRegistry = new SimpleMeterRegistry();
metrics.bindTo(meterRegistry);
verifyCommonCacheMetrics(meterRegistry, metrics);
Gauge cacheRemovals = fetch(meterRegistry, "cache.removals").gauge();
assertThat(cacheRemovals.value()).isEqualTo(expectedAttributeValue.doubleValue());
}
use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.
the class JvmInfoMetricsTest method assertJvmInfo.
@Test
void assertJvmInfo() {
MeterRegistry registry = new SimpleMeterRegistry();
new JvmInfoMetrics().bindTo(registry);
Collection<Gauge> gauges = Search.in(registry).name("jvm.info").gauges();
assertThat(gauges.size()).isEqualTo(1);
Gauge jvmInfo = gauges.iterator().next();
assertThat(jvmInfo.value()).isEqualTo(1L);
Meter.Id id = jvmInfo.getId();
assertThat(id.getTag("version")).isNotNull();
assertThat(id.getTag("vendor")).isNotNull();
assertThat(id.getTag("runtime")).isNotNull();
}
use of io.micrometer.core.instrument.Gauge in project micrometer by micrometer-metrics.
the class EhCache2MetricsTest method reportMetrics.
@Test
void reportMetrics() {
MeterRegistry registry = new SimpleMeterRegistry();
metrics.bindTo(registry);
verifyCommonCacheMetrics(registry, metrics);
StatisticsGateway stats = cache.getStatistics();
Gauge remoteSize = fetch(registry, "cache.remoteSize").gauge();
assertThat(remoteSize.value()).isEqualTo(stats.getRemoteSize());
FunctionCounter cacheRemovals = fetch(registry, "cache.removals").functionCounter();
assertThat(cacheRemovals.count()).isEqualTo(stats.cacheRemoveCount());
String cacheAdded = "cache.puts.added";
FunctionCounter putsAdded = fetch(registry, cacheAdded, Tags.of("result", "added")).functionCounter();
assertThat(putsAdded.count()).isEqualTo(stats.cachePutAddedCount());
FunctionCounter putsUpdated = fetch(registry, cacheAdded, Tags.of("result", "updated")).functionCounter();
assertThat(putsUpdated.count()).isEqualTo(stats.cachePutUpdatedCount());
Gauge offHeapSize = fetch(registry, "cache.local.offheap.size").gauge();
assertThat(offHeapSize.value()).isEqualTo(stats.getLocalOffHeapSizeInBytes());
Gauge heapSize = fetch(registry, "cache.local.heap.size").gauge();
assertThat(heapSize.value()).isEqualTo(stats.getLocalHeapSizeInBytes());
Gauge diskSize = fetch(registry, "cache.local.disk.size").gauge();
assertThat(diskSize.value()).isEqualTo(stats.getLocalDiskSizeInBytes());
// miss metrics
String misses = "cache.misses";
FunctionCounter expiredMisses = fetch(registry, misses, Tags.of("reason", "expired")).functionCounter();
assertThat(expiredMisses.count()).isEqualTo(stats.cacheMissExpiredCount());
FunctionCounter notFoundMisses = fetch(registry, misses, Tags.of("reason", "notFound")).functionCounter();
assertThat(notFoundMisses.count()).isEqualTo(stats.cacheMissNotFoundCount());
// commit transaction metrics
String xaCommits = "cache.xa.commits";
FunctionCounter readOnlyCommits = fetch(registry, xaCommits, Tags.of("result", "readOnly")).functionCounter();
assertThat(readOnlyCommits.count()).isEqualTo(stats.xaCommitReadOnlyCount());
FunctionCounter exceptionCommits = fetch(registry, xaCommits, Tags.of("result", "exception")).functionCounter();
assertThat(exceptionCommits.count()).isEqualTo(stats.xaCommitExceptionCount());
FunctionCounter committedCommits = fetch(registry, xaCommits, Tags.of("result", "committed")).functionCounter();
assertThat(committedCommits.count()).isEqualTo(stats.xaCommitCommittedCount());
// rollback transaction metrics
String xaRollbacks = "cache.xa.rollbacks";
FunctionCounter exceptionRollback = fetch(registry, xaRollbacks, Tags.of("result", "exception")).functionCounter();
assertThat(exceptionRollback.count()).isEqualTo(stats.xaRollbackExceptionCount());
FunctionCounter successRollback = fetch(registry, xaRollbacks, Tags.of("result", "success")).functionCounter();
assertThat(successRollback.count()).isEqualTo(stats.xaRollbackSuccessCount());
// recovery transaction metrics
String xaRecoveries = "cache.xa.recoveries";
FunctionCounter nothingRecovered = fetch(registry, xaRecoveries, Tags.of("result", "nothing")).functionCounter();
assertThat(nothingRecovered.count()).isEqualTo(stats.xaRecoveryNothingCount());
FunctionCounter successRecoveries = fetch(registry, xaRecoveries, Tags.of("result", "success")).functionCounter();
assertThat(successRecoveries.count()).isEqualTo(stats.xaRecoveryRecoveredCount());
}
Aggregations