public StandardMetrics(final SpecCatalog specCatalog, Optional<Config> sysConfig) { this.timeWindowSizeInMinutes = sysConfig.isPresent()? ConfigUtils.getInt(sysConfig.get(), ConfigurationKeys.METRIC_TIMER_WINDOW_SIZE_IN_MINUTES, ConfigurationKeys.DEFAULT_METRIC_TIMER_WINDOW_SIZE_IN_MINUTES) : ConfigurationKeys.DEFAULT_METRIC_TIMER_WINDOW_SIZE_IN_MINUTES; this.metricsContext = specCatalog.getMetricContext(); this.timeForSpecCatalogGet = metricsContext.contextAwareTimer(TIME_FOR_SPEC_CATALOG_GET, timeWindowSizeInMinutes, TimeUnit.MINUTES); this.totalAddedSpecs = new AtomicLong(0); this.totalDeletedSpecs = new AtomicLong(0); this.totalUpdatedSpecs = new AtomicLong(0); this.numActiveSpecs = metricsContext.newContextAwareGauge(NUM_ACTIVE_SPECS_NAME, ()->{ long startTime = System.currentTimeMillis(); int size = specCatalog.getSpecs().size(); updateGetSpecTime(startTime); return size; }); this.totalAddCalls = metricsContext.newContextAwareGauge(TOTAL_ADD_CALLS, ()->this.totalAddedSpecs.get()); this.totalUpdateCalls = metricsContext.newContextAwareGauge(TOTAL_UPDATE_CALLS, ()->this.totalUpdatedSpecs.get()); this.totalDeleteCalls = metricsContext.newContextAwareGauge(TOTAL_DELETE_CALLS, ()->this.totalDeletedSpecs.get()); this.contextAwareMetrics.add(numActiveSpecs); this.contextAwareMetrics.add(totalAddCalls); this.contextAwareMetrics.add(totalUpdateCalls); this.contextAwareMetrics.add(totalDeleteCalls); this.contextAwareMetrics.add(timeForSpecCatalogGet); }
public StandardMetrics(final SpecCatalog specCatalog, Optional<Config> sysConfig) { this.timeWindowSizeInMinutes = sysConfig.isPresent()? ConfigUtils.getInt(sysConfig.get(), ConfigurationKeys.METRIC_TIMER_WINDOW_SIZE_IN_MINUTES, ConfigurationKeys.DEFAULT_METRIC_TIMER_WINDOW_SIZE_IN_MINUTES) : ConfigurationKeys.DEFAULT_METRIC_TIMER_WINDOW_SIZE_IN_MINUTES; this.metricsContext = specCatalog.getMetricContext(); this.timeForSpecCatalogGet = metricsContext.contextAwareTimer(TIME_FOR_SPEC_CATALOG_GET, timeWindowSizeInMinutes, TimeUnit.MINUTES); this.totalAddedSpecs = new AtomicLong(0); this.totalDeletedSpecs = new AtomicLong(0); this.totalUpdatedSpecs = new AtomicLong(0); this.numActiveSpecs = metricsContext.newContextAwareGauge(NUM_ACTIVE_SPECS_NAME, ()->{ long startTime = System.currentTimeMillis(); int size = specCatalog.getSpecs().size(); updateGetSpecTime(startTime); return size; }); this.totalAddCalls = metricsContext.newContextAwareGauge(TOTAL_ADD_CALLS, ()->this.totalAddedSpecs.get()); this.totalUpdateCalls = metricsContext.newContextAwareGauge(TOTAL_UPDATE_CALLS, ()->this.totalUpdatedSpecs.get()); this.totalDeleteCalls = metricsContext.newContextAwareGauge(TOTAL_DELETE_CALLS, ()->this.totalDeletedSpecs.get()); this.contextAwareMetrics.add(numActiveSpecs); this.contextAwareMetrics.add(totalAddCalls); this.contextAwareMetrics.add(totalUpdateCalls); this.contextAwareMetrics.add(totalDeleteCalls); this.contextAwareMetrics.add(timeForSpecCatalogGet); }