io.micrometer.core.instrument.Measurement Java Examples
The following examples show how to use
io.micrometer.core.instrument.Measurement.
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: MoreMeters.java From armeria with Apache License 2.0 | 6 votes |
private static String measurementName(Meter.Id id, Measurement measurement) { final StringBuilder buf = new StringBuilder(); // Append name. buf.append(id.getName()); // Append statistic. buf.append('#'); buf.append(measurement.getStatistic().getTagValueRepresentation()); // Append tags if there are any. final Iterator<Tag> tagsIterator = id.getTags().iterator(); if (tagsIterator.hasNext()) { buf.append('{'); tagsIterator.forEachRemaining(tag -> buf.append(tag.getKey()).append('=') .append(tag.getValue()).append(',')); buf.setCharAt(buf.length() - 1, '}'); } return buf.toString(); }
Example #2
Source File: KairosMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeCustomMetricWhenCustomMeterHasMixedFiniteAndNonFiniteValuesShouldSkipOnlyNonFiniteValues() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); Measurement measurement4 = new Measurement(() -> 1d, Statistic.VALUE); Measurement measurement5 = new Measurement(() -> 2d, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3, measurement4, measurement5); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(meterRegistry.writeCustomMetric(meter)).hasSize(2); }
Example #3
Source File: MicrometerAtlasIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenCompositeRegistries_whenRecordMeter_thenAllRegistriesRecorded() { CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry(); SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry(); AtlasMeterRegistry atlasMeterRegistry = new AtlasMeterRegistry(atlasConfig, Clock.SYSTEM); compositeRegistry.add(oneSimpleMeter); compositeRegistry.add(atlasMeterRegistry); compositeRegistry.gauge("baeldung.heat", 90); Optional<Gauge> oneGauge = oneSimpleMeter .find("baeldung.heat") .gauge(); assertTrue(oneGauge.isPresent()); Iterator<Measurement> measurements = oneGauge .get() .measure() .iterator(); assertTrue(measurements.hasNext()); assertThat(measurements .next() .getValue(), equalTo(90.00)); Optional<Gauge> atlasGauge = atlasMeterRegistry .find("baeldung.heat") .gauge(); assertTrue(atlasGauge.isPresent()); Iterator<Measurement> anotherMeasurements = atlasGauge .get() .measure() .iterator(); assertTrue(anotherMeasurements.hasNext()); assertThat(anotherMeasurements .next() .getValue(), equalTo(90.00)); }
Example #4
Source File: MetricsPluginTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static Map<Meter.Id, Double> getMetrics(ActiveMQServer server) { Map<Meter.Id, Double> metrics = new HashMap<>(); List<Meter> meters = server.getMetricsManager().getMeterRegistry().getMeters(); assertTrue(meters.size() > 0); for (Meter meter : meters) { Iterable<Measurement> measurements = meter.measure(); for (Measurement measurement : measurements) { metrics.put(meter.getId(), measurement.getValue()); } } return metrics; }
Example #5
Source File: SkywalkingCustomCounterTest.java From skywalking with Apache License 2.0 | 5 votes |
@Test public void testBuild() { // Creating a custom measurement Measurement measurement = new Measurement(() -> 1d, Statistic.COUNT); final List<MeterId.Tag> tags = Arrays.asList(new MeterId.Tag("skywalking", "custom_counter")); final MeterId meterId = new MeterId("test_custom_conter", MeterId.MeterType.COUNTER, tags); final Counter counter = new SkywalkingCustomCounter.Builder(meterId, measurement, SkywalkingConfig.DEFAULT).build(); // Check is counter meter id and value assertCounter(counter, "test_custom_conter", tags, 1d); }
Example #6
Source File: SkywalkingMeterRegistryTest.java From skywalking with Apache License 2.0 | 5 votes |
/** * Check custom measurement */ private void testNewMeter(String meterName, Meter.Type type, Statistic statistic, Consumer<MeterData> meterChecker) { final SkywalkingMeterRegistry registry = new SkywalkingMeterRegistry(); // Create measurement Meter.builder(meterName, type, Arrays.asList(new Measurement(() -> 1d, statistic))) .tag("skywalking", "test") .register(registry); final List<MeterId.Tag> tags = Arrays.asList(new MeterId.Tag("skywalking", "test")); Assert.assertEquals(1, meterMap.size()); meterChecker.accept(new MeterData(meterMap.values().iterator().next(), tags)); // clear all data cleanup(); }
Example #7
Source File: SkywalkingMeterRegistry.java From skywalking with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, ToDoubleFunction<T> countFunction) { final MeterId meterId = convertId(id); FunctionCounter fc = new CumulativeFunctionCounter<>(id, obj, countFunction); new SkywalkingCustomCounter.Builder(meterId, new Measurement(() -> countFunction.applyAsDouble(obj), Statistic.COUNT), config).build(); return fc; }
Example #8
Source File: SkywalkingMeterRegistry.java From skywalking with Apache License 2.0 | 5 votes |
@Override protected Meter newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) { final MeterId meterId = convertId(id); final String baseName = meterId.getName(); measurements.forEach(m -> { String meterName = baseName; boolean isCounter = false; switch (m.getStatistic()) { case TOTAL: case TOTAL_TIME: meterName = baseName + "_sum"; isCounter = true; break; case COUNT: isCounter = true; break; case MAX: meterName = baseName + "_max"; break; case ACTIVE_TASKS: meterName = baseName + "_active_count"; break; case DURATION: meterName = baseName + "_duration_sum"; break; } if (isCounter) { new SkywalkingCustomCounter.Builder(meterId.copyTo(meterName, MeterId.MeterType.COUNTER), m, config).build(); } else { MeterFactory.gauge(meterId.copyTo(meterName, MeterId.MeterType.GAUGE), () -> m.getValue()).build(); } }); return new DefaultMeter(id, type, measurements); }
Example #9
Source File: CumulativeDistributionSummary.java From micrometer with Apache License 2.0 | 5 votes |
@Override public Iterable<Measurement> measure() { return Arrays.asList( new Measurement(() -> (double) count(), Statistic.COUNT), new Measurement(this::totalAmount, Statistic.TOTAL), new Measurement(this::max, Statistic.MAX) ); }
Example #10
Source File: KairosMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeCustomMetricWhenCustomMeterHasOnlyNonFiniteValuesShouldNotBeWritten() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(meterRegistry.writeCustomMetric(meter)).isEmpty(); }
Example #11
Source File: AppOpticsMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeMeterWhenCustomMeterHasMixedFiniteAndNonFiniteValuesShouldSkipOnlyNonFiniteValues() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); Measurement measurement4 = new Measurement(() -> 1d, Statistic.VALUE); Measurement measurement5 = new Measurement(() -> 2d, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3, measurement4, measurement5); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(meterRegistry.writeMeter(meter)).hasValue("{\"name\":\"my.meter\",\"period\":60,\"value\":1.0,\"tags\":{\"statistic\":\"value\"}},{\"name\":\"my.meter\",\"period\":60,\"value\":2.0,\"tags\":{\"statistic\":\"value\"}}"); }
Example #12
Source File: AppOpticsMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeMeterWhenCustomMeterHasOnlyNonFiniteValuesShouldNotBeWritten() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(meterRegistry.writeMeter(meter)).isNotPresent(); }
Example #13
Source File: WavefrontMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void publishMeterWhenCustomMeterHasMixedFiniteAndNonFiniteValuesShouldSkipOnlyNonFiniteValues() throws IOException { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); Measurement measurement4 = new Measurement(() -> 1d, Statistic.VALUE); Measurement measurement5 = new Measurement(() -> 2d, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3, measurement4, measurement5); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.registry); registry.publishMeter(meter); verify(wavefrontSender, times(1)).sendMetric("my.meter", 1d, clock.wallTime(), "host", Collections.singletonMap("statistic", "value")); verify(wavefrontSender, times(1)).sendMetric("my.meter", 2d, clock.wallTime(), "host", Collections.singletonMap("statistic", "value")); verifyNoMoreInteractions(wavefrontSender); }
Example #14
Source File: WavefrontMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void publishMeterWhenCustomMeterHasOnlyNonFiniteValuesShouldNotBeWritten() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.registry); registry.publishMeter(meter); verifyNoInteractions(wavefrontSender); }
Example #15
Source File: HumioMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeMeterWhenCustomMeterHasMixedFiniteAndNonFiniteValuesShouldSkipOnlyNonFiniteValues() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); Measurement measurement4 = new Measurement(() -> 1d, Statistic.VALUE); Measurement measurement5 = new Measurement(() -> 2d, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3, measurement4, measurement5); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(createBatch().writeMeter(meter)) .isEqualTo("{\"timestamp\":\"1970-01-01T00:00:00.001Z\",\"attributes\":{\"name\":\"my_meter\",\"value\":1,\"value\":2}}"); }
Example #16
Source File: HumioMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void writeMeterWhenCustomMeterHasOnlyNonFiniteValuesShouldNotBeWritten() { Measurement measurement1 = new Measurement(() -> Double.POSITIVE_INFINITY, Statistic.VALUE); Measurement measurement2 = new Measurement(() -> Double.NEGATIVE_INFINITY, Statistic.VALUE); Measurement measurement3 = new Measurement(() -> Double.NaN, Statistic.VALUE); List<Measurement> measurements = Arrays.asList(measurement1, measurement2, measurement3); Meter meter = Meter.builder("my.meter", Meter.Type.GAUGE, measurements).register(this.meterRegistry); assertThat(createBatch().writeMeter(meter)).isNull(); }
Example #17
Source File: StepDistributionSummary.java From micrometer with Apache License 2.0 | 5 votes |
@Override public Iterable<Measurement> measure() { return Arrays.asList( new Measurement(() -> (double) count(), Statistic.COUNT), new Measurement(this::totalAmount, Statistic.TOTAL), new Measurement(this::max, Statistic.MAX) ); }
Example #18
Source File: NoopMeterRegistry.java From dolphin-platform with Apache License 2.0 | 4 votes |
@Override protected Meter newMeter(final Meter.Id id, final Meter.Type type, final Iterable<Measurement> measurements) { return new NoopCounter(id); }
Example #19
Source File: NoopMeterRegistry.java From armeria with Apache License 2.0 | 4 votes |
@Override protected Meter newMeter(Id id, Type type, Iterable<Measurement> measurements) { return new NoopMeter(id); }
Example #20
Source File: SkywalkingCustomCounter.java From skywalking with Apache License 2.0 | 4 votes |
protected SkywalkingCustomCounter(MeterId meterId, Measurement measurement, SkywalkingConfig config) { super(meterId, MeterBuilder.getCounterMode(meterId, config)); this.measurement = measurement; }
Example #21
Source File: SkywalkingCustomCounter.java From skywalking with Apache License 2.0 | 4 votes |
public Builder(MeterId meterId, Measurement measurement, SkywalkingConfig config) { super(meterId); this.measurement = measurement; this.config = config; }
Example #22
Source File: NoopMeter.java From micrometer with Apache License 2.0 | 4 votes |
@Override public List<Measurement> measure() { return emptyList(); }
Example #23
Source File: CompositeCustomMeter.java From micrometer with Apache License 2.0 | 4 votes |
CompositeCustomMeter(Id id, Type type, Iterable<Measurement> measurements) { super(id, type, measurements); }
Example #24
Source File: DefaultMeter.java From micrometer with Apache License 2.0 | 4 votes |
@Override public Iterable<Measurement> measure() { return measurements; }
Example #25
Source File: DefaultDestinationPublishingMeterRegistry.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@Override protected Meter newMeter(Id id, Type type, Iterable<Measurement> measurements) { return new DefaultMeter(id, type, measurements); }
Example #26
Source File: DefaultMeter.java From micrometer with Apache License 2.0 | 4 votes |
public DefaultMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) { super(id); this.type = type; this.measurements = measurements; }