public void addBucket(Bucket lastBucket) { for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { getAdder(type).add(lastBucket.getAdder(type).sum()); } if (type.isMaxUpdater()) { getMaxUpdater(type).update(lastBucket.getMaxUpdater(type).max()); } } }
/** * Increment the counter in the current bucket by one for the given {@link HystrixRollingNumberEvent} type. * <p> * The {@link HystrixRollingNumberEvent} must be a "counter" type <code>HystrixRollingNumberEvent.isCounter() == true</code>. * * @param type * HystrixRollingNumberEvent defining which counter to increment */ public void increment(HystrixRollingNumberEvent type) { getCurrentBucket().getAdder(type).increment(); }
/** * Update a value and retain the max value. * <p> * The {@link HystrixRollingNumberEvent} must be a "max updater" type <code>HystrixRollingNumberEvent.isMaxUpdater() == true</code>. * * @param type HystrixRollingNumberEvent defining which counter to retrieve values from * @param value long value to be given to the max updater */ public void updateRollingMax(HystrixRollingNumberEvent type, long value) { getCurrentBucket().getMaxUpdater(type).update(value); }
/** * Add to the counter in the current bucket for the given {@link HystrixRollingNumberEvent} type. * <p> * The {@link HystrixRollingNumberEvent} must be a "counter" type <code>HystrixRollingNumberEvent.isCounter() == true</code>. * * @param type * HystrixRollingNumberEvent defining which counter to add to * @param value * long value to be added to the current bucket */ public void add(HystrixRollingNumberEvent type, long value) { getCurrentBucket().getAdder(type).add(value); }
/** * Force a reset of all rolling counters (clear all buckets) so that statistics start being gathered from scratch. * <p> * This does NOT reset the CumulativeSum values. */ public void reset() { // if we are resetting, that means the lastBucket won't have a chance to be captured in CumulativeSum, so let's do it here Bucket lastBucket = buckets.peekLast(); if (lastBucket != null) { cumulativeSum.addBucket(lastBucket); } // clear buckets so we start over again buckets.clear(); }
/** * Returns the {@link #max} as a {@code float} * after a widening primitive conversion. */ public float floatValue() { return (float)max(); }
/** * Get the rolling count for the given {@link HystrixRollingNumberEvent}. * <p> * The rolling window is defined by {@link HystrixCommandProperties#metricsRollingStatisticalWindowInMilliseconds()}. * * @param event * {@link HystrixRollingNumberEvent} of the event to retrieve a sum for * @return long rolling count */ public long getRollingCount(HystrixRollingNumberEvent event) { return counter.getRollingSum(event); }
/** * Returns the {@link #sum} as an {@code int} after a narrowing * primitive conversion. */ public int intValue() { return (int)sum(); }
/** * Retrieve (or create) an interned HystrixCommandKey instance for a given name. * * @param name command name * @return HystrixCommandKey instance that is interned (cached) so a given name will always retrieve the same instance. */ public static HystrixCommandKey asKey(String name) { return intern.interned(name); }
/** * Get the cumulative count since the start of the application for the given {@link HystrixRollingNumberEvent}. * * @param event * {@link HystrixRollingNumberEvent} of the event to retrieve a sum for * @return long cumulative count */ public long getCumulativeCount(HystrixRollingNumberEvent event) { return counter.getCumulativeSum(event); }
private ListState incrementTail() { /* if incrementing results in growing larger than 'length' which is the max we should be at, then also increment head (equivalent of removeFirst but done atomically) */ if (size == numBuckets) { // increment tail and head return new ListState(data, (head + 1) % dataLength, (tail + 1) % dataLength); } else { // increment only tail return new ListState(data, head, (tail + 1) % dataLength); } }
/** * Equivalent to {@code add(1)}. */ public void increment() { add(1L); }
/** * Provides percentile computation. */ public int getPercentile(double percentile) { if (length == 0) { return 0; } return computePercentile(percentile); }
/** * Returns the {@link #max} as an {@code int} after a narrowing * primitive conversion. */ public int intValue() { return (int)max(); }
/** * Returns the {@link #sum} as a {@code double} after a widening * primitive conversion. */ public double doubleValue() { return (double)sum(); }
/** * Returns the {@link #max} as a {@code double} after a widening * primitive conversion. */ public double doubleValue() { return (double)max(); }
/** * Equivalent to {@link #sum}. * * @return the sum */ public long longValue() { return sum(); }
/** * Equivalent to {@link #max}. * * @return the maximum */ public long longValue() { return max(); }