@Threads(16) @Benchmark public void dotAnd() { Tags.of("key", "value").and("key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5"); }
@SuppressWarnings({ "unchecked" }) private MeterBinder getMeterBinder(Cache cache, Tags tags) { Tags cacheTags = tags.and(getAdditionalTags(cache)); return LambdaSafe .callbacks(CacheMeterBinderProvider.class, this.binderProviders, cache) .withLogger(CacheMetricsRegistrar.class) .invokeAnd((binderProvider) -> binderProvider.getMeterBinder(cache, cacheTags)) .filter(Objects::nonNull).findFirst().orElse(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); }
private AtomicLong getPartitionLatencyHolder(int partition) { return partitionLatencies.computeIfAbsent(partition, k -> { Tags tags = roadStreamTags.and("partition", Integer.toString(k)); AtomicLong latencyHolder = new AtomicLong(); registry.more().timeGauge(OFFRAMP + LATENCY, tags, latencyHolder, MILLISECONDS, AtomicLong::doubleValue); return latencyHolder; }); }
@Override public final void incrementProcessedMessages(final String type, final String tenantId) { Objects.requireNonNull(type); Objects.requireNonNull(tenantId); this.registry.counter(METER_MESSAGES_PROCESSED, Tags.of(MetricsTags.TAG_TENANT, tenantId).and(MetricsTags.TAG_TYPE, type)) .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(); }
@Override public final void incrementProcessedPayload(final String type, final String tenantId, final long payloadSize) { Objects.requireNonNull(type); Objects.requireNonNull(tenantId); if (payloadSize < 0) { // A negative size would mess up the metrics return; } this.registry.counter("hono.messages.processed.payload", Tags.of(MetricsTags.TAG_TENANT, tenantId).and(MetricsTags.TAG_TYPE, type)) .increment(payloadSize); }
public <T> T record(TimerTag timerTag, Supplier<T> supplier) { return registry.timer(OFFRAMP_TIMER, roadStreamTags.and(timerTag.tag)).record(supplier); }
public void record(TimerTag timerTag, Runnable runnable) { registry.timer(OFFRAMP_TIMER, roadStreamTags.and(timerTag.tag)).record(runnable); }
/** * Verifies that HTTP adapter metrics are correctly mapped to * the legacy format's metric names. */ @Test public void testMappingOfHttpAdapterMetrics() { final Tags httpTags = defaultTags .and(MetricsTags.TAG_COMPONENT_TYPE, MetricsTags.VALUE_COMPONENT_TYPE_ADAPTER) .and(MetricsTags.TAG_COMPONENT_NAME, Constants.PROTOCOL_ADAPTER_TYPE_HTTP) .and(MetricsTags.TAG_TENANT, TENANT); assertCommonAdapterMetrics("http", httpTags); }
@Override public final void incrementProcessedMessages(final String type, final String tenantId) { this.registry.counter("hono.messages.processed", Tags .of("tenant", tenantId) .and("type", type)) .increment(); }
@Override public final void incrementUndeliverableMessages(final String type, final String tenantId) { this.registry.counter("hono.messages.undeliverable", Tags .of("tenant", tenantId) .and("type", type)) .increment(); }
/** * Verifies that MQTT adapter metrics are correctly mapped to * the legacy format's metric names. */ @Test public void testMappingOfMqttAdapterMetrics() { final Tags mqttTags = defaultTags .and(MetricsTags.TAG_COMPONENT_TYPE, MetricsTags.VALUE_COMPONENT_TYPE_ADAPTER) .and(MetricsTags.TAG_COMPONENT_NAME, Constants.PROTOCOL_ADAPTER_TYPE_MQTT); assertConnectionMetrics("mqtt", mqttTags); final Tags mqttWithTenantTags = mqttTags.and(MetricsTags.TAG_TENANT, TENANT); assertCommonAdapterMetrics("mqtt", mqttWithTenantTags); }
@Override public final void incrementProcessedPayload(final String type, final String tenantId, final long payloadSize) { if (payloadSize < 0) { // A negative size would mess up the metrics return; } this.registry.counter("hono.messages.processed.payload", Tags .of("tenant", tenantId) .and("type", type)) .increment(payloadSize); }
private void assertConnectionMetrics(final String protocol, final Tags tags) { final Tags tagsWithTenant = tags.and(MetricsTags.TAG_TENANT, TENANT); assertMapping( new Id(MicrometerBasedMetrics.METER_CONNECTIONS_UNAUTHENTICATED, tags, null, null, Type.GAUGE), String.format("%s.counter.hono.%s.connections.unauthenticated.count", HOSTNAME_MAPPED, protocol)); assertMapping( new Id(MicrometerBasedMetrics.METER_CONNECTIONS_AUTHENTICATED, tagsWithTenant, null, null, Type.GAUGE), String.format("%s.counter.hono.%s.connections.authenticated.%s.count", HOSTNAME_MAPPED, protocol, TENANT)); }
OfframpMetrics( String roadName, String streamName, MeterRegistry registry, Clock clock, Map<RoadAndStream, AtomicInteger> activeConnections) { this.registry = registry; this.clock = clock; this.activeConnections = activeConnections; roadAndStream = RoadAndStream.of(roadName, streamName); roadStreamTags = Tags.of(ROAD, roadName).and(STREAM, streamName); commitSuccessCounter = registry.counter(OFFRAMP + COMMIT_SUCCESS, roadStreamTags); commitFailureCounter = registry.counter(OFFRAMP + COMMIT_FAILURE, roadStreamTags); messageCounter = registry.counter(OFFRAMP + MESSAGE, roadStreamTags); bytesCounter = registry.counter(OFFRAMP + BYTES, roadStreamTags); rebalanceCounter = registry.counter(OFFRAMP + REBALANCE, roadStreamTags); roadNotFoundCounter = registry.counter(OFFRAMP + ROAD_NOT_FOUND, roadStreamTags); transportErrorCounter = registry.counter(OFFRAMP + TRANSPORT_ERROR, roadStreamTags); connectionEstablishedCounter = registry.counter(OFFRAMP + CONNECTIONS_ESTABLISHED, roadStreamTags); partitionLatencies = new ConcurrentHashMap<>(); }
@Override public void process(Exchange exchange) { Message in = exchange.getIn(); String defaultMetricsName = simple(exchange, getEndpoint().getMetricsName(), String.class); String finalMetricsName = getStringHeader(in, HEADER_METRIC_NAME, defaultMetricsName); Iterable<Tag> defaultTags = getEndpoint().getTags(); Iterable<Tag> headerTags = getTagHeader(in, HEADER_METRIC_TAGS, Tags.empty()); Iterable<Tag> finalTags = Tags.concat(defaultTags, headerTags).stream() .map(tag -> Tag.of( simple(exchange, tag.getKey(), String.class), simple(exchange, tag.getValue(), String.class))) .reduce(Tags.empty(), Tags::and, Tags::and) .and(Tags.of( CAMEL_CONTEXT_TAG, getEndpoint().getCamelContext().getName())); try { doProcess(exchange, finalMetricsName, finalTags); } catch (Exception e) { exchange.setException(e); } finally { clearMetricsHeaders(in); } }