@Bean public MetricCollectingServerInterceptor metricCollectingServerInterceptor(final MeterRegistry registry, final Collection<BindableService> services) { final MetricCollectingServerInterceptor metricCollector = new MetricCollectingServerInterceptor(registry, counter -> counter.tag("type", "counter"), timer -> timer.tag("type", "timer").publishPercentiles(0.5, 0.9, 0.99), OK, UNKNOWN); log.debug("Pre-Registering custom service metrics"); for (final BindableService service : services) { log.debug("- {}", service); metricCollector.preregisterService(service); } return metricCollector; }
@Test public void testServerCustomization() { log.info("--- Starting tests with server customization ---"); final MeterRegistry meterRegistry = new SimpleMeterRegistry(); assertEquals(0, meterRegistry.getMeters().size()); final MetricCollectingServerInterceptor mcsi = new MetricCollectingServerInterceptor(meterRegistry, counter -> counter.tag("type", "counter"), timer -> timer.tag("type", "timer").publishPercentiles(0.5, 0.9, 0.99), OK, UNKNOWN); mcsi.preregisterService(new TestServiceImpl()); MetricTestHelper.logMeters(meterRegistry.getMeters()); assertEquals(METHOD_COUNT * 10, meterRegistry.getMeters().size()); final Counter counter = meterRegistry.find(METRIC_NAME_SERVER_REQUESTS_RECEIVED).counter(); assertNotNull(counter); assertEquals("counter", counter.getId().getTag("type")); final Timer timer = meterRegistry.find(METRIC_NAME_SERVER_PROCESSING_DURATION).timer(); assertNotNull(timer); assertEquals("timer", timer.getId().getTag("type")); log.info("--- Test completed ---"); }
@Test public void testClientCustomization() { log.info("--- Starting tests with client customization ---"); final MeterRegistry meterRegistry = new SimpleMeterRegistry(); assertEquals(0, meterRegistry.getMeters().size()); final MetricCollectingClientInterceptor mcci = new MetricCollectingClientInterceptor(meterRegistry, counter -> counter.tag("type", "counter"), timer -> timer.tag("type", "timer").publishPercentiles(0.5, 0.9, 0.99), OK, UNKNOWN); mcci.preregisterService(TestServiceGrpc.getServiceDescriptor()); MetricTestHelper.logMeters(meterRegistry.getMeters()); assertEquals(METHOD_COUNT * 10, meterRegistry.getMeters().size()); final Counter counter = meterRegistry.find(METRIC_NAME_CLIENT_REQUESTS_SENT).counter(); assertNotNull(counter); assertEquals("counter", counter.getId().getTag("type")); final Timer timer = meterRegistry.find(METRIC_NAME_CLIENT_PROCESSING_DURATION).timer(); assertNotNull(timer); assertEquals("timer", timer.getId().getTag("type")); log.info("--- Test completed ---"); }
Counter.builder("zipkin_collector.messages") .description("cumulative amount of messages received") .tag("transport", transport) .register(registryInstance); this.messagesDropped = Counter.builder("zipkin_collector.messages_dropped") .description("cumulative amount of messages received that were later dropped") .tag("transport", transport) .register(registryInstance); Counter.builder("zipkin_collector.bytes") .description("cumulative amount of bytes received") .tag("transport", transport) .baseUnit("bytes") .register(registryInstance); Counter.builder("zipkin_collector.spans") .description("cumulative amount of spans received") .tag("transport", transport) .register(registryInstance); this.spansDropped = Counter.builder("zipkin_collector.spans_dropped") .description("cumulative amount of spans received that were later dropped") .tag("transport", transport) .register(registryInstance);
Counter.builder("che.server.api.response") .description("Che Server Tomcat informational responses (1xx responses)") .tag("code", "1xx") .tag("area", "http") .register(registry); successResponseCounter = Counter.builder("che.server.api.response") .description("Che Server Tomcat success responses (2xx responses)") .tag("code", "2xx") .tag("area", "http") .register(registry); redirectResponseCounter = Counter.builder("che.server.api.response") .description("Che Server Tomcat redirect responses (3xx responses)") .tag("code", "3xx") .tag("area", "http") .register(registry); clientErrorResponseCounter = Counter.builder("che.server.api.response") .description("Che Server Tomcat client errors (4xx responses)") .tag("code", "4xx") .tag("area", "http") .register(registry); serverErrorResponseCounter = Counter.builder("che.server.api.response") .description("Che Server Tomcat server errors (5xx responses)") .tag("code", "5xx") .tag("area", "http") .register(registry);
/** * Creates a new counter builder for the given method. By default the base unit will be messages. * * @param method The method the counter will be created for. * @param name The name of the counter to use. * @param description The description of the counter to use. * @return The newly created counter builder. */ public static Counter.Builder prepareCounterFor(final MethodDescriptor<?, ?> method, final String name, final String description) { return Counter.builder(name) .description(description) .baseUnit("messages") .tag(TAG_SERVICE_NAME, extractServiceName(method)) .tag(TAG_METHOD_NAME, extractMethodName(method)); }
@Override public CounterBuilder tag(String key, String value) { this.builder.tag(key, value); return this; }
/** * Creates a new counter builder for the given method. By default the base unit will be messages. * * @param method The method the counter will be created for. * @param name The name of the counter to use. * @param description The description of the counter to use. * @return The newly created counter builder. */ public static Counter.Builder prepareCounterFor(final MethodDescriptor<?, ?> method, final String name, final String description) { return Counter.builder(name) .description(description) .baseUnit("messages") .tag(TAG_SERVICE_NAME, extractServiceName(method)) .tag(TAG_METHOD_NAME, extractMethodName(method)); }
@Override public CounterBuilder tag(String key, String value) { this.builder.tag(key, value); return this; }