com.codahale.metrics.Counting Java Examples

The following examples show how to use com.codahale.metrics.Counting. 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 codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
private void processCounter(final String metricName, final Counting counter, final List<MetricDatum> metricData) {
    long currentCount = counter.getCount();
    Long lastCount = lastPolledCounts.get(counter);
    lastPolledCounts.put(counter, currentCount);

    if (lastCount == null) {
        lastCount = 0L;
    }

    final long reportValue;
    if (builder.withReportRawCountValue) {
        reportValue = currentCount;
    } else {
        // Only submit metrics that have changed - let's save some money!
        reportValue = currentCount - lastCount;
    }

    stageMetricDatum(true, metricName, reportValue, StandardUnit.COUNT, DIMENSION_COUNT, metricData);
}
 
Example #2
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 6 votes vote down vote up
void reportCounter(Map.Entry<String, ? extends Counting> entry, String typeDimValue, List<MetricDatum> data) {
    Counting metric = entry.getValue();
    final long diff = diffLast(metric);
    if (diff == 0) {
        // Don't submit metrics that have not changed. No reason to keep these alive. Also saves on CloudWatch
        // costs.
        return;
    }

    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.withValue((double) diff).withUnit(StandardUnit.Count);
        }
    }));
}
 
Example #3
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 #4
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 #5
Source File: ResponseCodeSupplier.java    From styx with Apache License 2.0 5 votes vote down vote up
private void updateFromMetrics(Map<String, ? extends Counting> metrics) {
    metrics.forEach((key, metric) -> {
        long count = metric.getCount();

        onMetricCount(key, (int) count);
    });
}
 
Example #6
Source File: MetricsSupport.java    From styx with Apache License 2.0 5 votes vote down vote up
private Set<String> updatedMetrics(MetricRegistry registry) {
    Map<String, Meter> meterMap = registry.getMeters((name, metric) -> {
        if (!excludedNames.contains(name)) {
            if (metric instanceof Counting) {
                return ((Counting) metric).getCount() != 0;
            }
        }
        return false;
    });
    return meterMap.keySet();
}
 
Example #7
Source File: FastForwardReporter.java    From semantic-metrics with Apache License 2.0 5 votes vote down vote up
private void reportCounter(MetricId key, Counting value) {
    key = MetricId.join(prefix, key);

    final Metric m = FastForward
        .metric(key.getKey())
        .attributes(key.getTags())
        .attribute(METRIC_TYPE, "counter");

    send(m.value(value.getCount()));
}
 
Example #8
Source File: InfluxDbReporter.java    From dropwizard-metrics-influxdb with Apache License 2.0 5 votes vote down vote up
private boolean canSkipMetric(String name, Counting counting) {
    boolean isIdle = (calculateDelta(name, counting.getCount()) == 0);
    if (skipIdleMetrics && !isIdle) {
        previousValues.put(name, counting.getCount());
    }
    return skipIdleMetrics && isIdle;
}
 
Example #9
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 #10
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 5 votes vote down vote up
private long diffLast(Counting metric) {
    long count = metric.getCount();

    Long lastCount = lastPolledCounts.get(metric);
    lastPolledCounts.put(metric, count);

    if (lastCount == null) {
        lastCount = 0L;
    }
    return count - lastCount;
}
 
Example #11
Source File: FastForwardHttpReporter.java    From semantic-metrics with Apache License 2.0 4 votes vote down vote up
private void reportCounter(
    final BatchBuilder builder, final Counting value
) {
    builder.buildPoint("count", value.getCount());
}
 
Example #12
Source File: InfluxDBReporter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private void reportCounter(List<Point> points, String prefix, String name, Counting counter, long timestamp)
    throws IOException {
  String metricName = getKey(prefix, name, COUNT.getName());
  points.add(buildMetricAsPoint(metricName, counter.getCount(), false, timestamp));
}
 
Example #13
Source File: GraphiteReporter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private void reportCounter(String prefix, String name, Counting counter, long timestamp) throws IOException {
  String metricName = getKey(prefix, name, COUNT.getName());
  pushMetric(metricName, counter.getCount(), false, timestamp);
}
 
Example #14
Source File: MorphlineMapper.java    From examples with Apache License 2.0 4 votes vote down vote up
private void addCounting(String metricName, Counting value, long scale) {
  context.getCounter("morphline", metricName).increment(value.getCount() / scale);
}
 
Example #15
Source File: HBaseIndexerMapper.java    From hbase-indexer with Apache License 2.0 4 votes vote down vote up
private void addCounting(Context context, String metricName, Counting value, long scale) {
    final String COUNTER_GROUP = "HBase Indexer Metrics";
    context.getCounter(COUNTER_GROUP, metricName).increment(value.getCount() / scale);
}
 
Example #16
Source File: MetricReportReporter.java    From incubator-gobblin with Apache License 2.0 2 votes vote down vote up
/**
 * Extracts metrics from {@link com.codahale.metrics.Counter}.
 *
 * @param name name of the {@link com.codahale.metrics.Counter}.
 * @param counter instance of {@link com.codahale.metrics.Counter} to serialize.
 * @return a list of {@link org.apache.gobblin.metrics.Metric}.
 */
protected List<Metric> serializeCounter(String name, Counting counter) {
  return Lists.newArrayList(
      serializeValue(name, counter.getCount(), Measurements.COUNT.name())
  );
}