LCOV - code coverage report
Current view: top level - pgm/http/jetty - JettyMetrics.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 79 79 100.0 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : package com.google.gerrit.pgm.http.jetty;
      15             : 
      16             : import com.google.common.collect.ImmutableSet;
      17             : import com.google.gerrit.metrics.CallbackMetric;
      18             : import com.google.gerrit.metrics.CallbackMetric0;
      19             : import com.google.gerrit.metrics.Description;
      20             : import com.google.gerrit.metrics.Description.Units;
      21             : import com.google.gerrit.metrics.MetricMaker;
      22             : import com.google.inject.Inject;
      23             : import com.google.inject.Singleton;
      24             : 
      25             : @Singleton
      26             : public class JettyMetrics {
      27             : 
      28             :   @Inject
      29          99 :   JettyMetrics(JettyServer jetty, MetricMaker metrics) {
      30          99 :     CallbackMetric0<Integer> minPoolSize =
      31          99 :         metrics.newCallbackMetric(
      32             :             "http/server/jetty/threadpool/min_pool_size",
      33             :             Integer.class,
      34          99 :             new Description("Minimum thread pool size").setGauge());
      35          99 :     CallbackMetric0<Integer> maxPoolSize =
      36          99 :         metrics.newCallbackMetric(
      37             :             "http/server/jetty/threadpool/max_pool_size",
      38             :             Integer.class,
      39          99 :             new Description("Maximum thread pool size").setGauge());
      40          99 :     CallbackMetric0<Integer> poolSize =
      41          99 :         metrics.newCallbackMetric(
      42             :             "http/server/jetty/threadpool/pool_size",
      43             :             Integer.class,
      44          99 :             new Description("Current thread pool size").setGauge());
      45          99 :     CallbackMetric0<Integer> idleThreads =
      46          99 :         metrics.newCallbackMetric(
      47             :             "http/server/jetty/threadpool/idle_threads",
      48             :             Integer.class,
      49          99 :             new Description("Idle threads").setGauge());
      50          99 :     CallbackMetric0<Integer> busyThreads =
      51          99 :         metrics.newCallbackMetric(
      52             :             "http/server/jetty/threadpool/active_threads",
      53             :             Integer.class,
      54          99 :             new Description("Active threads").setGauge());
      55          99 :     CallbackMetric0<Integer> reservedThreads =
      56          99 :         metrics.newCallbackMetric(
      57             :             "http/server/jetty/threadpool/reserved_threads",
      58             :             Integer.class,
      59          99 :             new Description("Reserved threads").setGauge());
      60          99 :     CallbackMetric0<Integer> queueSize =
      61          99 :         metrics.newCallbackMetric(
      62             :             "http/server/jetty/threadpool/queue_size",
      63             :             Integer.class,
      64          99 :             new Description("Queued requests waiting for a thread").setGauge());
      65          99 :     CallbackMetric0<Boolean> lowOnThreads =
      66          99 :         metrics.newCallbackMetric(
      67             :             "http/server/jetty/threadpool/is_low_on_threads",
      68             :             Boolean.class,
      69          99 :             new Description("Whether thread pool is low on threads").setGauge());
      70          99 :     CallbackMetric0<Long> connections =
      71          99 :         metrics.newCallbackMetric(
      72             :             "http/server/jetty/connections/connections",
      73             :             Long.class,
      74          99 :             new Description("The current number of open connections").setGauge());
      75          99 :     CallbackMetric0<Long> connectionsTotal =
      76          99 :         metrics.newCallbackMetric(
      77             :             "http/server/jetty/connections/connections_total",
      78             :             Long.class,
      79          99 :             new Description("The total number of connections opened").setGauge());
      80          99 :     CallbackMetric0<Long> connectionDurationMax =
      81          99 :         metrics.newCallbackMetric(
      82             :             "http/server/jetty/connections/connections_duration_max",
      83             :             Long.class,
      84             :             new Description("The max duration of a connection")
      85          99 :                 .setGauge()
      86          99 :                 .setUnit(Units.MILLISECONDS));
      87          99 :     CallbackMetric0<Double> connectionDurationMean =
      88          99 :         metrics.newCallbackMetric(
      89             :             "http/server/jetty/connections/connections_duration_mean",
      90             :             Double.class,
      91             :             new Description("The mean duration of a connection")
      92          99 :                 .setGauge()
      93          99 :                 .setUnit(Units.MILLISECONDS));
      94          99 :     CallbackMetric0<Double> connectionDurationStDev =
      95          99 :         metrics.newCallbackMetric(
      96             :             "http/server/jetty/connections/connections_duration_stdev",
      97             :             Double.class,
      98             :             new Description("The standard deviation of the duration of a connection")
      99          99 :                 .setGauge()
     100          99 :                 .setUnit(Units.MILLISECONDS));
     101          99 :     CallbackMetric0<Long> receivedMessages =
     102          99 :         metrics.newCallbackMetric(
     103             :             "http/server/jetty/connections/received_messages",
     104             :             Long.class,
     105          99 :             new Description("The total number of messages received").setGauge());
     106          99 :     CallbackMetric0<Long> sentMessages =
     107          99 :         metrics.newCallbackMetric(
     108             :             "http/server/jetty/connections/sent_messages",
     109             :             Long.class,
     110          99 :             new Description("The total number of messages sent").setGauge());
     111          99 :     CallbackMetric0<Long> receivedBytes =
     112          99 :         metrics.newCallbackMetric(
     113             :             "http/server/jetty/connections/received_bytes",
     114             :             Long.class,
     115             :             new Description("Total number of bytes received by tracked connections")
     116          99 :                 .setGauge()
     117          99 :                 .setUnit(Units.BYTES));
     118          99 :     CallbackMetric0<Long> sentBytes =
     119          99 :         metrics.newCallbackMetric(
     120             :             "http/server/jetty/connections/sent_bytes",
     121             :             Long.class,
     122             :             new Description("Total number of bytes sent by tracked connections")
     123          99 :                 .setGauge()
     124          99 :                 .setUnit(Units.BYTES));
     125             : 
     126          99 :     JettyServer.Metrics jettyMetrics = jetty.getMetrics();
     127          99 :     metrics.newTrigger(
     128          99 :         ImmutableSet.<CallbackMetric<?>>of(
     129             :             idleThreads,
     130             :             busyThreads,
     131             :             reservedThreads,
     132             :             minPoolSize,
     133             :             maxPoolSize,
     134             :             poolSize,
     135             :             queueSize,
     136             :             lowOnThreads,
     137             :             connections,
     138             :             connectionsTotal,
     139             :             connectionDurationMax,
     140             :             connectionDurationMean,
     141             :             connectionDurationStDev,
     142             :             receivedMessages,
     143             :             sentMessages,
     144             :             receivedBytes,
     145             :             sentBytes),
     146             :         () -> {
     147          15 :           minPoolSize.set(jettyMetrics.getMinThreads());
     148          15 :           maxPoolSize.set(jettyMetrics.getMaxThreads());
     149          15 :           poolSize.set(jettyMetrics.getThreads());
     150          15 :           idleThreads.set(jettyMetrics.getIdleThreads());
     151          15 :           busyThreads.set(jettyMetrics.getBusyThreads());
     152          15 :           reservedThreads.set(jettyMetrics.getReservedThreads());
     153          15 :           queueSize.set(jettyMetrics.getQueueSize());
     154          15 :           lowOnThreads.set(jettyMetrics.isLowOnThreads());
     155          15 :           connections.set(jettyMetrics.getConnections());
     156          15 :           connectionsTotal.set(jettyMetrics.getConnectionsTotal());
     157          15 :           connectionDurationMax.set(jettyMetrics.getConnectionDurationMax());
     158          15 :           connectionDurationMean.set(jettyMetrics.getConnectionDurationMean());
     159          15 :           connectionDurationStDev.set(jettyMetrics.getConnectionDurationStdDev());
     160          15 :           receivedMessages.set(jettyMetrics.getReceivedMessages());
     161          15 :           sentMessages.set(jettyMetrics.getSentMessages());
     162          15 :           receivedBytes.set(jettyMetrics.getReceivedBytes());
     163          15 :           sentBytes.set(jettyMetrics.getSentBytes());
     164          15 :         });
     165          99 :   }
     166             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750