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

项目:replicator    文件:ReplicatorDoctorTest.java   
@Test
public void makeSureTheDocSaysWeAreNotFineIfTheCountersDontChangeBetweenTwoSamples() throws Exception {

    Counting externalWorkCounter = mock(Counting.class);
    Counting interestingEventsObservedCounter = mock(Counting.class);

    when(externalWorkCounter.getCount()).thenReturn((long)0).thenReturn((long)500).thenReturn((long) 500);
    when(interestingEventsObservedCounter.getCount()).thenReturn((long)0).thenReturn((long)500).thenReturn((long)1500);

    ReplicatorDoctor doc = new ReplicatorDoctor(externalWorkCounter, "", mock(Logger.class), interestingEventsObservedCounter);

    // first reading is always OK, because there is no data for comparison
    assertTrue(doc.makeHealthAssessment().isOk());

    assertTrue(doc.makeHealthAssessment().isOk());
    assertFalse(doc.makeHealthAssessment().isOk());
}
项目:replicator    文件:ReplicatorDoctorTest.java   
@Test
public void makeSureTheDocSaysWeAreFineIfWeHaventSeenAnythingInterestingAndHaventPushedNothingOutsideBetweenTwoSamples() throws Exception {

    Counting externalWorkCounter = mock(Counting.class);
    Counting interestingEventsObservedCounter = mock(Counting.class);

    when(externalWorkCounter.getCount()).thenReturn((long) 0).thenReturn((long)500).thenReturn((long) 500);
    when(interestingEventsObservedCounter.getCount()).thenReturn((long)0).thenReturn((long)500).thenReturn((long)500);

    ReplicatorDoctor doc = new ReplicatorDoctor(externalWorkCounter, "", mock(Logger.class), interestingEventsObservedCounter);

    // first reading is always OK, because there is no data for comparison
    assertTrue(doc.makeHealthAssessment().isOk());

    assertTrue(doc.makeHealthAssessment().isOk());
    assertTrue(doc.makeHealthAssessment().isOk());
}
项目:ibole-microservice    文件:DropwizardMetricRegistry.java   
/**
 * Creates a {@link DropwizardMetricRegistry} with an {@link Slf4jReporter}.  Only non-zero metrics
 * will be logged to the {@link Slf4jReporter}.
 * 
 * @param registry The registry on which to add the reporter.
 * @param logger The {@link Logger} to report to
 * @param period the amount of time between polls
 * @param unit   the unit for {@code period}
 */
public static void createSlf4jReporter(DropwizardMetricRegistry registry, Logger logger,
    long period, TimeUnit unit) {
  MetricFilter nonZeroMatcher =
      new MetricFilter() {
        @Override
        public boolean matches(String name, Metric metric) {
          if (metric instanceof Counting) {
            Counting counter = (Counting) metric;
            return counter.getCount() > 0;
          }
          return true;
        }
      };
  Slf4jReporter.forRegistry(registry.getRegistry())
      .outputTo(logger)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .filter(nonZeroMatcher)
      .build()
      .start(period, unit);
}
项目:metrics-cloudwatch    文件:CloudWatchReporter.java   
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);
        }
    }));
}
项目:JInsight    文件:CountTracker.java   
private void register(Object[] tagValues,
    Function<TagEncodedMetricName, Counting> countingSupplier) {
  String key = getKey(tagValues);
  Map<String, String> tagMap = new HashMap<>(tagValues.length);
  for (int i = 0; i < tags.length; i++) {
    tagMap.put(tags[i], String.valueOf(tagValues[i]));
  }
  counters.put(key, countingSupplier.apply(rootMetric.withTags(tagMap)));
}
项目:anodot-metrics-bridge    文件:Anodot3NonZeroFilter.java   
@Override
public boolean matches(MetricName metricName, Metric metric) {
    if (metric instanceof Gauge) {
        final Object value = ((Gauge) metric).getValue();
        // Java, I hate you :(
        if (value instanceof Long) return (Long) value != 0;
        if (value instanceof Integer) return (Integer) value != 0;
        if (value instanceof Float) return (Float) value != 0;
        if (value instanceof Double) return (Double) value != 0;
        else return true;
    } else if (metric instanceof Counting) {
        return ((Counting)metric).getCount() != 0;
    }
    return false;
}
项目:semantic-metrics    文件:FastForwardReporter.java   
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()));
}
项目:codahale-aggregated-metrics-cloudwatch-reporter    文件:CloudWatchReporter.java   
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;
    }

    // Only submit metrics that have changed - let's save some money!
    final long delta = currentCount - lastCount;
    stageMetricDatum(true, metricName, delta, StandardUnit.Count, DIMENSION_COUNT, metricData);
}
项目:replicator    文件:ReplicatorDoctor.java   
/**
 * @param eventsPushedToWorldCounter - the counter which helps measure the work the Replicator pushes to the outside world
 * @param counterDescription - counterDescription
 * @param logger - logger
 * @param interestingEventsObservedCounter - the counter which shows how many interesting events the Replicator has observed (the # of events
 *                                          that have reached the Applier) in the databases being monitored
 */
