Java Code Examples for org.eclipse.microprofile.metrics.Meter#mark()
The following examples show how to use
org.eclipse.microprofile.metrics.Meter#mark() .
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: ExportersMetricScalingTest.java From smallrye-metrics with Apache License 2.0 | 6 votes |
/** * Given a Meter, * check that the statistics from OpenMetrics will be presented as per_second. */ @Test public void meter_openMetrics() throws InterruptedException { MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata.builder() .withName("meter1") .withType(MetricType.METERED) .build(); Meter metric = registry.meter(metadata); metric.mark(10); TimeUnit.SECONDS.sleep(1); OpenMetricsExporter exporter = new OpenMetricsExporter(); String exported = exporter.exportOneMetric(MetricRegistry.Type.APPLICATION, new MetricID("meter1")).toString(); Assert.assertThat(exported, containsString("application_meter1_total 10.0")); double ratePerSecond = Double.parseDouble(Arrays.stream(exported.split("\\n")) .filter(line -> line.contains("application_meter1_rate_per_second")) .filter(line -> !line.contains("TYPE") && !line.contains("HELP")) .findFirst() .get() .split(" ")[1]); Assert.assertTrue("Rate per second should be between 1 and 10 but is " + ratePerSecond, ratePerSecond > 1 && ratePerSecond < 10); }
Example 2
Source File: ExportersMetricScalingTest.java From smallrye-metrics with Apache License 2.0 | 6 votes |
/** * Given a Meter, * check that the statistics from JsonExporter will be presented as per_second. */ @Test public void meter_json() throws InterruptedException { MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata.builder() .withName("meter1") .withType(MetricType.METERED) .build(); Meter metric = registry.meter(metadata); metric.mark(10); TimeUnit.SECONDS.sleep(1); JsonExporter exporter = new JsonExporter(); String exported = exporter.exportOneMetric(MetricRegistry.Type.APPLICATION, new MetricID("meter1")).toString(); JsonObject json = Json.createReader(new StringReader(exported)).read().asJsonObject().getJsonObject("meter1"); assertEquals(10, json.getInt("count")); double meanRate = json.getJsonNumber("meanRate").doubleValue(); Assert.assertTrue("meanRate should be between 1 and 10 but is " + meanRate, meanRate > 1 && meanRate < 10); }
Example 3
Source File: JsonExporterTest.java From smallrye-metrics with Apache License 2.0 | 5 votes |
@Test public void testMeters() { JsonExporter exporter = new JsonExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Meter meterWithoutTags = registry.meter("mymeter"); Meter meterRed = registry.meter("mymeter", new Tag("color", "red")); Meter meterBlue = registry.meter("mymeter", new Tag("color", "blue"), new Tag("foo", "bar")); meterWithoutTags.mark(1); meterRed.mark(2); meterBlue.mark(3); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mymeter").toString(); JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject(); JsonObject myMeterObject = json.getJsonObject("mymeter"); assertEquals(1, myMeterObject.getInt("count")); assertEquals(2, myMeterObject.getInt("count;color=red")); assertEquals(3, myMeterObject.getInt("count;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("meanRate")); assertNotNull(myMeterObject.getJsonNumber("meanRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("meanRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate;color=blue;foo=bar")); }
Example 4
Source File: MeterTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test public void testRates() throws Exception { int count = 100; int markSeconds = 30; int delaySeconds = 15; Meter meter = registry.meter("testMeterRatesLong"); for (int i = 0; i < markSeconds; i++) { meter.mark(count); Thread.sleep(1000); } // All rates should be around the value of count TestUtils.assertEqualsWithTolerance(count, meter.getMeanRate()); TestUtils.assertEqualsWithTolerance(count, meter.getOneMinuteRate()); TestUtils.assertEqualsWithTolerance(count, meter.getFiveMinuteRate()); TestUtils.assertEqualsWithTolerance(count, meter.getFifteenMinuteRate()); Thread.sleep(delaySeconds * 1000); // Approximately calculate what the expected mean should be // and let the tolerance account for the delta double expectedMean = count * ((double) markSeconds/(markSeconds + delaySeconds)); TestUtils.assertEqualsWithTolerance(expectedMean, meter.getMeanRate()); // After a delay, we expect some decay of values Assert.assertThat(meter.getOneMinuteRate(), lessThan((double)count)); Assert.assertThat(meter.getFiveMinuteRate(), lessThan((double)count)); Assert.assertThat(meter.getFifteenMinuteRate(), lessThan((double)count)); }
Example 5
Source File: OpenMetricsExporterTest.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Test public void exportMeters() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata .builder() .withType(MetricType.METERED) .withName("mymeter") .withDescription("awesome") .build(); Tag blueTag = new Tag("color", "blue"); Meter blueMeter = registry.meter(metadata, blueTag); Tag greenTag = new Tag("color", "green"); Meter greenMeter = registry.meter(metadata, greenTag); blueMeter.mark(20); greenMeter.mark(10); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mymeter").toString(); System.out.println(result); assertHasTypeLineExactlyOnce(result, "application_mymeter_total", "counter"); assertHasHelpLineExactlyOnce(result, "application_mymeter_total", "awesome"); assertHasValueLineExactlyOnce(result, "application_mymeter_total", "20.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mymeter_total", "10.0", greenTag); assertHasTypeLineExactlyOnce(result, "application_mymeter_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mymeter_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mymeter_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mymeter_one_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mymeter_one_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mymeter_one_min_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mymeter_five_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mymeter_five_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mymeter_five_min_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mymeter_fifteen_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mymeter_fifteen_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mymeter_fifteen_min_rate_per_second", "*", greenTag); }
Example 6
Source File: MetricAppBean.java From microprofile-metrics with Apache License 2.0 | 2 votes |
public void meterMe() { Meter meter = metrics.meter("metricTest.test1.meter"); meter.mark(); }