當前位置: 首頁>>代碼示例>>Java>>正文


Java Histogram.update方法代碼示例

本文整理匯總了Java中com.codahale.metrics.Histogram.update方法的典型用法代碼示例。如果您正苦於以下問題:Java Histogram.update方法的具體用法?Java Histogram.update怎麽用?Java Histogram.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.codahale.metrics.Histogram的用法示例。


在下文中一共展示了Histogram.update方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: interceptCall

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
/**
 * Intercept all GRPC calls
 * @param serverCall
 * @param metadata
 * @param serverCallHandler
 * @param <ReqT>
 * @param <RespT>
 * @return
 */
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {

    Timer.Context timer = metricRegistry.timer(metricName(M_REQ_TIME, serverCall.getMethodDescriptor().getFullMethodName().replace("/", "."))).time();
    Histogram histogram = metricRegistry.histogram(metricName(M_RESPONSE_SIZE, serverCall.getMethodDescriptor().getFullMethodName().replace("/", ".")));

    SimpleForwardingServerCall<ReqT, RespT> nextCall = new SimpleForwardingServerCall<ReqT, RespT>(serverCall) {
        @Override
        public void close(Status status, Metadata trailers) {
            Meter errorMeter = metricRegistry.meter(metricName(ERROR_METRIC, getMethodDescriptor().getFullMethodName().replace("/", ".")));
            if (!status.isOk()) {
                errorMeter.mark();
                log.error("An error occured with {}", serverCall.getMethodDescriptor());
            }

            timer.stop();

            super.close(status, trailers);
        }

        @Override
        public void sendMessage(RespT message) {
            super.sendMessage(message);

            if (message instanceof MessageLite) {
                histogram.update(((MessageLite) message).getSerializedSize());
                log.info("Message sent size = {}", ((MessageLite) message).getSerializedSize());
            }
        }

    };
    return serverCallHandler.startCall(nextCall, metadata);
}
 
開發者ID:husseincoder,項目名稱:dockerized-microservices,代碼行數:43,代碼來源:GrpcServerInterceptor.java

示例2: reportHistogram

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
/**
 * A histogram measures the statistical distribution of values in a stream of data. In addition
 * to minimum, maximum, mean, etc., it also measures median, 75th, 90th, 95th, 98th, 99th, and
 * 99.9th percentiles. This histogram will measure the size of responses in bytes.
 */
private static void reportHistogram() {
    // Create or fetch (if it is already created) the metric.
    final Histogram histogram = registry.histogram(
        APP_PREFIX.tagged("what", "response-size").tagged("endpoint", "/v1/content"));

    // fetch the size of the response
    final long responseSize = 1000;
    // obviously this is gonna keep reporting 1000, but you know ;)

    histogram.update(responseSize);

    // That's it! The rest will be automatically done inside semantic metrics library. The
    // reported measurements will be kept in the registry.
    // Every time the reporter wants to report, different stats and aggregations (min, max,
    // median, 75th, 90th, 95th, 98th, 99th, and 99.9th percentiles) will be calculated and
    // datapoints will be created and reported.
}
 
開發者ID:spotify,項目名稱:semantic-metrics,代碼行數:23,代碼來源:MetricTypesExample.java

示例3: main

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    FastForwardReporter f = FastForwardReporter
        .forRegistry(registry)
        .histogramQuantiles(0.62, 0.55, 0.99)
        .schedule(TimeUnit.SECONDS, 10)
        .build();
    f.start();

    Histogram h = registry.histogram(APP_PREFIX.tagged("what", "stuff"));

    for (int i = 0; i < 100; i++) {
        h.update(i);
    }

    System.out.println("Sending custom percentiles for histogram...");
    System.in.read();
    f.stop();
}
 
開發者ID:spotify,項目名稱:semantic-metrics,代碼行數:19,代碼來源:CustomPercentiles.java

