本文整理汇总了Java中com.codahale.metrics.Snapshot类的典型用法代码示例。如果您正苦于以下问题:Java Snapshot类的具体用法?Java Snapshot怎么用?Java Snapshot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Snapshot类属于com.codahale.metrics包,在下文中一共展示了Snapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSnapshot
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
/**
* Returns a snapshot of the decaying values in this reservoir.
*
* Non-decaying reservoir will not be included in the snapshot.
*
* @return the snapshot
*/
public Snapshot getSnapshot()
{
rescaleIfNeeded();
lockForRegularUsage();
try
{
return new EstimatedHistogramReservoirSnapshot(this);
}
finally
{
unlockForRegularUsage();
}
}
示例2: reportSnapshot
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private void reportSnapshot(TagEncodedMetricName metric, Snapshot snapshot) {
addDataPoint(metric.submetric("duration.min"), convertDuration(snapshot.getMin()));
addDataPoint(metric.submetric("duration.max"), convertDuration(snapshot.getMax()));
addDataPoint(metric.submetric("duration.mean"), convertDuration(snapshot.getMean()));
addDataPoint(metric.submetric("duration.stddev"), convertDuration(snapshot.getStdDev()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p50"),
convertDuration(snapshot.getMedian()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p75"),
convertDuration(snapshot.get75thPercentile()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p95"),
convertDuration(snapshot.get95thPercentile()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p98"),
convertDuration(snapshot.get98thPercentile()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p99"),
convertDuration(snapshot.get99thPercentile()));
addDataPoint(metric.submetric("duration").withTags("quantile", "p999"),
convertDuration(snapshot.get999thPercentile()));
}
示例3: fromHistogram
import com.codahale.metrics.Snapshot; //导入依赖的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();
}
示例4: serialize
import com.codahale.metrics.Snapshot; //导入依赖的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();
}
示例5: reportTimer
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
/** */
private void reportTimer(String timestamp, String name, Timer timer) {
final Snapshot snapshot = timer.getSnapshot();
report(timestamp,
name,
"count,max,mean,min,stddev,p50,p75,p95,p98,p99,p999,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit,duration_unit",
"%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,calls/%s,%s",
timer.getCount(),
convertDuration(snapshot.getMax()),
convertDuration(snapshot.getMean()),
convertDuration(snapshot.getMin()),
convertDuration(snapshot.getStdDev()),
convertDuration(snapshot.getMedian()),
convertDuration(snapshot.get75thPercentile()),
convertDuration(snapshot.get95thPercentile()),
convertDuration(snapshot.get98thPercentile()),
convertDuration(snapshot.get99thPercentile()),
convertDuration(snapshot.get999thPercentile()),
convertRate(timer.getMeanRate()),
convertRate(timer.getOneMinuteRate()),
convertRate(timer.getFiveMinuteRate()),
convertRate(timer.getFifteenMinuteRate()),
getRateUnit(),
getDurationUnit());
}
示例6: reportHistogram
import com.codahale.metrics.Snapshot; //导入依赖的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());
}
示例7: writeSnapshotAndCount
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private void writeSnapshotAndCount(String dropwizardName, Snapshot snapshot, long count, double factor, MetricType type, String helpMessage) throws IOException {
String name = sanitizeMetricName(dropwizardName);
writer.writeHelp(name, helpMessage);
writer.writeType(name, type);
writer.writeSample(name, mapOf("quantile", "0.5"), snapshot.getMedian() * factor);
writer.writeSample(name, mapOf("quantile", "0.75"), snapshot.get75thPercentile() * factor);
writer.writeSample(name, mapOf("quantile", "0.95"), snapshot.get95thPercentile() * factor);
writer.writeSample(name, mapOf("quantile", "0.98"), snapshot.get98thPercentile() * factor);
writer.writeSample(name, mapOf("quantile", "0.99"), snapshot.get99thPercentile() * factor);
writer.writeSample(name, mapOf("quantile", "0.999"), snapshot.get999thPercentile() * factor);
writer.writeSample(name + "_min", emptyMap(), snapshot.getMin());
writer.writeSample(name + "_max", emptyMap(), snapshot.getMax());
writer.writeSample(name + "_median", emptyMap(), snapshot.getMedian());
writer.writeSample(name + "_mean", emptyMap(), snapshot.getMean());
writer.writeSample(name + "_stddev", emptyMap(), snapshot.getStdDev());
writer.writeSample(name + "_count", emptyMap(), count);
}
示例8: reportHistogram
import com.codahale.metrics.Snapshot; //导入依赖的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: processTimer
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
/**
* The {@link Snapshot} values of {@link Timer} are reported as {@link StatisticSet} after conversion. The
* conversion is done using the duration factor, which is deduced from the set duration unit.
* <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 Timer#getSnapshot
* @see #getDurationUnit
* @see #convertDuration(double)
*/
private void processTimer(final String metricName, final Timer timer, final List<MetricDatum> metricData) {
final Snapshot snapshot = timer.getSnapshot();
if (builder.withZeroValuesSubmission || snapshot.size() > 0) {
for (final Percentile percentile : builder.percentiles) {
final double convertedDuration = convertDuration(snapshot.getValue(percentile.getQuantile()));
stageMetricDatum(true, metricName, convertedDuration, durationUnit, percentile.getDesc(), metricData);
}
}
// prevent empty snapshot from causing InvalidParameterValueException
if (snapshot.size() > 0) {
final String formattedDuration = String.format(" [in-%s]", getDurationUnit());
stageMetricDatum(builder.withArithmeticMean, metricName, convertDuration(snapshot.getMean()), durationUnit, DIMENSION_SNAPSHOT_MEAN + formattedDuration, metricData);
stageMetricDatum(builder.withStdDev, metricName, convertDuration(snapshot.getStdDev()), durationUnit, DIMENSION_SNAPSHOT_STD_DEV + formattedDuration, metricData);
stageMetricDatumWithConvertedSnapshot(builder.withStatisticSet, metricName, snapshot, durationUnit, metricData);
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:35,代码来源:CloudWatchReporter.java
示例10: processHistogram
import com.codahale.metrics.Snapshot; //导入依赖的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
示例11: stageMetricDatumWithConvertedSnapshot
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private void stageMetricDatumWithConvertedSnapshot(final boolean metricConfigured,
final String metricName,
final Snapshot snapshot,
final StandardUnit standardUnit,
final List<MetricDatum> metricData) {
if (metricConfigured) {
double scaledSum = convertDuration(LongStream.of(snapshot.getValues()).sum());
final StatisticSet statisticSet = new StatisticSet()
.withSum(scaledSum)
.withSampleCount((double) snapshot.size())
.withMinimum(convertDuration(snapshot.getMin()))
.withMaximum(convertDuration(snapshot.getMax()));
final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));
metricData.add(new MetricDatum()
.withTimestamp(new Date(builder.clock.getTime()))
.withMetricName(metricName)
.withDimensions(dimensions)
.withStatisticValues(statisticSet)
.withUnit(standardUnit));
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java
示例12: stageMetricDatumWithRawSnapshot
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private void stageMetricDatumWithRawSnapshot(final boolean metricConfigured,
final String metricName,
final Snapshot snapshot,
final StandardUnit standardUnit,
final List<MetricDatum> metricData) {
if (metricConfigured) {
double total = LongStream.of(snapshot.getValues()).sum();
final StatisticSet statisticSet = new StatisticSet()
.withSum(total)
.withSampleCount((double) snapshot.size())
.withMinimum((double) snapshot.getMin())
.withMaximum((double) snapshot.getMax());
final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
dimensions.add(new Dimension().withName(DIMENSION_NAME_TYPE).withValue(DIMENSION_SNAPSHOT_SUMMARY));
metricData.add(new MetricDatum()
.withTimestamp(new Date(builder.clock.getTime()))
.withMetricName(metricName)
.withDimensions(dimensions)
.withStatisticValues(statisticSet)
.withUnit(standardUnit));
}
}
开发者ID:azagniotov,项目名称:codahale-aggregated-metrics-cloudwatch-reporter,代码行数:25,代码来源:CloudWatchReporter.java
示例13: reportHistogram
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private void reportHistogram(String name, Histogram histogram) throws IOException {
final Snapshot snapshot = histogram.getSnapshot();
statsdClient.send(prefix(name, "count"),
format(histogram.getCount()),
StatsdClient.StatType.GAUGE);
statsdClient.send(prefix(name, "max"),
format(snapshot.getMax()),
StatsdClient.StatType.TIMER);
statsdClient.send(prefix(name, "mean"),
format(snapshot.getMean()),
StatsdClient.StatType.TIMER);
statsdClient.send(prefix(name, "p95"),
format(snapshot.get95thPercentile()),
StatsdClient.StatType.TIMER);
}
示例14: formatSamplingSnapshot
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
private String formatSamplingSnapshot(String name, Snapshot snapshot, long timestamp, boolean convertValuesToDurations) {
StringBuilder outputBuilder = new StringBuilder();
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "max"), convertValuesToDurations ? convertDuration(snapshot.getMax()) : snapshot.getMax(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "mean"), convertValuesToDurations ? convertDuration(snapshot.getMean()) : snapshot.getMean(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "min"), convertValuesToDurations ? convertDuration(snapshot.getMin()) : snapshot.getMin(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "stddev"), convertValuesToDurations ? convertDuration(snapshot.getStdDev()) : snapshot.getStdDev(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p50"), convertValuesToDurations ? convertDuration(snapshot.getMedian()) : snapshot.getMedian(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p75"), convertValuesToDurations ? convertDuration(snapshot.get75thPercentile()) : snapshot.get75thPercentile(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p95"), convertValuesToDurations ? convertDuration(snapshot.get95thPercentile()) : snapshot.get95thPercentile(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p98"), convertValuesToDurations ? convertDuration(snapshot.get98thPercentile()) : snapshot.get98thPercentile(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p99"), convertValuesToDurations ? convertDuration(snapshot.get99thPercentile()) : snapshot.get99thPercentile(), timestamp));
outputBuilder.append(formatLine(MetricNamingUtil.join(name, "p999"), convertValuesToDurations ? convertDuration(snapshot.get999thPercentile()) : snapshot.get999thPercentile(), timestamp));
return outputBuilder.toString();
}
示例15: serialize
import com.codahale.metrics.Snapshot; //导入依赖的package包/类
@Override
public JsonElement serialize(Timer timer, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
final Snapshot snapshot = timer.getSnapshot();
json.addProperty("count", timer.getCount());
json.addProperty("max", snapshot.getMax() * DURATION_FACTOR);
json.addProperty("mean", snapshot.getMean() * DURATION_FACTOR);
json.addProperty("min", snapshot.getMin() * DURATION_FACTOR);
json.addProperty("p50", snapshot.getMedian() * DURATION_FACTOR);
json.addProperty("p75", snapshot.get75thPercentile() * DURATION_FACTOR);
json.addProperty("p95", snapshot.get95thPercentile() * DURATION_FACTOR);
json.addProperty("p98", snapshot.get98thPercentile() * DURATION_FACTOR);
json.addProperty("p99", snapshot.get99thPercentile() * DURATION_FACTOR);
json.addProperty("p999", snapshot.get999thPercentile() * DURATION_FACTOR);
json.addProperty("stddev", snapshot.getStdDev() * DURATION_FACTOR);
json.addProperty("m15_rate", timer.getFifteenMinuteRate());
json.addProperty("m1_rate", timer.getOneMinuteRate());
json.addProperty("m5_rate", timer.getFiveMinuteRate());
json.addProperty("mean_rate", timer.getMeanRate());
json.addProperty("duration_units", "seconds");
json.addProperty("rate_units", "calls/second");
return json;
}