private static AtomicLong getGauge(String name, String... additionalTags) { String key = className + "." + name + "." + Joiner.on(",").join(additionalTags); return gauges.computeIfAbsent(key, pollTimer -> { Id id = registry.createId(name, getTags(additionalTags)); return PolledMeter.using(registry) .withId(id) .monitorValue(new AtomicLong(0)); }); }
@Inject public CassMonitorMetrics(Registry registry) { cassStop = registry.gauge(Metrics.METRIC_PREFIX + "cass.stop"); cassStart = registry.gauge(Metrics.METRIC_PREFIX + "cass.start"); cassAutoStart = registry.gauge(Metrics.METRIC_PREFIX + "cass.auto.start"); getSeedsCnt = PolledMeter.using(registry) .withName(Metrics.METRIC_PREFIX + "cass.getSeedCnt") .monitorMonotonicCounter(new AtomicLong(0)); getTokenCnt = PolledMeter.using(registry) .withName(Metrics.METRIC_PREFIX + "cass.getTokenCnt") .monitorMonotonicCounter(new AtomicLong(0)); getReplacedIpCnt = PolledMeter.using(registry) .withName(Metrics.METRIC_PREFIX + "cass.getReplacedIpCnt") .monitorMonotonicCounter(new AtomicLong(0)); doubleRingCnt = PolledMeter.using(registry) .withName(Metrics.METRIC_PREFIX + "cass.doubleRingCnt") .monitorMonotonicCounter(new AtomicLong(0)); }
/** * Set the base identifier for the type being constructed. * * @param id * Identifier for the type being constructed. * @return * Builder object to allow for method chaining. */ public T withId(Id id) { return createTypeBuilder(id); } }
/** * Set the base identifier for the type being constructed. * * @param id * Identifier for the type being constructed. * @return * Builder object to allow for method chaining. */ public T withId(Id id) { return createTypeBuilder(id); } }
@Override public void registerGauge(String id, Supplier<Number> supplier, String... tagNameValuePairs) { Id metricId = suffixBaseId(id).withTags(tagNameValuePairs); PolledMeter.remove(registry, metricId); PolledMeter.using(registry) .withId(metricId) .monitorValue(supplier, ignore -> supplier.get().doubleValue()); }
new ArrayBlockingQueue<>(configuration.getBackupQueueSize()); PolledMeter.using(backupMetrics.getRegistry()) .withName(backupMetrics.uploadQueueSize) .monitorSize(uploadQueue); this.fileUploadExecutor = new ArrayBlockingQueue<>(configuration.getDownloadQueueSize()); PolledMeter.using(backupMetrics.getRegistry()) .withName(backupMetrics.downloadQueueSize) .monitorSize(downloadQueue); this.fileDownloadExecutor =
/** * Create a new identifier with the provide name. * * @param name * Name used in the identifier. * @return * Builder object to allow for method chaining. */ public T withName(String name) { return createTypeBuilder(registry.createId(name)); }
/** Create builder for a polled gauge based on the config. */ public static PolledMeter.Builder polledGauge(MonitorConfig config) { long delayMillis = Math.max(Pollers.getPollingIntervals().get(0) - 1000, 5000); Id id = createId(config); PolledMeter.remove(registry, id); return PolledMeter.using(registry) .withId(id) .withDelay(Duration.ofMillis(delayMillis)) .scheduleOn(gaugePool()); }
.withName("genie.tasks.databaseCleanup.numDeletedJobs.gauge") .monitorValue(new AtomicLong()); this.numDeletedClusters = PolledMeter .using(registry) .withName("genie.tasks.databaseCleanup.numDeletedClusters.gauge") .monitorValue(new AtomicLong()); this.numDeletedTags = PolledMeter .using(registry) .withName("genie.tasks.databaseCleanup.numDeletedTags.gauge") .monitorValue(new AtomicLong()); this.numDeletedFiles = PolledMeter .using(registry) .withName("genie.tasks.databaseCleanup.numDeletedFiles.gauge") .monitorValue(new AtomicLong()); this.deletionTimerId = registry.createId("genie.tasks.databaseCleanup.duration.timer");
/** * Create a new identifier with the provide name. * * @param name * Name used in the identifier. * @return * Builder object to allow for method chaining. */ public T withName(String name) { return createTypeBuilder(registry.createId(name)); }
private static AtomicLong getGauge(String name, String... additionalTags) { String key = className + "." + name + "." + Joiner.on(",").join(additionalTags); return gauges.computeIfAbsent(key, pollTimer -> { Id id = registry.createId(name, getTags(additionalTags)); return PolledMeter.using(registry) .withId(id) .monitorValue(new AtomicLong(0)); }); }
.withName("genie.tasks.clusterChecker.errorCounts.gauge") .monitorSize(this.errorCounts); this.lostJobsCounter = registry.counter("genie.tasks.clusterChecker.lostJobs.rate");
/** * Tells the registry to regularly poll the value of a {@link java.lang.Number} and report * it as a gauge. See {@link #gauge(Id, Number)} for more information. * * @param id * Identifier for the metric being registered. * @param number * Thread-safe implementation of {@link Number} used to access the value. * @return * The number that was passed in so the registration can be done as part of an assignment * statement. * @deprecated * Use {@link PolledMeter} instead. This method has been deprecated to help * reduce confusion between active gauges that are explicitly updated by the * user and passive gauges that are polled in the background. Going forward * the registry methods will only be used for the core types directly updated * by the user. Other patterns such as {@link PolledMeter}s will be handled * separately. Scheduled to be removed in 2.0. */ @Deprecated default <T extends Number> T gauge(Id id, T number) { return PolledMeter.using(this).withId(id).monitorValue(number); }
/** * See {@link #gauge(Id, Object, ToDoubleFunction)} for more information. * * @param id * Identifier for the metric being registered. * @param obj * Object used to compute a value. * @param f * Function that is applied on the value for the number. * @return * The object that was passed in so the registration can be done as part of an assignment * statement. * @deprecated * Use {@link PolledMeter} instead. This method has been deprecated to help * reduce confusion between active gauges that are explicitly updated by the * user and passive gauges that are polled in the background. Going forward * the registry methods will only be used for the core types directly updated * by the user. Other patterns such as {@link PolledMeter}s will be handled * separately. Scheduled to be removed in 2.0. */ @Deprecated default <T> T gauge(Id id, T obj, ToDoubleFunction<T> f) { return PolledMeter.using(this).withId(id).monitorValue(obj, f); }
.withName("genie.tasks.diskCleanup.numberDeletedJobDirs.gauge") .monitorValue(new AtomicLong()); this.numberOfDirsUnableToDelete = PolledMeter .using(registry) .withName("genie.tasks.diskCleanup.numberDirsUnableToDelete.gauge") .monitorValue(new AtomicLong()); this.unableToGetJobCounter = registry.counter("genie.tasks.diskCleanup.unableToGetJobs.rate");
/** * See {@link #gauge(Id, Object, ToDoubleFunction)} for more information. * * @param id * Identifier for the metric being registered. * @param obj * Object used to compute a value. * @param f * Function that is applied on the value for the number. * @return * The object that was passed in so the registration can be done as part of an assignment * statement. * @deprecated * Use {@link PolledMeter} instead. This method has been deprecated to help * reduce confusion between active gauges that are explicitly updated by the * user and passive gauges that are polled in the background. Going forward * the registry methods will only be used for the core types directly updated * by the user. Other patterns such as {@link PolledMeter}s will be handled * separately. Scheduled to be removed in 2.0. */ @Deprecated default <T> T gauge(Id id, T obj, ToDoubleFunction<T> f) { return PolledMeter.using(this).withId(id).monitorValue(obj, f); }
.withName("genie.jobs.file.cache.hitRate") .monitorValue(this.fileCache, value -> value.stats().hitRate()); .withName("genie.jobs.file.cache.missRate") .monitorValue(this.fileCache, value -> value.stats().missRate()); .withName("genie.jobs.file.cache.loadExceptionRate") .monitorValue(this.fileCache, value -> value.stats().loadExceptionRate());
/** * Tells the registry to regularly poll the value of a {@link java.lang.Number} and report * it as a gauge. See {@link #gauge(Id, Number)} for more information. * * @param id * Identifier for the metric being registered. * @param number * Thread-safe implementation of {@link Number} used to access the value. * @return * The number that was passed in so the registration can be done as part of an assignment * statement. * @deprecated * Use {@link PolledMeter} instead. This method has been deprecated to help * reduce confusion between active gauges that are explicitly updated by the * user and passive gauges that are polled in the background. Going forward * the registry methods will only be used for the core types directly updated * by the user. Other patterns such as {@link PolledMeter}s will be handled * separately. Scheduled to be removed in 2.0. */ @Deprecated default <T extends Number> T gauge(Id id, T number) { return PolledMeter.using(this).withId(id).monitorValue(number); }
.withName(TASK_COUNT) .withTag(idTag) .monitorMonotonicCounter(threadPool, ThreadPoolExecutor::getTaskCount); PolledMeter.using(registry) .withName(COMPLETED_TASK_COUNT) .withTag(idTag) .monitorMonotonicCounter(threadPool, ThreadPoolExecutor::getCompletedTaskCount); PolledMeter.using(registry) .withName(CURRENT_THREADS_BUSY) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getActiveCount); PolledMeter.using(registry) .withName(MAX_THREADS) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getMaximumPoolSize); PolledMeter.using(registry) .withName(POOL_SIZE) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getPoolSize); PolledMeter.using(registry) .withName(CORE_POOL_SIZE) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getCorePoolSize); PolledMeter.using(registry) .withName(QUEUE_SIZE) .withTag(idTag) .monitorValue(threadPool, tp -> tp.getQueue().size());