public Ratio getHitRatio1Min() { final Meter hitRate = registry.meter(allCacheHitsMetricName); final Meter missRate = registry.meter(allCacheMissesMetricName); final double oneMinuteHitRate = hitRate.getOneMinuteRate(); return Ratio.of(oneMinuteHitRate * 100.0, oneMinuteHitRate + missRate.getOneMinuteRate()); }
private Supplier<Ratio> errorRatioSupplier(Supplier<Double> errorRateSupplier, Supplier<Double> replyRateSupplier) { // We limit both the denominator and the resulting ratio when calculating error ratios. // // The ratio is limited in order to avoid producing ratios that are arbitrarily close to zero // but not quite zero. Them being close to but not quite zero is not a problem per se but it // distorts the apparent meaning of graphs in some monitoring tools - when the ratio goes // from e.g. 1e-316 to 1e-300 it can look like a huge increase indicating that something // sinister is in the works even though the error ratio is basically nil. // // The denominator is limited to avoid noise in the ratio when the total reply rate is low, // dividing by a EWMA-computed rate can cause ratios that are higher than the true ratio due to // computational noise in the EWMA computations. // If a service is drained of traffic (for instance by moving traffic to another host or site), // the meter values will decay exponentially towards zero. If left for some time (hours), // rounding errors will cause the values of the meters to approach each other, thus skewing // the ratio. If an alert is tied to this ratio, it may trigger falsely. To fix this, we set a // minimum for the denominator in the ratio, effectively making sure it will be be bigger than // the error rate as both rates goes towards zero. return () -> { final double denominator = max(replyRateSupplier.get(), ERROR_GAUGE_MINIMUM_REPLY_RATE); final Ratio ratio = Ratio.of(errorRateSupplier.get(), denominator); return ratio.getValue() > ERROR_RATIO_MINIMUM ? ratio : Ratio.of(0, denominator); }; }
@Override protected Ratio getRatio() { return Ratio.of(responses[4].getOneMinuteRate(), requests.getOneMinuteRate()); } });
@Override protected Ratio getRatio() { //TODO Should we use getMeanRate return Ratio.of(meter.getFifteenMinuteRate(), timer.getFifteenMinuteRate()); } }
@Override protected Ratio getRatio() { return RatioGauge.Ratio.of(success.getFiveMinuteRate(), attempts.getFiveMinuteRate()); } }
METRICS.deleteTracker, METRICS.incrementTracker, METRICS.putTracker }) { assertEquals("Failed to invoke callTimer on " + t, loop, t.callTimer.getCount()); assertEquals("Failed to invoke reqHist on " + t, loop, t.reqHist.getCount()); assertEquals("Failed to invoke respHist on " + t, loop, t.respHist.getCount()); RatioGauge metaMetrics = (RatioGauge) METRICS.getMetricRegistry() .getMetrics().get(METRICS.getMetaPoolName()); assertEquals(Ratio.of(0, 3).getValue(), executorMetrics.getValue(), 0); assertEquals(Double.NaN, metaMetrics.getValue(), 0);
@Override protected Ratio getRatio() { return Ratio.of( getHits.getFiveMinuteRate(), gets.getFiveMinuteRate() + multigetItems.getFiveMinuteRate()); } };
protected Ratio getRatio() { return Ratio.of(hits.getFifteenMinuteRate(), requests.getFifteenMinuteRate()); } });
@Override protected Ratio getRatio() { return Ratio.of(sizeGauge.getValue(), sizeLimitGauge.getValue()); } });
@Override protected Ratio getRatio() { return Ratio.of(getSnapshot().getUsed(), getSnapshot().getTotal() * 100.0); } });
/** * Creates a new ratio with the given numerator and denominator. * * @param numerator the numerator of the ratio * @param denominator the denominator of the ratio * @return {@code numerator:denominator} */ public static Ratio of(double numerator, double denominator) { return new Ratio(numerator, denominator); }
@Override protected Ratio getRatio() { return Ratio.of(pooledResource.getPoolNumActive() * 100.0, pooledResource.getMaxPoolSize()); } });
@Override public Double getValue() { return getRatio().getValue(); } }
@Override public Map<MetricId, Metric> getMetrics() { final Map<MetricId, Metric> gauges = new HashMap<>(); final MetricId metricId = MetricId.build().tagged("what", "file-descriptor-ratio", "unit", "%"); gauges.put(metricId, (Gauge<Object>) () -> { try { return fileDescriptorRatioGauge.getValue(); } catch (final Exception ex) { LOG.debug("Failed to get metrics for FileDescriptorGaugeSet", ex); // This is what the upstream FileDescriptorRatioGauge returns when an exception occurs. return RatioGauge.Ratio.of(Double.NaN, Double.NaN); } }); return Collections.unmodifiableMap(gauges); } });