/** * Constructs a new Micrometer metrics listener that adds metrics to the given registry with the given list of tags. * * @param meterRegistry the registry to which to add metrics * @param tagKeysAndValues an optional list of tag keys/values to attach to metrics; must be an even number of * strings representing alternating key/value pairs */ public MicrometerApnsClientMetricsListener(final MeterRegistry meterRegistry, final String... tagKeysAndValues) { this(meterRegistry, Tags.of(tagKeysAndValues)); }
/** * Returns a {@link MeterIdPrefixFunction} that returns a newly created {@link MeterIdPrefix} which has * the specified label added. */ default MeterIdPrefixFunction withTags(String... keyValues) { requireNonNull(keyValues, "keyValues"); return withTags(Tags.of(keyValues)); }
@Threads(16) @Benchmark public void of() { Tags.of("key", "value", "key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5"); }
@Threads(16) @Benchmark public void dotAnd() { Tags.of("key", "value").and("key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5"); }
private void endTimerInner(ServerWebExchange exchange, Sample sample) { String outcome = "CUSTOM"; String status = "CUSTOM"; HttpStatus statusCode = exchange.getResponse().getStatusCode(); if (statusCode != null) { outcome = statusCode.series().name(); status = statusCode.name(); } else { // a non standard HTTPS status could be used. Let's be defensive here if (exchange.getResponse() instanceof AbstractServerHttpResponse) { Integer statusInt = ((AbstractServerHttpResponse) exchange.getResponse()) .getStatusCodeValue(); if (statusInt != null) { status = String.valueOf(statusInt); } else { status = "NA"; } } } Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR); Tags tags = Tags.of("outcome", outcome, "status", status, "routeId", route.getId(), "routeUri", route.getUri().toString()); if (log.isTraceEnabled()) { log.trace("Stopping timer 'gateway.requests' with tags " + tags); } sample.stop(meterRegistry.timer("gateway.requests", tags)); } }
/** * Return additional {@link Tag tags} to be associated with the given {@link Cache}. * @param cache the cache * @return a list of additional tags to associate to that {@code cache}. */ protected Iterable<Tag> getAdditionalTags(Cache cache) { return Tags.of("name", cache.getName()); }
@Override public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) { return Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, null)); }
private static Counter counter( MeterRegistry meterRegistry, String interactionModel, SignalType signalType, Tag... tags) { return meterRegistry.counter( "rsocket." + interactionModel, Tags.of(tags).and("signal.type", signalType.name())); } }
private static Timer timer( MeterRegistry meterRegistry, String interactionModel, SignalType signalType, Tag... tags) { return meterRegistry.timer( "rsocket." + interactionModel, Tags.of(tags).and("signal.type", signalType.name())); } }
/** * Creates a new {@link DuplexConnection}. * * @param connectionType the type of connection being monitored * @param delegate the {@link DuplexConnection} to delegate to * @param meterRegistry the {@link MeterRegistry} to use * @param tags additional tags to attach to {@link Meter}s * @throws NullPointerException if {@code connectionType}, {@code delegate}, or {@code * meterRegistry} is {@code null} */ MicrometerDuplexConnection( Type connectionType, DuplexConnection delegate, MeterRegistry meterRegistry, Tag... tags) { Objects.requireNonNull(connectionType, "connectionType must not be null"); this.delegate = Objects.requireNonNull(delegate, "delegate must not be null"); Objects.requireNonNull(meterRegistry, "meterRegistry must not be null"); this.close = meterRegistry.counter( "rsocket.duplex.connection.close", Tags.of(tags).and("connection.type", connectionType.name())); this.dispose = meterRegistry.counter( "rsocket.duplex.connection.dispose", Tags.of(tags).and("connection.type", connectionType.name())); this.frameCounters = new FrameCounters(connectionType, meterRegistry, tags); }
/** * Attempt to bind the specified {@link Cache} to the registry. Return {@code true} if * the cache is supported and was bound to the registry, {@code false} otherwise. * @param cache the cache to handle * @param tags the tags to associate with the metrics of that cache * @return {@code true} if the {@code cache} is supported and was registered */ public boolean bindCacheToRegistry(Cache cache, Tag... tags) { MeterBinder meterBinder = getMeterBinder(unwrapIfNecessary(cache), Tags.of(tags)); if (meterBinder != null) { meterBinder.bindTo(this.registry); return true; } return false; }
private static Counter counter( Type connectionType, MeterRegistry meterRegistry, String frameType, Tag... tags) { return meterRegistry.counter( "rsocket.frame", Tags.of(tags).and("connection.type", connectionType.name()).and("frame.type", frameType)); } }
@Override public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) { return Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, response), WebMvcTags.exception(exception), WebMvcTags.status(response), WebMvcTags.outcome(response)); }
/** * Record metrics on a ConcurrentMapCache cache. * * @param registry The registry to bind metrics to. * @param cache The cache to instrument. * @param tags Tags to apply to all recorded metrics. Must be an even number of arguments representing key/value pairs of tags. * @return The instrumented cache, unchanged. The original cache is not wrapped or proxied in any way. */ public static ConcurrentMapCache monitor(MeterRegistry registry, ConcurrentMapCache cache, String... tags) { return monitor(registry, cache, Tags.of(tags)); }
default Tags getTags(CamelContext camelContext) { return Tags.of( SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(), CAMEL_CONTEXT_TAG, camelContext.getName(), EVENT_TYPE_TAG, AbstractRouteEvent.class.getSimpleName()); } }
private static MeterFilter createMapFilter(Map<String, String> tags) { if (tags.isEmpty()) { return new MeterFilter() { }; } Tags commonTags = Tags.of(tags.entrySet().stream() .map((entry) -> Tag.of(entry.getKey(), entry.getValue())) .collect(Collectors.toList())); return MeterFilter.commonTags(commonTags); }
@Override public final void incrementNoCommandReceivedAndTTDExpired(final String tenantId) { Objects.requireNonNull(tenantId); this.registry.counter(METER_COMMANDS_TTD_EXPIRED, Tags.of(MetricsTags.TAG_TENANT, tenantId)) .increment(); }
@Override public final void incrementUndeliverableMessages(final String type, final String tenantId) { Objects.requireNonNull(type); Objects.requireNonNull(tenantId); this.registry.counter(METER_MESSAGES_UNDELIVERABLE, Tags.of(MetricsTags.TAG_TENANT, tenantId).and(MetricsTags.TAG_TYPE, type)) .increment(); }
/** * Creates the default tag set for a service. * * @param name The name of the service. * @return A ready to use tag set. */ public static Tags forService(final String name) { return Tags.of( Tag.of(MetricsTags.TAG_HOST, Hostnames.getHostname()), Tag.of(MetricsTags.TAG_COMPONENT_TYPE, MetricsTags.VALUE_COMPONENT_TYPE_SERVICE), Tag.of(MetricsTags.TAG_COMPONENT_NAME, name)); }
/** * Creates the default tag set for a protocol adapter. * * @param name The name of the protocol adapter. * @return A ready to use tag set. */ public static Tags forProtocolAdapter(final String name) { return Tags.of( Tag.of(MetricsTags.TAG_HOST, Hostnames.getHostname()), Tag.of(MetricsTags.TAG_COMPONENT_TYPE, MetricsTags.VALUE_COMPONENT_TYPE_ADAPTER), Tag.of(MetricsTags.TAG_COMPONENT_NAME, name)); }