org.eclipse.microprofile.metrics.ConcurrentGauge Java Examples
The following examples show how to use
org.eclipse.microprofile.metrics.ConcurrentGauge.
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: TagsTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @InSequence(8) public void concurrentGuageTagsTest() { Tag tagEarth = new Tag("planet", "earth"); Tag tagRed = new Tag("colour", "red"); Tag tagBlue = new Tag("colour", "blue"); String concurrentGaugeName = "org.eclipse.microprofile.metrics.tck.TagTest.concurrentGaugeColour"; ConcurrentGauge concurrentGaugeColour = registry.concurrentGauge(concurrentGaugeName); ConcurrentGauge concurrentGaugeRed = registry.concurrentGauge(concurrentGaugeName,tagEarth,tagRed); ConcurrentGauge concurrentGaugeBlue = registry.concurrentGauge(concurrentGaugeName,tagEarth,tagBlue); MetricID concurrentGaugeColourMID = new MetricID(concurrentGaugeName); MetricID concurrentGaugeRedMID = new MetricID(concurrentGaugeName, tagEarth,tagRed); MetricID concurrentGaugeBlueMID = new MetricID(concurrentGaugeName, tagEarth,tagBlue); //check multi-dimensional metrics are registered assertThat("ConcurrentGauge is not registered correctly", registry.getConcurrentGauge(concurrentGaugeColourMID), notNullValue()); assertThat("ConcurrentGauge is not registered correctly", registry.getConcurrentGauge(concurrentGaugeRedMID), notNullValue()); assertThat("ConcurrentGauge is not registered correctly", registry.getConcurrentGauge(concurrentGaugeBlueMID), notNullValue()); }
Example #2
Source File: MetricRegistryTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @InSequence(2) public void registerTest() { metrics.register("regCountTemp", countTemp); assertExists(Counter.class, new MetricID("regCountTemp")); metrics.register("regHistoTemp", histoTemp); assertExists(Histogram.class, new MetricID("regHistoTemp")); metrics.register("regTimerTemp", timerTemp); assertExists(Timer.class, new MetricID("regTimerTemp")); metrics.register("regSimpleTimerTemp", simpleTimerTemp); assertExists(SimpleTimer.class, new MetricID("regSimpleTimerTemp")); metrics.register("regConcurrentGaugeTemp", concurrentGaugeTemp); assertExists(ConcurrentGauge.class, new MetricID("regConcurrentGaugeTemp")); metrics.register("regMeterTemp", meterTemp); assertExists(Meter.class, new MetricID("regMeterTemp")); }
Example #3
Source File: ConcurrentGaugedClassBeanTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @InSequence(1) public void countedMethodsNotCalledYet() { final SortedMap<MetricID, ConcurrentGauge> concurrentGauges = registry.getConcurrentGauges(); assertThat("Concurrent Gauges are not registered correctly", concurrentGauges.keySet(), is(equalTo(counterMIDs))); MetricID constructorMetricID = new MetricID(MetricsUtil.absoluteMetricName( ConcurrentGaugedClassBean.class, "cGaugedClass", CONSTRUCTOR_NAME)); for (Map.Entry<MetricID, ConcurrentGauge> entry : concurrentGauges.entrySet()) { // make sure the max values are zero, with the exception of the constructor, where it could potentially be 1 if(!entry.getKey().equals(constructorMetricID)) { assertEquals("Max value of metric " + entry.getKey().toString() + " should be 0", 0, entry.getValue().getMax()); } // make sure the min values are zero assertEquals("Min value of metric " + entry.getKey().toString() + " should be 0", 0, entry.getValue().getMin()); // make sure the current counts are zero assertEquals("Current count of metric " + entry.getKey().toString() + " should be 0", 0, entry.getValue().getCount()); } }
Example #4
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 6 votes |
private MetricType metricTypeFromClass(Class<?> in) { if (in.equals(Counter.class)) { return MetricType.COUNTER; } else if (in.equals(Gauge.class)) { return MetricType.GAUGE; } else if (in.equals(ConcurrentGauge.class)) { return MetricType.CONCURRENT_GAUGE; } else if (in.equals(Meter.class)) { return MetricType.METERED; } else if (in.equals(Timer.class)) { return MetricType.TIMER; } else if (in.equals(SimpleTimer.class)) { return MetricType.SIMPLE_TIMER; } else if (in.equals(Histogram.class)) { return MetricType.HISTOGRAM; } return null; }
Example #5
Source File: ConcurrentGaugeFunctionalTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
/** * To test the 'min' and 'max' values we have to do this: * - run invocation1 and keep it running * - wait until the next minute starts * - run invocation2 and stop it right away * - wait until the next minute starts * - stop invocation1 * - after this, 'min' should be 1 and 'max' should be 2 */ @Test @InSequence(1) public void testMinMax() throws TimeoutException, InterruptedException { ControlledInvocation invocation1 = new ControlledInvocation(bean); ControlledInvocation invocation2 = new ControlledInvocation(bean); invocation1.start(); try { TimeUtil.waitForNextMinute(); invocation2 = new ControlledInvocation(bean); invocation2.start(); invocation2.stop(); TimeUtil.waitForNextMinute(); invocation1.stop(); ConcurrentGauge cGauge = metricRegistry.getConcurrentGauge(new MetricID("mygauge")); assertEquals("Minimum should be 1 ", 1, cGauge.getMin()); assertEquals("Maximum should be 2", 2, cGauge.getMax()); } finally { invocation1.stop(); invocation2.stop(); } }
Example #6
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 6 votes |
private boolean isSameType(Metric metricInstance, MetricType type) { switch (type) { case CONCURRENT_GAUGE: return metricInstance instanceof ConcurrentGauge; case GAUGE: return metricInstance instanceof Gauge; case HISTOGRAM: return metricInstance instanceof Histogram; case TIMER: return metricInstance instanceof Timer; case METERED: return metricInstance instanceof Meter; case COUNTER: return metricInstance instanceof Counter; case SIMPLE_TIMER: return metricInstance instanceof SimpleTimer; default: throw new IllegalArgumentException(); } }
Example #7
Source File: OpenMetricsExporter.java From smallrye-metrics with Apache License 2.0 | 5 votes |
private void writeConcurrentGaugeValues(StringBuilder sb, MetricRegistry.Type scope, ConcurrentGauge concurrentGauge, Metadata md, String key, Map<String, String> tags) { key = getOpenMetricsMetricName(key); writeHelpLine(sb, scope, key, md, "_current"); writeTypeAndValue(sb, scope, "_current", concurrentGauge.getCount(), GAUGE, md, false, tags); writeTypeAndValue(sb, scope, "_max", concurrentGauge.getMax(), GAUGE, md, false, tags); writeTypeAndValue(sb, scope, "_min", concurrentGauge.getMin(), GAUGE, md, false, tags); }
Example #8
Source File: JsonExporter.java From smallrye-metrics with Apache License 2.0 | 5 votes |
private Map<String, JsonValue> exportConcurrentGauge(ConcurrentGauge concurrentGauge, String tags) { Map<String, JsonValue> map = new HashMap<>(); map.put("current" + tags, JsonProviderHolder.get().createValue(concurrentGauge.getCount())); map.put("max" + tags, JsonProviderHolder.get().createValue(concurrentGauge.getMax())); map.put("min" + tags, JsonProviderHolder.get().createValue(concurrentGauge.getMin())); return map; }
Example #9
Source File: OpenMetricsExporterTest.java From smallrye-metrics with Apache License 2.0 | 5 votes |
@Test public void exportConcurrentGauges() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata .builder() .withType(MetricType.CONCURRENT_GAUGE) .withName("myconcurrentgauge") .withDescription("awesome") .withUnit("dollars") // this should get ignored and should not be reflected in the output .build(); Tag blueTag = new Tag("color", "blue"); ConcurrentGauge blueCGauge = registry.concurrentGauge(metadata, blueTag); Tag greenTag = new Tag("color", "green"); ConcurrentGauge greenCGauge = registry.concurrentGauge(metadata, greenTag); blueCGauge.inc(); blueCGauge.inc(); greenCGauge.inc(); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "myconcurrentgauge").toString(); System.out.println(result); assertHasTypeLineExactlyOnce(result, "application_myconcurrentgauge_current", "gauge"); assertHasTypeLineExactlyOnce(result, "application_myconcurrentgauge_min", "gauge"); assertHasTypeLineExactlyOnce(result, "application_myconcurrentgauge_max", "gauge"); assertHasHelpLineExactlyOnce(result, "application_myconcurrentgauge_current", "awesome"); assertHasValueLineExactlyOnce(result, "application_myconcurrentgauge_current", "2.0", blueTag); assertHasValueLineExactlyOnce(result, "application_myconcurrentgauge_current", "1.0", greenTag); }
Example #10
Source File: JsonExporterTest.java From smallrye-metrics with Apache License 2.0 | 5 votes |
@Test public void testConcurrentGauges() { JsonExporter exporter = new JsonExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); ConcurrentGauge cGaugeWithoutTags = registry.concurrentGauge("mycgauge"); ConcurrentGauge cGaugeRed = registry.concurrentGauge("mycgauge", new Tag("color", "red")); ConcurrentGauge cGaugeBlue = registry.concurrentGauge("mycgauge", new Tag("color", "blue"), new Tag("foo", "bar")); cGaugeWithoutTags.inc(); cGaugeRed.inc(); cGaugeRed.inc(); cGaugeBlue.inc(); cGaugeBlue.inc(); cGaugeBlue.inc(); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mycgauge").toString(); JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject(); JsonObject myCgaugeObject = json.getJsonObject("mycgauge"); assertEquals(1, myCgaugeObject.getInt("current")); assertEquals(2, myCgaugeObject.getInt("current;color=red")); assertEquals(3, myCgaugeObject.getInt("current;color=blue;foo=bar")); assertNotNull(myCgaugeObject.getJsonNumber("min")); assertNotNull(myCgaugeObject.getJsonNumber("min;color=red")); assertNotNull(myCgaugeObject.getJsonNumber("min;color=blue;foo=bar")); assertNotNull(myCgaugeObject.getJsonNumber("max")); assertNotNull(myCgaugeObject.getJsonNumber("max;color=red")); assertNotNull(myCgaugeObject.getJsonNumber("max;color=blue;foo=bar")); }
Example #11
Source File: ConcurrentGaugedMethodBeanTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test @InSequence(1) public void countedMethodNotCalledYet() { ConcurrentGauge cGauge = registry.getConcurrentGauge(cGaugeMID); assertThat("Concurrent Gauges is not registered correctly", cGauge, notNullValue()); // Make sure that the counter hasn't been called yet assertThat("Concurrent Gauges count is incorrect", cGauge.getCount(), is(equalTo(COUNTER_COUNT.get()))); }
Example #12
Source File: ConcurrentGaugedMethodBeanTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test @InSequence(2) public void metricInjectionIntoTest(@Metric(name = C_GAUGE_NAME, absolute = true) ConcurrentGauge instance) { ConcurrentGauge cGauge = registry.getConcurrentGauge(cGaugeMID); assertThat("Concurrent Gauges is not registered correctly", cGauge, notNullValue()); // Make sure that the counter registered and the bean instance are the same assertThat("Concurrent Gauges and bean instance are not equal", instance, is(equalTo(cGauge))); }
Example #13
Source File: ConcurrentGaugedMethodBeanTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test @InSequence(4) public void removeCounterFromRegistry() { ConcurrentGauge cGauge = registry.getConcurrentGauge(cGaugeMID); assertThat("Concurrent Gauge is not registered correctly", cGauge, notNullValue()); // Remove the counter from metrics registry registry.remove(cGaugeMID); try { // Call the counted method and assert an exception is thrown bean.countedMethod(new Callable<Long>() { @Override public Long call() throws Exception { return null; } }); } catch (Exception cause) { assertThat(cause, is(instanceOf(IllegalStateException.class))); // Make sure that the counter hasn't been called assertThat("Concurrent Gauges count is incorrect", cGauge.getCount(), is(equalTo(COUNTER_COUNT.get()))); return; } fail("No exception has been re-thrown!"); }
Example #14
Source File: ConcurrentGaugeFunctionalTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
/** * Over time, run multiple invocations on the bean (so that at one point, all are running at the same time). * Over time, check that the concurrent gauge's value is updated properly. * After that, start stopping the invocations one by one, and again, check that the concurrent gauge is updated. */ @Test @InSequence(2) public void testConcurrentInvocations() throws InterruptedException, TimeoutException { ControlledInvocation[] invocations = new ControlledInvocation[NUMBER_OF_INVOCATIONS]; try { // run some clients for the first method, see the 'count' of the concurrent gauge increment over time ConcurrentGauge cGauge = metricRegistry.getConcurrentGauge(new MetricID("mygauge")); for (int i = 0; i < NUMBER_OF_INVOCATIONS; i++) { invocations[i] = new ControlledInvocation(bean); invocations[i].start(); assertEquals(i + 1, cGauge.getCount()); } // stop all clients and see the 'count' of the concurrent gauge decrement over time for (int i = 0; i < NUMBER_OF_INVOCATIONS; i++) { invocations[i].stop(); assertEquals(NUMBER_OF_INVOCATIONS - i - 1, cGauge.getCount()); } } finally { try { for(ControlledInvocation invocation : invocations) { invocation.stop(); } } catch (Exception e) { e.printStackTrace(); } } }
Example #15
Source File: ConcurrentGaugedClassBeanTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test @InSequence(2) public void callCountedMethodsOnce() { assertThat("Concurrent Gauges are not registered correctly", registry.getConcurrentGauges().keySet(), is(equalTo(counterMIDs))); // Call the counted methods and assert they're back to zero bean.countedMethodOne(); bean.countedMethodTwo(); // Let's call the non-public methods as well bean.countedMethodProtected(); bean.countedMethodPackagedPrivate(); assertThat("Concurrent Gauges counts should return to zero", registry.getConcurrentGauges().values(), everyItem(Matchers.<ConcurrentGauge>hasProperty("count", equalTo(0L)))); }
Example #16
Source File: ConcurrentGaugedConstructorBeanTest.java From microprofile-metrics with Apache License 2.0 | 5 votes |
@Test @InSequence(1) public void countedConstructorCalled() { long count = 1L + Math.round(Math.random() * 10); for (int i = 0; i < count; i++) { instance.get(); } ConcurrentGauge concurrentGauge = registry.getConcurrentGauge(counterMID); assertThat("Concurrent Gauge is not registered correctly", concurrentGauge, notNullValue()); assertThat("Concurrent gauge count is incorrect", concurrentGauge.getCount(), is(equalTo(0L))); }
Example #17
Source File: SmallRyeMetricsRecorder.java From quarkus with Apache License 2.0 | 4 votes |
public void registerMetric(MetricRegistry.Type scope, MetadataHolder metadataHolder, TagHolder[] tagHolders, Object implementor) { Metadata metadata = metadataHolder.toMetadata(); Tag[] tags = Arrays.stream(tagHolders).map(TagHolder::toTag).toArray(Tag[]::new); MetricRegistry registry = MetricRegistries.get(scope); switch (metadata.getTypeRaw()) { case GAUGE: registry.register(metadata, (Gauge) implementor, tags); break; case TIMER: if (implementor == null) { registry.timer(metadata, tags); } else { registry.register(metadata, (Timer) implementor); } break; case COUNTER: if (implementor == null) { registry.counter(metadata, tags); } else { registry.register(metadata, (Counter) implementor, tags); } break; case HISTOGRAM: if (implementor == null) { registry.histogram(metadata, tags); } else { registry.register(metadata, (Histogram) implementor, tags); } break; case CONCURRENT_GAUGE: if (implementor == null) { registry.concurrentGauge(metadata, tags); } else { registry.register(metadata, (ConcurrentGauge) implementor, tags); } break; case METERED: if (implementor == null) { registry.meter(metadata, tags); } else { registry.register(metadata, (Metered) implementor, tags); } break; case INVALID: break; default: break; } }
Example #18
Source File: ConcurrentGaugedMethodBeanTest.java From microprofile-metrics with Apache License 2.0 | 4 votes |
@Test @InSequence(3) public void callCountedMethodOnce() throws InterruptedException, TimeoutException { ConcurrentGauge cGauge = registry.getConcurrentGauge(cGaugeMID); assertThat("Concurrent Gauges is not registered correctly", cGauge, notNullValue()); // Call the counted method, block and assert it's been counted final Exchanger<Long> exchanger = new Exchanger<>(); Thread thread = new Thread(new Runnable() { @Override public void run() { try { exchanger.exchange(bean.countedMethod(new Callable<Long>() { @Override public Long call() throws Exception { exchanger.exchange(0L); return exchanger.exchange(0L); } })); } catch (InterruptedException cause) { throw new RuntimeException(cause); } } }); final AtomicInteger uncaught = new AtomicInteger(); thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { uncaught.incrementAndGet(); } }); thread.start(); // Wait until the method is executing and make sure that the counter has been incremented exchanger.exchange(0L, 5L, TimeUnit.SECONDS); assertThat("Concurrent Gauges count is incorrect", cGauge.getCount(), is(equalTo(COUNTER_COUNT.incrementAndGet()))); // Exchange the result and unblock the method execution Long random = 1 + Math.round(Math.random() * (Long.MAX_VALUE - 1)); exchanger.exchange(random, 5L, TimeUnit.SECONDS); // Wait until the method has returned assertThat("Concurrent Gauges method return value is incorrect", exchanger.exchange(0L), is(equalTo(random))); // Then make sure that the counter has been decremented assertThat("Concurrent Gauges count is incorrect", cGauge.getCount(), is(equalTo(COUNTER_COUNT.decrementAndGet()))); // Finally make sure calling thread is returns correctly thread.join(); assertThat("Exception thrown in method call thread", uncaught.get(), is(equalTo(0))); }
Example #19
Source File: MetricProducer.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Produces ConcurrentGauge getConcurrentGauge(InjectionPoint ip) { Metadata metadata = getMetadata(ip, MetricType.CONCURRENT_GAUGE); Tag[] tags = getTags(ip); return this.applicationRegistry.concurrentGauge(metadata, tags); }
Example #20
Source File: TestMetricsServiceImpl.java From smallrye-graphql with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(String name) { throw new UnsupportedOperationException("unimplemented"); }
Example #21
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge getConcurrentGauge(MetricID metricID) { return getMetric(metricID, ConcurrentGauge.class); }
Example #22
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter metricFilter) { return getMetrics(MetricType.CONCURRENT_GAUGE, metricFilter); }
Example #23
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges() { return getConcurrentGauges(MetricFilter.ALL); }
Example #24
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(Metadata metadata, Tag... tags) { return get(new MetricID(metadata.getName(), tags), sanitizeMetadata(metadata, MetricType.CONCURRENT_GAUGE)); }
Example #25
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(String name, Tag... tags) { return get(new MetricID(name, tags), new UnspecifiedMetadata(name, MetricType.CONCURRENT_GAUGE)); }
Example #26
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(MetricID metricID) { return get(metricID, new UnspecifiedMetadata(metricID.getName(), MetricType.CONCURRENT_GAUGE)); }
Example #27
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(Metadata metadata) { return get(new MetricID(metadata.getName()), sanitizeMetadata(metadata, MetricType.CONCURRENT_GAUGE)); }
Example #28
Source File: MetricsRegistryImpl.java From smallrye-metrics with Apache License 2.0 | 4 votes |
@Override public ConcurrentGauge concurrentGauge(String name) { return get(new MetricID(name), new UnspecifiedMetadata(name, MetricType.CONCURRENT_GAUGE)); }
Example #29
Source File: TestMetricsServiceImpl.java From smallrye-graphql with Apache License 2.0 | 4 votes |
@Override public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter filter) { throw new UnsupportedOperationException("unimplemented"); }
Example #30
Source File: TestMetricsServiceImpl.java From smallrye-graphql with Apache License 2.0 | 4 votes |
@Override public SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges() { throw new UnsupportedOperationException("unimplemented"); }