本文整理汇总了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);
}
示例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.
}
示例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();
}
示例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());
}
}
}
}
}
示例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());
}
示例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();
}
}
示例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);
}
示例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);
}
示例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\"}"));
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}