/** * Creates a new instance of the gauge. * * @param config configuration for this monitor * @param function a function used to fetch the value on demand */ public BasicGauge(MonitorConfig config, Callable<T> function) { super(config.withAdditionalTag(DataSourceType.GAUGE)); this.baseConfig = config; this.function = function; }
/** * Creates a new instance of the counter. */ public BasicInformational(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.INFORMATIONAL)); }
/** * Convert a MonitorConfig for a counter to one that is explicit about * being a RATE. */ private MonitorConfig toRateConfig(MonitorConfig config) { return config.withAdditionalTag(RATE_TAG); }
/** * Construct a gauge that will store a weak reference to a number. The number * should be set by the subclass immediately after the call to super(config); * using the {@link #setBackingNumber(Number)} method. */ protected NumberGauge(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; }
PeakRateCounter(MonitorConfig config, Clock clock) { super(config.withAdditionalTag(DataSourceType.GAUGE)); this.clock = clock; this.peakRate = new StepLong(0L, clock); }
/** * Construct a gauge that will store a weak reference to the number. The value returned * by the monitor will be the value stored in {@code number} or {@code Double.NaN} in case * the referred Number has been garbage collected. */ public NumberGauge(MonitorConfig config, Number number) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; Preconditions.checkNotNull(number, "number"); this.numberRef = new WeakReference<>(number); }
/** * Creates a new instance of the gauge using a specific Clock. Useful for unit testing. */ MinGauge(MonitorConfig config, Clock clock) { super(config.withAdditionalTag(DataSourceType.GAUGE)); min = new StepLong(Long.MAX_VALUE, clock); }
/** * Creates a new instance of the counter. */ public BasicCounter(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.COUNTER)); this.baseConfig = config; spectatorCounter = SpectatorContext.counter(config); }
PercentileGaugeWrapper(MonitorConfig baseConfig, double percentile, int index) { super(baseConfig.withAdditionalTag(percentileTag(percentile))); this.percentile = percentile; this.index = index; }
/** * Create a new instance with the specified configuration. * * @param config configuration for this gauge */ public LongGauge(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; number = new AtomicLong(0L); spectatorGauge = SpectatorContext.gauge(config); }
/** * Create a new instance. */ public BasicDistributionSummary(MonitorConfig config) { super(config); totalAmount = new StepCounter(config.withAdditionalTag(STAT_TOTAL)); count = new StepCounter(config.withAdditionalTag(STAT_COUNT)); max = new MaxGauge(config.withAdditionalTag(STAT_MAX)); min = new MinGauge(config.withAdditionalTag(STAT_MIN)); monitors = UnmodifiableList.<Monitor<?>>of(totalAmount, count, max, min); }
private void addGarbageCollectorMetrics(long timestamp, MetricList metrics) { final List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean bean : beans) { final Tag id = Tags.newTag("id", bean.getName()); metrics.add(new Metric(COLLECTION_COUNT.withAdditionalTag(id), timestamp, bean.getCollectionCount())); metrics.add(new Metric(COLLECTION_TIME.withAdditionalTag(id), timestamp, bean.getCollectionTime())); } }
/** * Creates a new instance of the gauge using a specific clock. Useful for unit testing. */ DoubleMaxGauge(MonitorConfig config, Clock clock) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; max = new StepLong(Double.doubleToLongBits(0.0), clock); spectatorGauge = SpectatorContext.maxGauge(config); }
/** * Create a new instance with the specified configuration. * * @param config configuration for this gauge */ public DoubleGauge(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; number = new AtomicDouble(0.0); spectatorGauge = SpectatorContext.gauge(config); }
/** * Creates a new instance of the gauge using a specific clock. Useful for unit testing. */ MaxGauge(MonitorConfig config, Clock clock) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; max = new StepLong(0L, clock); spectatorGauge = SpectatorContext.maxGauge(config); }
/** * Creates a new instance of the counter. */ DoubleCounter(MonitorConfig config, Clock clock) { // This class will reset the value so it is not a monotonically increasing value as // expected for type=COUNTER. This class looks like a counter to the user and a gauge to // the publishing pipeline receiving the value. super(config.withAdditionalTag(DataSourceType.NORMALIZED)); this.baseConfig = config; count = new StepLong(0L, clock); spectatorCounter = SpectatorContext.counter(config); }
/** * Creates a new instance of the counter. */ @VisibleForTesting public StepCounter(MonitorConfig config, Clock clock) { // This class will reset the value so it is not a monotonically increasing value as // expected for type=COUNTER. This class looks like a counter to the user and a gauge to // the publishing pipeline receiving the value. super(config.withAdditionalTag(DataSourceType.NORMALIZED)); this.baseConfig = config; count = new StepLong(0L, clock); spectatorCounter = SpectatorContext.counter(config); }
protected static Metric asGauge(Metric m) { return new Metric(m.getConfig().withAdditionalTag(ATLAS_GAUGE_TAG), m.getTimestamp(), m.getValue()); }
protected static Metric asCounter(Metric m) { return new Metric(m.getConfig().withAdditionalTag(ATLAS_COUNTER_TAG), m.getTimestamp(), m.getValue()); }
public void increment(String value) { counters.computeIfAbsent(value, v -> { MonitorConfig c = baseConfig.withAdditionalTag(new com.netflix.servo.tag.BasicTag("c", v)); return new BasicCounter(c); }).increment(); }