aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc/src/main/java/com/yahoo/container/jdisc/metric/JrtMetrics.java
blob: ecbbcd8e27a53905df91234308e8aa45703ce60f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.metric;

// import com.yahoo.jdisc.Container;

import ai.vespa.metrics.ContainerMetrics;
import com.yahoo.jdisc.Metric;
import com.yahoo.jrt.TransportMetrics;

import static com.yahoo.jrt.TransportMetrics.Snapshot;

/**
 * Emits jrt metrics
 *
 * @author bjorncs
 */
class JrtMetrics {

    private final TransportMetrics transportMetrics = TransportMetrics.getInstance();
    private final Metric metric;
    private Snapshot previousSnapshot = Snapshot.EMPTY;

    JrtMetrics(Metric metric) {
        this.metric = metric;
    }

    void emitMetrics() {
        Snapshot snapshot = transportMetrics.snapshot();
        Snapshot changesSincePrevious = snapshot.changesSince(previousSnapshot);
        increment(ContainerMetrics.JRT_TRANSPORT_TLS_CERTIFICATE_VERIFICATION_FAILURES.baseName(), changesSincePrevious.tlsCertificateVerificationFailures());
        increment(ContainerMetrics.JRT_TRANSPORT_PEER_AUTHORIZATION_FAILURES.baseName(), changesSincePrevious.peerAuthorizationFailures());
        increment(ContainerMetrics.JRT_TRANSPORT_SERVER_TLS_CONNECTIONS_ESTABLISHED.baseName(), changesSincePrevious.serverTlsConnectionsEstablished());
        increment(ContainerMetrics.JRT_TRANSPORT_CLIENT_TLS_CONNECTIONS_ESTABLISHED.baseName(), changesSincePrevious.clientTlsConnectionsEstablished());
        increment(ContainerMetrics.JRT_TRANSPORT_CLIENT_UNENCRYPTED_CONNECTIONS_ESTABLISHED.baseName(), changesSincePrevious.serverUnencryptedConnectionsEstablished());
        increment(ContainerMetrics.JRT_TRANSPORT_CLIENT_UNENCRYPTED_CONNECTIONS_ESTABLISHED.baseName(), changesSincePrevious.clientUnencryptedConnectionsEstablished());
        previousSnapshot = snapshot;
    }

    private void increment(String metricName, long countIncrement) {
        if (countIncrement > 0) {
            metric.add(metricName, countIncrement, null);
        }
    }

}