public ReplicatorDoctor(
        Counting eventsPushedToWorldCounter,
        String counterDescription,
        Logger logger,
        Counting interestingEventsObservedCounter)
{
    if (eventsPushedToWorldCounter == null)
    {
        throw new IllegalArgumentException("eventsPushedToWorldCounter must be not null");
    }

    if (interestingEventsObservedCounter == null)
    {
        throw new IllegalArgumentException("interestingEventsObservedCounter must be not null");
    }

    if (logger == null)
    {
        throw new IllegalArgumentException("logger must be not null");
    }

    this.counterDescription = counterDescription;
    this.globallyImpactingEventsCounter = eventsPushedToWorldCounter;
    this.logger = logger;
    this.numberOfInterestingEventsObserved = interestingEventsObservedCounter;
}
项目:replicator    文件:ReplicatorDoctorTest.java   
@Test
public void makeSureTheDocSaysWeAreFineIfTheCountersChangeBetweenTwoSamples() throws Exception {
    Counting externalWorkCounter = mock(Counting.class);
    Counting interestingEventsObservedCounter = mock(Counting.class);

    when(externalWorkCounter.getCount()).thenReturn((long) 0).thenReturn((long)500);
    when(interestingEventsObservedCounter.getCount()).thenReturn((long)500).thenReturn((long)1500);

    ReplicatorDoctor doc = new ReplicatorDoctor(externalWorkCounter, "", mock(Logger.class), interestingEventsObservedCounter);

    assertTrue(doc.makeHealthAssessment().isOk());
    assertTrue(doc.makeHealthAssessment().isOk());
}
项目:dropwizard-metrics-influxdb    文件:InfluxDbReporter.java   
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;
}
项目: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;
}
项目:metrics-influxdb    文件:ReporterV08.java   
/**
 * Returns true if this metric is idle and should be skipped.
 *
 * @param name
 * @param counting
 * @return true if the metric should be skipped
 */
protected boolean canSkipMetric(String name, Counting counting) {
    boolean isIdle = calculateDelta(name, counting.getCount()) == 0L;
    if (skipIdleMetrics && !isIdle) {
        previousValues.put(name, counting.getCount());
    }
    return skipIdleMetrics && isIdle;
}
项目: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();
}
项目:metrics-cloudwatch    文件:CloudWatchReporter.java   
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;
}
项目:semantic-metrics    文件:FastForwardHttpReporter.java   
private void reportCounter(
    final BatchBuilder builder, final Counting value
) {
    builder.buildPoint("count", value.getCount());
}
项目:HeliosStreams    文件:MetricType.java   
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.jmx.metrics.MetricType.AttributeAdapter#invoke(com.codahale.metrics.Metric)
 */
