Java 类com.codahale.metrics.Sampling 实例源码

项目:metrics-cloudwatch    文件:CloudWatchReporter.java   
/**
 * @param rescale the submitted sum by this multiplier. 1.0 is the identity (no rescale).
 */
void reportSampling(Map.Entry<String, ? extends Sampling> entry, String typeDimValue, double rescale, List<MetricDatum> data) {
    Sampling metric = entry.getValue();
    Snapshot snapshot = metric.getSnapshot();
    double scaledSum = sum(snapshot.getValues()) * rescale;
    final StatisticSet statisticSet = new StatisticSet()
            .withSum(scaledSum)
            .withSampleCount((double) snapshot.size())
            .withMinimum((double) snapshot.getMin() * rescale)
            .withMaximum((double) snapshot.getMax() * rescale);

    DemuxedKey key = new DemuxedKey(appendGlobalDimensions(entry.getKey()));
    Iterables.addAll(data, key.newDatums(typeDimName, typeDimValue, new Function<MetricDatum, MetricDatum>() {
        @Override
        public MetricDatum apply(MetricDatum datum) {
            return datum.withStatisticValues(statisticSet);
        }
    }));
}
项目:HeliosStreams    文件:MetricType.java   
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.jmx.metrics.MetricType.AttributeAdapter#invoke(com.codahale.metrics.Metric)
 */