示例4: updateMetrics

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
private void updateMetrics(MetricsMessageCollection messageCollection) {
    List<MetricsMessage> messages = messageCollection.getMessages();
    for (MetricsMessage message : messages) {
        List<KeyValuePair> pairs = message.getHeaders();
        for (KeyValuePair pair : pairs) {
            String key = pair.getKey();
            for (KeyValuePair keyValuePair : message.getHeaders()) {
                Histogram histogram = metricsRegistry.histogram(HISTOGRAM + key);
                if (keyValuePair.getValueType() == ValueType.DECIMAL && keyValuePair.getDecimalValue()!= null) {
                    histogram.update(Long.valueOf(keyValuePair.getDecimalValue().intValue()));
                } else if (keyValuePair.getValueType() == ValueType.LONG && keyValuePair.getLongValue()!= null) {
                    histogram.update(keyValuePair.getLongValue());
                } else if (keyValuePair.getValueType() == ValueType.INTEGER && keyValuePair.getIntValue()!= null) {
                    histogram.update(keyValuePair.getIntValue());
                }
            }
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:20,代碼來源:JettyServletMetricsActor.java

示例5: testFromHistogram

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void testFromHistogram() {
  final Set<String> fieldKeys = ImmutableSet.of(
    "count",
    "min",
    "max",
    "mean",
    "std-dev",
    "50-percentile",
    "75-percentile",
    "95-percentile",
    "99-percentile",
    "999-percentile",
    "run-count"
  );

  final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
  final DropwizardTransformer transformer = transformerWithParser(parser, true);

  when(parser.parse("some.metric.name")).thenReturn(
    DropwizardMeasurement.create("Measurement", MEASUREMENT_TAGS, Optional.empty())
  );

  final Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
  histogram.update(15L);
  histogram.update(70L);
  histogram.update(100L);

  final InfluxDbMeasurement measurement = transformer.fromHistogram("some.metric.name", histogram, 90210L);
  assertEquals("should parse name from full metric key", "Measurement", measurement.name());
  assertEquals("should add global and measurement tags", ALL_TAGS, measurement.tags());
  assertEquals("should timestamp measurement", 90210L, measurement.timestamp());
  assertEquals("should add all histogram fields", fieldKeys, measurement.fields().keySet());
}
 
開發者ID:kickstarter,項目名稱:dropwizard-influxdb-reporter,代碼行數:35,代碼來源:DropwizardTransformerTest.java

示例6: run

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Override
public void run() {
  samplerLock.lock();
  try {
    for (Histogram histogram : schedulerHistogramList) {
      Timer timer = histogramTimerMap.get(histogram);
      histogram.update((int) timer.getSnapshot().getMean());
    }
  } finally {
    samplerLock.unlock();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:ResourceSchedulerWrapper.java

示例7: shouldReportHistogramSubsequentSnapshotValues_SumMaxMinValues

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void shouldReportHistogramSubsequentSnapshotValues_SumMaxMinValues() throws Exception {
    CloudWatchReporter reporter = reporterBuilder.withStatisticSet().build();

    final Histogram slidingWindowHistogram = new Histogram(new SlidingWindowReservoir(4));
    metricRegistry.register("SlidingWindowHistogram", slidingWindowHistogram);

    slidingWindowHistogram.update(1);
    slidingWindowHistogram.update(2);
    slidingWindowHistogram.update(30);
    reporter.report();

    final MetricDatum metricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);

    assertThat(metricData.getStatisticValues().getMaximum().intValue()).isEqualTo(30);
    assertThat(metricData.getStatisticValues().getMinimum().intValue()).isEqualTo(1);
    assertThat(metricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(3);
    assertThat(metricData.getStatisticValues().getSum().intValue()).isEqualTo(33);
    assertThat(metricData.getUnit()).isEqualTo(None.toString());

    slidingWindowHistogram.update(4);
    slidingWindowHistogram.update(100);
    slidingWindowHistogram.update(5);
    slidingWindowHistogram.update(6);
    reporter.report();

    final MetricDatum secondMetricData = metricDatumByDimensionFromCapturedRequest(DIMENSION_SNAPSHOT_SUMMARY);

    assertThat(secondMetricData.getStatisticValues().getMaximum().intValue()).isEqualTo(100);
    assertThat(secondMetricData.getStatisticValues().getMinimum().intValue()).isEqualTo(4);
    assertThat(secondMetricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(4);
    assertThat(secondMetricData.getStatisticValues().getSum().intValue()).isEqualTo(115);
    assertThat(secondMetricData.getUnit()).isEqualTo(None.toString());

}
 
開發者ID:azagniotov,項目名稱:codahale-aggregated-metrics-cloudwatch-reporter,代碼行數:36,代碼來源:CloudWatchReporterTest.java

示例8: HistogramResource

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Inject
public HistogramResource(
    Histogram unnamedHistogram,
    @Metric(name = "com.metric") Histogram metricHistogram,
    @Metric(name = "com.absoluteMetric", absolute = true) Histogram absoluteMetricHistogram
) {
    unnamedHistogram.update(123);
    metricHistogram.update(456);
    absoluteMetricHistogram.update(789);
}
 
開發者ID:baharclerode,項目名稱:dropwizard-hk2,代碼行數:11,代碼來源:HistogramFactoryTest.java

示例9: testExpansionFilterExclusion

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void testExpansionFilterExclusion() throws Exception {
    String json =
            "{" +
                    "\"type\": \"datadogExpansionFiltered\"," +
                    "\"host\": \"test-host\"," +
                    "\"excludeExpansions\": [\"min\", \"max\", \"p75\", \"p95\", \"p98\", \"p99\", \"p999\"]," +
                    "\"transport\": {" +
                    "\"type\": \"http\"," +
                    "\"apiKey\": \"12345\"" +
                    "}" +
                    "}";


    ScheduledReporter reporter = createReporter(json);

    // Create a representative type.
    Histogram histogram = _metricRegistry.histogram("test.histogram");
    histogram.update(1);
    histogram.update(2);
    histogram.update(3);

    reporter.report();

    // Verify only the desired metrics were sent.  Notably min, max, and the nth percentiles should be absent.
    verify(_request).addCounter(argThat(hasCounter("test.histogram.count", 3)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.mean", 2)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.median", 2)));
    verify(_request).addGauge(argThat(hasGauge("test.histogram.stddev", 1.0)));

    // Send was called exactly once
    verify(_request).send();

    verifyNoMoreInteractions(_request);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:36,代碼來源:DatadogMetricFilterTest.java

示例10: shouldReportPartialHistogram

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void shouldReportPartialHistogram() {
    HawkularReporter reporter = HawkularReporter.builder(registry, "unit-test")
            .setMetricComposition("my.histogram", Lists.newArrayList("mean", "median", "stddev"))
            .useHttpClient(uri -> client)
            .build();

    final Histogram histogram = registry.histogram("my.histogram");
    histogram.update(3);
    reporter.report();

    assertThat(client.getMetricsRestCalls()).hasSize(1);
    JSONObject metrics = new JSONObject(client.getMetricsRestCalls().get(0));
    assertThat(metrics.keySet()).containsOnly("gauges");

    JSONArray gaugesJson = metrics.getJSONArray("gauges");
    Map<String, Integer> values = StreamSupport.stream(gaugesJson.spliterator(), false)
            .collect(toMap(idFromRoot::extract, valueFromRoot::extract));
    // Note: we extract int values here for simplicity, but actual values are double. The goal is not to test
    // Dropwizard algorithm for metrics generation, so we don't bother with accuracy.
    assertThat(values).containsOnly(
            entry("my.histogram.mean", 3),
            entry("my.histogram.median", 3),
            entry("my.histogram.stddev", 0));

    assertThat(client.getTagsRestCalls()).containsOnly(
            Pair.of("/gauges/my.histogram.mean/tags", "{\"histogram\":\"mean\"}"),
            Pair.of("/gauges/my.histogram.stddev/tags", "{\"histogram\":\"stddev\"}"),
            Pair.of("/gauges/my.histogram.median/tags", "{\"histogram\":\"median\"}"));
}
 
開發者ID:hawkular,項目名稱:hawkular-dropwizard-reporter,代碼行數:31,代碼來源:HawkularReporterTest.java

示例11: doProcess

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Override
protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName) throws Exception {
    Message in = exchange.getIn();
    Histogram histogram = registry.histogram(metricsName);
    Long value = endpoint.getValue();
    Long finalValue = getLongHeader(in, HEADER_HISTOGRAM_VALUE, value);
    if (finalValue != null) {
        histogram.update(finalValue);
    } else {
        LOG.warn("Cannot update histogram \"{}\" with null value", metricsName);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:HistogramProducer.java

示例12: refreshStatus

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
public GameServer refreshStatus(GameServer server) {
    if (server == null) {
        return null;
    }

    Timer timer = getDelayTimer(server);
    Timer.Context context = timer.time();
    int delay;
    try {
        SourceServer source = gameQueryService.getServerInfo(getInetSocketAddress(server)).join();
        delay = Long.valueOf(nanosToMillis(context.stop())).intValue();

        String mapName = source.getMapName();
        int players = source.getNumOfPlayers();
        int max = source.getMaxPlayers();
        String versionString = source.getGameVersion();
        int tvPort = source.getTvPort();

        Histogram histogram = getPlayerHistogram(server);
        histogram.update(players);

        server.setStatusCheckDate(ZonedDateTime.now());
        server.setMap(mapName);
        server.setPlayers(players);
        server.setMaxPlayers(max);
        server.setVersion(checkedParseInt(versionString));
        server.setTvPort(tvPort);

        playerCountMap.put(server, players);
    } catch (Exception e) {
        if (e.getCause() instanceof ReadTimeoutException) {
            log.info("[{}] Status check timed out", server);
        } else {
            log.warn("[{}] Failed to refresh status: {}", server, e.toString());
        }
        delay = Long.valueOf(nanosToMillis(context.stop())).intValue();
    }

    server.setPing(delay);
    if (getStatusMonitor(server).check(delay) != Monitor.State.BAD) {
        server.setLastValidPing(ZonedDateTime.now());
    }
    // clear cached data if last valid ping was at least 30 minutes ago
    if (server.getLastValidPing().plusMinutes(15).isBefore(ZonedDateTime.now())) {
        log.info("[{}] Clearing cached data from {}", server, formatRelative(server.getLastValidPing()));
        server.setMap("");
        server.setPlayers(0);
        server.setMaxPlayers(0);
        server.setTvPort(0);
    }
    return server;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:53,代碼來源:GameServerService.java

示例13: testHistorgramInt

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void testHistorgramInt() throws Exception {
  Histogram h = registry.histogram("H1");
  h.update(1);
  assertEquals(h, updatedMetric);
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:7,代碼來源:TracingMetricRegistryTest.java

示例14: testHistorgramLong

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
@Test
public void testHistorgramLong() throws Exception {
  Histogram h = registry.histogram("H2");
  h.update(1L);
  assertEquals(h, updatedMetric);
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:7,代碼來源:TracingMetricRegistryTest.java

示例15: registerMetricsTypes

import com.codahale.metrics.Histogram; //導入方法依賴的package包/類
private void registerMetricsTypes(MetricsMessage message) {
    for (KeyValuePair keyValuePair : message.getHeaders()) {
        Histogram histogram = metricsRegistry.histogram("histogram_" + keyValuePair.getKey());
        histogram.update(0);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:7,代碼來源:JettyServletMetricsActor.java


注:本文中的com.codahale.metrics.Histogram.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。