com.codahale.metrics.Sampling Java Examples

The following examples show how to use com.codahale.metrics.Sampling. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 6 votes vote down vote up
/**
 * @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);
        }
    }));
}
 
Example #2
Source File: CassandraMetricsUtilities.java    From cassandra-exporter with Apache License 2.0 5 votes vote down vote up
static <X extends Sampling & Counting> SamplingCounting adaptSamplingCounting(final X metric) {
    return new SamplingCounting() {
        @Override
        public long getCount() {
            return metric.getCount();
        }

        @Override
        public Iterable<Interval> getIntervals() {
            final Snapshot snapshot = metric.getSnapshot();

            return Interval.asIntervals(Interval.Quantile.STANDARD_PERCENTILES, q -> (float) snapshot.getValue(q.value));
        }
    };
}
 
Example #3
Source File: CassandraMetricsUtilities.java    From cassandra-exporter with Apache License 2.0 5 votes vote down vote up
/**
 * Timers and Histograms can be optimised if access to the "raw" {@link com.codahale.metrics.Metric} is available (in-process only).
 * This function tries to access the given {@link NamedObject}'s raw Metric, and adapt it to a {@link SamplingCounting}, failing back to adapting
 * the JMX proxy object to a {@link SamplingCounting}.
 */
private static <RawT extends Sampling & Counting, MBeanT> NamedObject<SamplingCounting> mBeanAsSamplingCounting(final NamedObject<?> mBean, final Function<MBeanT, SamplingCounting> mBeanAdapterFunction) {
    try {
        return CassandraMetricsUtilities.<RawT>metricForMBean(mBean).map((n, o) -> adaptSamplingCounting(o));

    } catch (final Exception e) {
        return mBean.<MBeanT>cast().map((n, o) -> mBeanAdapterFunction.apply(o));
    }
}
 
Example #4
Source File: DropwizardMetricsIntegrationTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static void assertSummary(Map<String, ?> map, String property, int expectedCount) {
    assertThat(((Counting) map.get(clientMetricNameWithStatus(property, 200))).getCount())
            .isEqualTo(expectedCount);
    assertThat(((Sampling) map.get(clientMetricNameWithStatus(property, 200))).getSnapshot().getMean())
            .isPositive();
    assertThat(((Counting) map.get(serverMetricNameWithStatus(property, 200))).getCount())
            .isEqualTo(expectedCount);
    assertThat(((Sampling) map.get(serverMetricNameWithStatus(property, 200))).getSnapshot().getMean())
            .isPositive();
}
 
Example #5
Source File: LimitCheckers.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
public static Builder<Sampling> whenMaxValueGreaterThan(final long value) {
    return LimitCheckers.<Sampling>builder().limit(new MaxSnapshotValue(new GreaterThan<>(value)));
}
 
Example #6
Source File: LimitCheckers.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
@Override
Long getMetric(Sampling metric) {
    return metric.getSnapshot().getMax();
}
 
Example #7
Source File: AggregateMetricSenderSessionWrapper.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
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());
    }
}