@Override
public Object invoke(final Metric metric) {
    return ((Counting)metric).getCount();
}
项目:HeliosStreams    文件:MetricType.java   
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.jmx.metrics.MetricType.AttributeAdapter#invoke(com.codahale.metrics.Metric)
 */
@Override
public Object invoke(final Metric metric) {
    return ((Counting)metric).getCount();
}
项目:HeliosStreams    文件:MetricType.java   
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.jmx.metrics.MetricType.AttributeAdapter#invoke(com.codahale.metrics.Metric)
 */
@Override
public Object invoke(final Metric metric) {
    return ((Counting)metric).getCount();
}
项目:hawkular-dropwizard-reporter    文件:MetricsDecomposer.java   
Stream<MetricPart<Counting, Long>> countings() {
    return COUNTINGS.stream()
            .filter(metricPart -> metricPredicate.test(metricPart.getSuffix()));
}
项目:parfait    文件:CountingAdapter.java   
public CountingAdapter(Counting counter, String name, String description, ValueSemantics valueSemantics) {
    this.counter = counter;
    this.monitoredValue = new NonSelfRegisteringSettableValue<>(name, description, ONE, counter.getCount(), valueSemantics);
}
项目:search    文件:MorphlineMapper.java   
private void addCounting(String metricName, Counting value, long scale) {
  context.getCounter("morphline", metricName).increment(value.getCount() / scale);
}
项目: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();
}
项目:modules    文件:MetricDtoToSupplierConverter.java   
/**
 * Returns the appropriate function depending on configuration sent from the user interface.
 *
 * @param dto an object describing the type of function to create
 * @return a function that yields a number
 */
public Supplier<Number> convert(MetricDto dto) {
    Metric metric = getMetric(dto);
    Supplier<Number> ret = null;

    switch (dto.getValue()) {
        case COUNT:
            ret = new Supplier<Number>() {
                @Override
                public Long get() {
                    return ((Counting) metric).getCount();
                }
            };
            break;
        case MEAN:
            ret = new Supplier<Number>() {
                @Override
                public Double get() {
                    return ((Metered) metric).getMeanRate();
                }
            };
            break;
        case ONE_MINUTE:
            ret = new Supplier<Number>() {
                @Override
                public Double get() {
                    return ((Metered) metric).getOneMinuteRate();
                }
            };
            break;
        case FIVE_MINUTE:
            ret = new Supplier<Number>() {
                @Override
                public Double get() {
                    return ((Metered) metric).getFiveMinuteRate();
                }
            };
            break;
        case FIFTEEN_MINUTE:
            ret = new Supplier<Number>() {
                @Override
                public Double get() {
                    return ((Metered) metric).getFifteenMinuteRate();
                }
            };
            break;
    }

    return ret;
}
项目:incubator-gobblin    文件:InfluxDBReporter.java   
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));
}
项目:incubator-gobblin    文件:GraphiteReporter.java   
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);
}
项目:hawkular-metrics    文件:MetricsDecomposer.java   
Stream<MetricPart<Counting, Long>> countings() {
    return COUNTINGS.stream()
            .filter(metricPart -> metricPredicate.test(metricPart.getSuffix()));
}
项目:read-open-source-code    文件:MorphlineMapper.java   
private void addCounting(String metricName, Counting value, long scale) {
  context.getCounter("morphline", metricName).increment(value.getCount() / scale);
}
项目:hbase-indexer    文件:HBaseIndexerMapper.java   
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);
}
项目:Gobblin    文件:MetricReportReporter.java   
/**
 * 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 gobblin.metrics.Metric}.
 */
protected List<Metric> serializeCounter(String name, Counting counter) {
  return Lists.newArrayList(
      serializeValue(name, counter.getCount(), Measurements.COUNT.name())
  );
}
项目:incubator-gobblin    文件:MetricReportReporter.java   
/**
 * 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())
  );
}