本文整理汇总了Java中com.codahale.metrics.Histogram类的典型用法代码示例。如果您正苦于以下问题:Java Histogram类的具体用法?Java Histogram怎么用?Java Histogram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Histogram类属于com.codahale.metrics包,在下文中一共展示了Histogram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: report
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@Override
public void report(final SortedMap<String, Gauge> gauges,
final SortedMap<String, Counter> counters,
final SortedMap<String, Histogram> histograms,
final SortedMap<String, Meter> meters,
final SortedMap<String, Timer> timers) {
final long timestamp = clock.instant().toEpochMilli();
final ImmutableList<InfluxDbMeasurement> influxDbMeasurements = ImmutableList.<InfluxDbMeasurement>builder()
.addAll(transformer.fromGauges(gauges, timestamp))
.addAll(transformer.fromCounters(counters, timestamp))
.addAll(transformer.fromHistograms(histograms, timestamp))
.addAll(transformer.fromMeters(meters, timestamp))
.addAll(transformer.fromTimers(timers, timestamp))
.build();
sender.send(influxDbMeasurements);
}
示例2: fromHistogram
import com.codahale.metrics.Histogram; //导入依赖的package包/类
/**
* Build an {@link InfluxDbMeasurement} from a histogram.
*/
@VisibleForTesting InfluxDbMeasurement fromHistogram(final String metricName, final Histogram h, final long timestamp) {
final Snapshot snapshot = h.getSnapshot();
final DropwizardMeasurement measurement = parser.parse(metricName);
final Map<String, String> tags = new HashMap<>(baseTags);
tags.putAll(measurement.tags());
return new InfluxDbMeasurement.Builder(measurement.name(), timestamp)
.putTags(tags)
.putField("count", snapshot.size())
.putField("min", snapshot.getMin())
.putField("max", snapshot.getMax())
.putField("mean", snapshot.getMean())
.putField("std-dev", snapshot.getStdDev())
.putField("50-percentile", snapshot.getMedian())
.putField("75-percentile", snapshot.get75thPercentile())
.putField("95-percentile", snapshot.get95thPercentile())
.putField("99-percentile", snapshot.get99thPercentile())
.putField("999-percentile", snapshot.get999thPercentile())
.putField("run-count", h.getCount())
.build();
}
示例3: serialize
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@Override
public void serialize(JsonHistogram jsonHistogram,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("name", jsonHistogram.name());
json.writeObjectField(timestampFieldname, jsonHistogram.timestampAsDate());
Histogram histogram = jsonHistogram.value();
final Snapshot snapshot = histogram.getSnapshot();
json.writeNumberField("count", histogram.getCount());
json.writeNumberField("max", snapshot.getMax());
json.writeNumberField("mean", snapshot.getMean());
json.writeNumberField("min", snapshot.getMin());
json.writeNumberField("p50", snapshot.getMedian());
json.writeNumberField("p75", snapshot.get75thPercentile());
json.writeNumberField("p95", snapshot.get95thPercentile());
json.writeNumberField("p98", snapshot.get98thPercentile());
json.writeNumberField("p99", snapshot.get99thPercentile());
json.writeNumberField("p999", snapshot.get999thPercentile());
json.writeNumberField("stddev", snapshot.getStdDev());
addOneOpsMetadata(json);
json.writeEndObject();
}
示例4: reportHistogram
import com.codahale.metrics.Histogram; //导入依赖的package包/类
/** */
private void reportHistogram(String timestamp, String name, Histogram histogram) {
final Snapshot snapshot = histogram.getSnapshot();
report(timestamp,
name,
"count,max,mean,min,stddev,p50,p75,p90,p95,p98,p99,p999",
"%d,%d,%f,%d,%f,%f,%f,%f,%f,%f,%f,%f",
histogram.getCount(),
snapshot.getMax(),
snapshot.getMean(),
snapshot.getMin(),
snapshot.getStdDev(),
snapshot.getMedian(),
snapshot.get75thPercentile(),
snapshot.getValue(0.9), // Add 90-th percentile to report.
snapshot.get95thPercentile(),
snapshot.get98thPercentile(),
snapshot.get99thPercentile(),
snapshot.get999thPercentile());
}
示例5: 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);
}
示例6: 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.
}
示例7: 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();
}
示例8: reportHistogram
import com.codahale.metrics.Histogram; //导入依赖的package包/类
private void reportHistogram(JsonGenerator jsonGenerator, Entry<String, Histogram> entry, String timestampString) {
try {
writeStartMetric(entry.getKey(), jsonGenerator, timestampString);
jsonGenerator.writeStartObject();
final Histogram histogram = entry.getValue();
final Snapshot snapshot = histogram.getSnapshot();
jsonGenerator.writeNumberField("count", histogram.getCount());
jsonGenerator.writeNumberField("min", convertDuration(snapshot.getMin()));
jsonGenerator.writeNumberField("max", convertDuration(snapshot.getMax()));
jsonGenerator.writeNumberField("mean", convertDuration(snapshot.getMean()));
jsonGenerator.writeNumberField("stddev", convertDuration(snapshot.getStdDev()));
jsonGenerator.writeNumberField("median", convertDuration(snapshot.getMedian()));
jsonGenerator.writeNumberField("75th percentile", convertDuration(snapshot.get75thPercentile()));
jsonGenerator.writeNumberField("95th percentile", convertDuration(snapshot.get95thPercentile()));
jsonGenerator.writeNumberField("98th percentile", convertDuration(snapshot.get98thPercentile()));
jsonGenerator.writeNumberField("99th percentile", convertDuration(snapshot.get99thPercentile()));
jsonGenerator.writeNumberField("999th percentile", convertDuration(snapshot.get999thPercentile()));
jsonGenerator.writeEndObject();
writeEndMetric(jsonGenerator);
} catch (IOException ioe) {
LOGGER.error("Exception writing metrics to Elasticsearch index: " + ioe.toString());
}
}
示例9: processHistogram
import com.codahale.metrics.Histogram; //导入依赖的package包/类
/**
* The {@link Snapshot} values of {@link Histogram} are reported as {@link StatisticSet} raw. In other words, the
* conversion using the duration factor does NOT apply.
* <p>
* Please note, the reported values submitted only if they show some data (greater than zero) in order to:
* <p>
* 1. save some money
* 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
* is submitted
* <p>
* If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
*
* @see Histogram#getSnapshot
*/
private void processHistogram(final String metricName, final Histogram histogram, final List<MetricDatum> metricData) {
final Snapshot snapshot = histogram.getSnapshot();
if (builder.withZeroValuesSubmission || snapshot.size() > 0) {
for (final Percentile percentile : builder.percentiles) {
final double value = snapshot.getValue(percentile.getQuantile());
stageMetricDatum(true, metricName, value, StandardUnit.None, percentile.getDesc(), metricData);
}
}
// prevent empty snapshot from causing InvalidParameterValueException
if (snapshot.size() > 0) {
stageMetricDatum(builder.withArithmeticMean, metricName, snapshot.getMean(), StandardUnit.None, DIMENSION_SNAPSHOT_MEAN, metricData);
stageMetricDatum(builder.withStdDev, metricName, snapshot.getStdDev(), StandardUnit.None, DIMENSION_SNAPSHOT_STD_DEV, metricData);
stageMetricDatumWithRawSnapshot(builder.withStatisticSet, metricName, snapshot, StandardUnit.None, metricData);
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:32,代码来源:CloudWatchReporter.java
示例10: 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());
}
}
}
}
}
示例11: getNamedHistogram_with_iterable_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@DataProvider(value = {
"null",
"0",
"1",
"2"
}, splitBy = "\\|")
@Test
public void getNamedHistogram_with_iterable_dimensions_creates_dimensioned_histogram_using_sfx_mechanisms(
Integer numDimensions
) {
// given
String histogramName = UUID.randomUUID().toString();
List<Pair<String, String>> iterableDims = generateIterableDimensions(numDimensions);
// when
Histogram result = sfxImpl.getNamedHistogram(histogramName, iterableDims);
// then
verifyMetricCreation(histogramBuilderMock, histogramTaggerMock, histogramName, iterableDims, histogramMock, result);
}
示例12: RollingWindowTimerBuilder
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@DataProvider(value = {
"42 | DAYS",
"123 | SECONDS",
"999 | MILLISECONDS",
"3 | HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_newMetric_creates_new_timer_with_SlidingTimeWindowReservoir_with_expected_values(
long amount, TimeUnit timeUnit
) {
// given
RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(amount, timeUnit);
// when
Timer timer = rwtb.newMetric();
// then
Histogram histogram = (Histogram) getInternalState(timer, "histogram");
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
示例13: RollingWindowHistogramBuilder
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@DataProvider(value = {
"42 | DAYS",
"123 | SECONDS",
"999 | MILLISECONDS",
"3 | HOURS"
}, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_newMetric_creates_new_histogram_with_SlidingTimeWindowReservoir_with_expected_values(
long amount, TimeUnit timeUnit
) {
// given
RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(amount, timeUnit);
// when
Histogram histogram = rwhb.newMetric();
// then
Reservoir reservoir = (Reservoir) getInternalState(histogram, "reservoir");
assertThat(reservoir).isInstanceOf(SlidingTimeWindowReservoir.class);
// The expected value here comes from logic in the SlidingTimeWindowReservoir constructor.
assertThat(getInternalState(reservoir, "window")).isEqualTo(timeUnit.toNanos(amount) * 256);
}
示例14: RollingWindowHistogramBuilder_isInstance_works_as_expected
import com.codahale.metrics.Histogram; //导入依赖的package包/类
@DataProvider(value = {
"true | true",
"false | false"
}, splitBy = "\\|")
@Test
public void RollingWindowHistogramBuilder_isInstance_works_as_expected(boolean useHistogram, boolean expectedResult) {
// given
Metric metric = (useHistogram) ? mock(Histogram.class) : mock(Gauge.class);
RollingWindowHistogramBuilder rwhb = new RollingWindowHistogramBuilder(42, TimeUnit.DAYS);
// when
boolean result = rwhb.isInstance(metric);
// then
assertThat(result).isEqualTo(expectedResult);
}
示例15: notifyListenerOfAddedMetric
import com.codahale.metrics.Histogram; //导入依赖的package包/类
private void notifyListenerOfAddedMetric(
final MetricRegistryListener listener, final Metric metric, final String name
) {
if(metric instanceof Gauge) {
listener.onGaugeAdded(name, (Gauge<?>) metric);
} else if(metric instanceof Counter) {
listener.onCounterAdded(name, (Counter) metric);
} else if(metric instanceof Histogram) {
listener.onHistogramAdded(name, (Histogram) metric);
} else if(metric instanceof Meter) {
listener.onMeterAdded(name, (Meter) metric);
} else if(metric instanceof Timer) {
listener.onTimerAdded(name, (Timer) metric);
} else {
throw new IllegalArgumentException("Unsupported metric type: " + metric.getClass());
}
}