@Override
public Object invoke(final Metric metric) {
    final Sampling s = (Sampling)metric;
    switch(this) {
    case MAX:
        return s.getSnapshot().getMax();
    case MEAN:
        return s.getSnapshot().getMean();
    case MEDIAN:
        return s.getSnapshot().getMedian();
    case MIN:
        return s.getSnapshot().getMin();
    case PCT75:
        return s.getSnapshot().get75thPercentile();
    case PCT95:
        return s.getSnapshot().get95thPercentile();
    case PCT98:
        return s.getSnapshot().get98thPercentile();
    case PCT99:
        return s.getSnapshot().get99thPercentile();
    case PCT999:
        return s.getSnapshot().get999thPercentile();
    case STDDEV:
        return s.getSnapshot().getStdDev();         
    }
    return null;
}
项目:parfait    文件:SamplingAdapter.java   
public SamplingAdapter(Sampling samplingMetric, String name, String description, Unit<?> unit) {
    this.samplingMetric = samplingMetric;
    Snapshot snapshot = samplingMetric.getSnapshot();
    this.mean = new NonSelfRegisteringSettableValue<>(name(name, "mean"), description + " - Mean", unit, snapshot.getMean(), ValueSemantics.FREE_RUNNING);
    this.seventyFifthPercentile = new NonSelfRegisteringSettableValue<>(name(name, "seventyfifth"), description + " - 75th Percentile of recent data", unit, snapshot.get75thPercentile(), ValueSemantics.FREE_RUNNING);
    this.ninetyFifthPercentile = new NonSelfRegisteringSettableValue<>(name(name, "ninetyfifth"), description + " - 95th Percentile of recent data", unit, snapshot.get95thPercentile(), ValueSemantics.FREE_RUNNING);
    this.ninetyEighthPercentile = new NonSelfRegisteringSettableValue<>(name(name, "ninetyeighth"), description + " - 98th Percentile of recent data", unit, snapshot.get98thPercentile(), ValueSemantics.FREE_RUNNING);
    this.ninetyNinthPercentile = new NonSelfRegisteringSettableValue<>(name(name, "ninetynineth"), description + " - 99th Percentile of recent data", unit, snapshot.get99thPercentile(), ValueSemantics.FREE_RUNNING);
    this.threeNinesPercentile = new NonSelfRegisteringSettableValue<>(name(name, "threenines"), description + " - 99.9th Percentile of recent data", unit, snapshot.get999thPercentile(), ValueSemantics.FREE_RUNNING);

    this.median = new NonSelfRegisteringSettableValue<>(name(name, "median"), description + " - Median", unit, snapshot.getMedian(), ValueSemantics.FREE_RUNNING);
    this.max = new NonSelfRegisteringSettableValue<>(name(name, "max"), description + " - Maximum", unit, snapshot.getMax(), ValueSemantics.MONOTONICALLY_INCREASING);
    this.min = new NonSelfRegisteringSettableValue<>(name(name, "min"), description + " - Minimum", unit, snapshot.getMin(), ValueSemantics.FREE_RUNNING);
    this.stddev = new NonSelfRegisteringSettableValue<>(name(name, "stddev"), description + " - Standard Deviation", unit, snapshot.getStdDev(), ValueSemantics.FREE_RUNNING);
}
项目:oap    文件:Metrics.java   
private static Snapshot toSnapshot( String name, Metric value ) {
    Snapshot snapshot = new Snapshot( name );
    if( value instanceof Sampling )
        snapshot.mean = ( ( Sampling ) value ).getSnapshot().getMean();
    if( value instanceof Metered )
        snapshot.meanRate = ( ( Metered ) value ).getMeanRate();
    if( value instanceof Counting )
        snapshot.count = ( ( Counting ) value ).getCount();
    if( value instanceof Gauge )
        snapshot.count = ( ( Number ) ( ( Gauge ) value ).getValue() ).longValue();
    return snapshot;
}
项目:stdlib    文件:MetricsRestServiceImpl.java   
@Override
public String getIndex()
{
    TemplateCall call = templater.template(PREFIX + "index.html");

    call.set("gauges", registry.getGauges().entrySet());
    call.set("counters", this.<Counting>combine(registry.getCounters(),
                                                registry.getMeters(),
                                                registry.getTimers(),
                                                registry.getHistograms()).entrySet());
    call.set("meters", this.<Metered>combine(registry.getMeters(), registry.getTimers()).entrySet());
    call.set("histograms", this.<Sampling>combine(registry.getHistograms(), registry.getTimers()).entrySet());

    return call.process();
}
项目:HeliosStreams    文件:MetricAttributeHandler.java   
SnapshotAttributeGetter(final Sampling target, final String methodName) {
    this.target = target.getSnapshot();
    method = PrivateAccessor.findMethodFromClass(Snapshot.class, methodName);
}
项目:HeliosStreams    文件:MetricAttributeHandler.java   
@Override
public NVP<Metric, MBeanAttributeInfo[]> minfo(final Metric metric) {
    return new NVP<Metric, MBeanAttributeInfo[]>(metric, new MBeanAttributeInfo[]{
        new MBeanAttributeInfo("HistogramCount", "long", "The number of values that have been recorded", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getCount"))
                .fput("metricType", new AttributeGetter(metric, "counter"))
            )),
        new MBeanAttributeInfo("75thPct", "double", "The value at the 75th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get75thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("95thPct", "double", "The value at the 95th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get95thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("98thPct", "double", "The value at the 98th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get98thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("99thPct", "double", "The value at the 99th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get99thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("999thPct", "double", "The value at the 99.9th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get999thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("HistogramMax", "double", "The highest value in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMax"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("HistogramMin", "double", "The lowest value in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMin"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("HistogramMean", "double", "The arithmetic mean of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMean"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("HistogramMedian", "double", "The median of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMedian"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("HistogramStdDev", "double", "The standard deviation of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Histogram.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getStdDev"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            ))
    });
}
项目:HeliosStreams    文件:MetricAttributeHandler.java   
@Override
public NVP<Metric, MBeanAttributeInfo[]> minfo(final Metric metric) {
    return new NVP<Metric, MBeanAttributeInfo[]>(metric, new MBeanAttributeInfo[]{
        new MBeanAttributeInfo("TimerCount", "long", "The number of events that have been marked", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getCount"))
                .fput("metricType", new AttributeGetter(metric, "counter"))
            )),
        new MBeanAttributeInfo("TimerRate15m", "double", "The fifteen-minute exponentially-weighted moving average rate at which events have occurred since the meter was created", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Meter.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getFifteenMinuteRate"))
                .fput("metricType", "gauge")
            )),
        new MBeanAttributeInfo("TimerRate5m", "double", "The five-minute exponentially-weighted moving average rate at which events have occurred since the meter was created", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Meter.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getFiveMinuteRate"))
                .fput("metricType", "gauge")
            )),
        new MBeanAttributeInfo("TimerRate1m", "double", "The one-minute exponentially-weighted moving average rate at which events have occurred since the meter was created", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Meter.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getOneMinuteRate"))
                .fput("metricType", "gauge")
            )),
        new MBeanAttributeInfo("TimerMeanRate", "double", "The mean rate at which events have occurred since the meter was created", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Meter.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMeanRate"))
                .fput("metricType", "gauge")
            )),

        new MBeanAttributeInfo("Timer75thPct", "double", "The value at the 75th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get75thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("Timer95thPct", "double", "The value at the 95th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get95thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("Timer98thPct", "double", "The value at the 98th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get98thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("Timer99thPct", "double", "The value at the 99th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get99thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("Timer999thPct", "double", "The value at the 99.9th percentile in the distribution.", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "get999thPercentile"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("TimerMax", "double", "The highest value in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMax"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("TimerMin", "double", "The lowest value in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMin"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("TimerMean", "double", "The arithmetic mean of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMean"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("TimerMedian", "double", "The median of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getMedian"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            )),
        new MBeanAttributeInfo("TimerStdDev", "double", "The standard deviation of values in the snapshot", true, false, false, new ImmutableDescriptor(FluentMap.newMap(String.class, Object.class)
                .fput("metricClass", com.codahale.metrics.Timer.class.getName())
                .fput("invoker", new AttributeGetter(metric, "getStdDev"))
                .fput("metricType", new SnapshotAttributeGetter((Sampling)metric, "gauge"))
            ))
    });
}
项目:hawkular-dropwizard-reporter    文件:MetricsDecomposer.java   
Stream<MetricPart<Sampling, Object>> samplings() {
    return SAMPLING.stream()
            .filter(metricPart -> metricPredicate.test(metricPart.getSuffix()));
}
项目:haven-platform    文件:LimitCheckers.java   
public static Builder<Sampling> whenMaxValueGreaterThan(final long value) {
    return LimitCheckers.<Sampling>builder().limit(new MaxSnapshotValue(new GreaterThan<>(value)));
}
项目:haven-platform    文件:LimitCheckers.java   
@Override
Long getMetric(Sampling metric) {
    return metric.getSnapshot().getMax();
}
项目:parfait    文件:SamplingAdapter.java   
public SamplingAdapter(Sampling samplingMetric, String name, String description) {
    this(samplingMetric, name, description, ONE);
}
项目:armeria    文件:DropwizardMetricsIntegrationTest.java   
private static void assertSummary(Map<String, ?> map, String property, int expectedCount) {
    assertThat(((Counting) map.get(clientMetricName(property))).getCount()).isEqualTo(expectedCount);
    assertThat(((Sampling) map.get(clientMetricName(property))).getSnapshot().getMean()).isPositive();
    assertThat(((Counting) map.get(serverMetricName(property))).getCount()).isEqualTo(expectedCount);
    assertThat(((Sampling) map.get(serverMetricName(property))).getSnapshot().getMean()).isPositive();
}
项目:hawkular-metrics    文件:MetricsDecomposer.java   
Stream<MetricPart<Sampling, Object>> samplings() {
    return SAMPLING.stream()
            .filter(metricPart -> metricPredicate.test(metricPart.getSuffix()));
}
项目:signalfx-java    文件:AggregateMetricSenderSessionWrapper.java   
private void addSampling(String baseName, Sampling sampling) {
    Metric metric = (Metric)sampling;
    final Snapshot snapshot = sampling.getSnapshot();
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.MEDIAN,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMedian());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.PERCENT_75,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get75thPercentile());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.PERCENT_95,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get95thPercentile());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.PERCENT_98,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get98thPercentile());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.PERCENT_99,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get99thPercentile());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.PERCENT_999,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get999thPercentile());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.MAX,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMax());
    addMetric(metric, baseName,
            SignalFxReporter.MetricDetails.MIN,
            SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMin());


    // These are slower to calculate.  Only calculate if we need.
    if (detailsToAdd.contains(SignalFxReporter.MetricDetails.STD_DEV)) {
        addMetric(metric, baseName,
                SignalFxReporter.MetricDetails.STD_DEV,
                SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getStdDev());
    }
    if (detailsToAdd.contains(SignalFxReporter.MetricDetails.MEAN)) {
        addMetric(metric, baseName,
                SignalFxReporter.MetricDetails.MEAN,
                SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMean());
    }
}