public GaugeMetricValue createEmptyValue(TimeRange range) { return new GaugeMetricValue(range); }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; GaugeMetricValue that = (GaugeMetricValue) obj; return (Double.compare(that.max, max) == 0) && (Double.compare(that.min, min) == 0) && (n == that.n) && (Double.compare(that.sum, sum) == 0) && (Double.compare(that.sumOfSquares, sumOfSquares) == 0) && ObjectUtil.typedEquals(getHistogram(), that.getHistogram()) && ObjectUtil.typedEquals(getRange(), that.getRange()) ; }
public IDataPoint getDataPoint() { if (dataPoint == null) { dataPoint = new DataPoint(getTimeStamp(), getMean()); } return dataPoint; }
public void toData(DataOutput dataOutput) throws IOException { super.toData(serialVersionUID, dataOutput); dataOutput.writeInt(slots.size()); int usedSlots = 0; for (GaugeMetricValue v : slots) { if (v != null) usedSlots++; } dataOutput.writeInt(usedSlots); int idx = -1; for (GaugeMetricValue v : slots) { idx++; if (v == null) { continue; } dataOutput.writeInt(idx); dataOutput.writeDouble(v.getMin()); dataOutput.writeDouble(v.getMax()); dataOutput.writeLong(v.getN()); dataOutput.writeDouble(v.getSum()); dataOutput.writeDouble(v.getSumOfSquares()); dataOutput.writeLong(v.getRange().getStart()); SparseHistogram histo = v.getHistogram(); dataOutput.writeInt(histo.getBins().size()); for (IndexedBin bin : histo.getBins()) { dataOutput.writeInt(bin.getBinNumber()); dataOutput.writeLong(bin.getCount()); } } }
/** * Create a {@link GaugeMetricValue} from a series of {@link GaugeMetricValue}s. The * resulting value will be a summarization of each individual value. * * @param range The range which represents the aggregated value */ public GaugeMetricValue fromValues(TimeRange range, Collection<GaugeMetricValue> values) { if (values.isEmpty()) { return new GaugeMetricValue(range); } HistogramAccumulator accum = makeHistoAccumulator(); Min min = new Min(); Max max = new Max(); Sum total = new Sum(); Sum n = new Sum(); Sum sumOfSquares = new Sum(); for (GaugeMetricValue v : values) { min.increment(v.getMin()); max.increment(v.getMax()); n.increment(v.getN()); total.increment(v.getSum()); sumOfSquares.increment(v.getSumOfSquares()); accum.add(v.getHistogram()); } return new GaugeMetricValue(range, min.getResult(), max.getResult(), (long)n.getResult(), total.getResult(), sumOfSquares.getResult(), accum.getSparseHistogram()); }
public double getValueAtPercentile(GaugeMetricValue value, int p) { SparseHistogram histo = value.getHistogram(); int binNo = histo.getBinAfterPercentile(p); if (binNo == -1) { return Double.NaN; } return INSIGHT_HISTO.getBinDefinition(binNo).getStart(); }
public Histogram build() { SparseHistogram sparseMetric=metricValue.getHistogram(); Histogram metricHistogram=sparseMetric.getFullHistogram(definition); List<Bin> rawBins = growTo(metricHistogram.getBins(), end, binsCount); List<Bin> histBins = new ArrayList<Bin>(); int binCount = this.binsCount; // force start and end to bin boundaries double startHistory = definition.getBinDefinition(definition.getBinForValue(this.start)).getStart(); double endHistory = definition.getBinDefinition(definition.getBinForValue(this.end)).getEnd(); if (lowOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, Double.NEGATIVE_INFINITY, startHistory)).getCount(), Double.NEGATIVE_INFINITY, startHistory)); } if (highOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, endHistory, Double.POSITIVE_INFINITY)).getCount(), endHistory, Double.POSITIVE_INFINITY)); } histBins.addAll(toSize(collect(rawBins, startHistory, endHistory), binCount)); Collections.sort(histBins); return new Histogram(histBins); }
@Override public int hashCode() { int result=MathUtil.hashValue(sumOfSquares); result = 31 * result + MathUtil.hashValue(min); result = 31 * result + MathUtil.hashValue(max); result = 31 * result + MathUtil.hashValue(n); result = 31 * result + MathUtil.hashValue(sum); result = 31 * result + ObjectUtil.hashCode(getRange()); result = 31 * result + ObjectUtil.hashCode(getHistogram()); return result; }
public MetricValue getMetricValue() { return new GaugeMetricValue(range, min, max, n, sum, sumOfSquares, histo.getSparseHistogram()); }
public void fromData(DataInput dataInput) throws IOException { super.fromData(serialVersionUID, dataInput); int numSlots = dataInput.readInt(); GaugeMetricValue[] slots = new GaugeMetricValue[numSlots]; int usedSlots = dataInput.readInt(); for (int i=0; i<usedSlots; i++) { int slotIdx = dataInput.readInt(); double min = dataInput.readDouble(); double max = dataInput.readDouble(); long n = dataInput.readLong(); double sum = dataInput.readDouble(); double sumOfSquares = dataInput.readDouble(); long rangeStart = dataInput.readLong(); long rangeEnd = rangeStart + getEntryGranularity().getNanos(); int numBins = dataInput.readInt(); List<IndexedBin> bins = new ArrayList<IndexedBin>(numBins); for (int b=0; b<numBins; b++) { bins.add(new IndexedBin(dataInput.readInt(), dataInput.readLong())); } slots[slotIdx] = new GaugeMetricValue(TimeRange.nanoTimeRange(rangeStart, rangeEnd), min, max, n, sum, sumOfSquares, new SparseHistogram(InsightGaugeHistogramDefinition.getInstance(), bins)); } this.slots = Arrays.asList(slots); }
public GaugeMetricValue build() { return new GaugeMetricValue(valueRange, stats.getMin(), stats.getMax(), stats.getN(), Double.isNaN(stats.getSum()) ? 0.0 : stats.getSum(), Double.isNaN(stats.getSumsq()) ? 0.0 : stats.getSumsq(), accum.getSparseHistogram()); } }
public static UpdateMetricDistributionCommand getUpdateGauge() { ResourceMetricKey key = ResourceMetricKey.valueOf(getServerResourceCommand("butter", "butter-label").getResource().getKey(), Metrics.ENDPOINT_RESPONSE_TIME); IndexedBin bin1 = new IndexedBin(1, 4); IndexedBin bin2 = new IndexedBin(2, 6); SparseHistogram histo = new SparseHistogram(InsightGaugeHistogramDefinition.getInstance(), Arrays.asList(bin1, bin2)); GaugeMetricValue gauge = new GaugeMetricValue(TimeRange.range(0, 56), 34, 80, 40, 400, 600,histo); return new UpdateMetricDistributionCommand(key, gauge); }