|  | 
| 14 | 14 | import java.util.concurrent.Executors; | 
| 15 | 15 | import java.util.concurrent.ScheduledExecutorService; | 
| 16 | 16 | import java.util.concurrent.ThreadFactory; | 
| 17 |  | -import java.util.concurrent.atomic.AtomicLong; | 
| 18 | 17 | import lombok.NonNull; | 
| 19 | 18 | import lombok.extern.slf4j.Slf4j; | 
| 20 | 19 | import org.hypertrace.core.documentstore.Datastore; | 
| 21 | 20 | import org.hypertrace.core.documentstore.metric.DocStoreMetric; | 
| 22 | 21 | import org.hypertrace.core.documentstore.metric.DocStoreMetricProvider; | 
| 23 | 22 | import org.hypertrace.core.serviceframework.metrics.Measurement; | 
| 24 |  | -import org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry; | 
| 25 | 23 | import org.hypertrace.core.serviceframework.metrics.ResizeableGauge; | 
| 26 | 24 | import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle; | 
| 27 | 25 | 
 | 
| @@ -97,7 +95,6 @@ public void monitor() { | 
| 97 | 95 | 
 | 
| 98 | 96 |     addShutdownHook(); | 
| 99 | 97 | 
 | 
| 100 |  | -    new StandardDocStoreMetricsRegistry().monitor(); | 
| 101 | 98 |     monitorCustomMetrics(); | 
| 102 | 99 |   } | 
| 103 | 100 | 
 | 
| @@ -158,36 +155,4 @@ private void report( | 
| 158 | 155 |       log.warn("Unable to report custom database metric for config: {}", reportingConfig, e); | 
| 159 | 156 |     } | 
| 160 | 157 |   } | 
| 161 |  | - | 
| 162 |  | -  private class StandardDocStoreMetricsRegistry { | 
| 163 |  | -    private final AtomicLong connectionCount; | 
| 164 |  | - | 
| 165 |  | -    public StandardDocStoreMetricsRegistry() { | 
| 166 |  | -      this.connectionCount = registerConnectionCountMetric(); | 
| 167 |  | -    } | 
| 168 |  | - | 
| 169 |  | -    private void monitor() { | 
| 170 |  | -      executor.scheduleAtFixedRate( | 
| 171 |  | -          this::queryDocStoreAndSetMetricValues, | 
| 172 |  | -          INITIAL_DELAY_SECONDS, | 
| 173 |  | -          standardMetricsReportingInterval.toSeconds(), | 
| 174 |  | -          SECONDS); | 
| 175 |  | -    } | 
| 176 |  | - | 
| 177 |  | -    private AtomicLong registerConnectionCountMetric() { | 
| 178 |  | -      final DocStoreMetric docStoreMetric = metricProvider.getConnectionCountMetric(); | 
| 179 |  | -      return PlatformMetricsRegistry.registerGauge( | 
| 180 |  | -          docStoreMetric.name(), | 
| 181 |  | -          docStoreMetric.labels(), | 
| 182 |  | -          new AtomicLong(castToLong(docStoreMetric.value()))); | 
| 183 |  | -    } | 
| 184 |  | - | 
| 185 |  | -    private void queryDocStoreAndSetMetricValues() { | 
| 186 |  | -      connectionCount.set(castToLong(metricProvider.getConnectionCountMetric().value())); | 
| 187 |  | -    } | 
| 188 |  | - | 
| 189 |  | -    private long castToLong(final double value) { | 
| 190 |  | -      return Double.valueOf(value).longValue(); | 
| 191 |  | -    } | 
| 192 |  | -  } | 
| 193 | 158 | } | 
0 commit comments