本文整理了Java中io.prometheus.client.Histogram
类的一些代码示例,展示了Histogram
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Histogram
类的具体详情如下:
包路径:io.prometheus.client.Histogram
类名称:Histogram
[英]Histogram metric, to track distributions of events.
Example of uses for Histograms include:
Note: Each bucket is one timeseries. Many buckets and/or many dimensions with labels can produce large amount of time series, that may cause performance problems.
The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds.
Example Histograms:
class YourClass finally
requestTimer.observeDuration();
}
}
// Or if using Java 8 lambdas.
void processRequestLambda(Request req)
requestLatency.time(() ->
// Your code here.
});
}
}
}
You can choose your own buckets:
static final Histogram requestLatency = Histogram.build()
Histogram.Builder#linearBuckets(double,double,int) and Histogram.Builder#exponentialBuckets(double,double,int)offer easy ways to set common bucket patterns.
[中]直方图度量,用于跟踪事件的分布。
直方图的使用示例包括:
*响应延迟
*请求大小
*注:*每个桶为一个时间序列。许多桶和/或带有标签的多个维度会产生大量的时间序列,这可能会导致性能问题。
默认存储桶用于覆盖从毫秒到秒的典型web/rpc请求。
直方图示例:
class YourClass finally
requestTimer.observeDuration();
}
}
// Or if using Java 8 lambdas.
void processRequestLambda(Request req)
requestLatency.time(() ->
// Your code here.
});
}
}
}
您可以选择自己的桶:
static final Histogram requestLatency = Histogram.build()
直方图。生成器#linearBuckets(double、double、int)和直方图。Builder#指数桶(double、double、int)提供了设置常用桶模式的简单方法。
代码示例来源:origin: resilience4j/resilience4j
@Override
public Child labels(String... labels) {
return new CallMeterChildImpl(
collectors.histogram.labels(labels),
collectors.totalCounter.labels(labels),
collectors.errorCounter.labels(labels));
}
代码示例来源:origin: micrometer-metrics/micrometer
@Setup(Level.Trial)
public void setup() {
double[] micrometerBuckets =
Doubles.toArray(PercentileHistogramBuckets.buckets(
DistributionStatisticConfig.builder().minimumExpectedValue(0L).maximumExpectedValue(Long.MAX_VALUE)
.percentilesHistogram(true).build()));
histogram = io.prometheus.client.Histogram.build("histogram", "A histogram")
.buckets(micrometerBuckets).create();
}
代码示例来源:origin: micrometer-metrics/micrometer
@TearDown(Level.Iteration)
public void tearDown(Blackhole hole) {
hole.consume(histogram.collect());
}
}
代码示例来源:origin: ahus1/prometheus-hystrix
public Histogram.Child addHistogram(String subsystem, String metric, String helpDoc,
SortedMap<String, String> labels) {
lock.writeLock().lock();
try {
String name = name(subsystem, metric);
Histogram histogram = histograms.get(name);
if (histogram == null) {
Histogram.Builder histogramBuilder = Histogram.build().name(name).help(helpDoc)
.labelNames(labels.keySet().toArray(new String[]{}));
histogramParameterizer.accept(histogramBuilder);
histogram = histogramBuilder.create();
histogram.register(registry);
histograms.put(name, histogram);
}
return histogram.labels(labels.values().toArray(new String[]{}));
} finally {
lock.writeLock().unlock();
}
}
代码示例来源:origin: prometheus/client_java
@Setup
public void setup() {
prometheusSummary = io.prometheus.client.metrics.Summary.newBuilder()
.name("name")
.documentation("some description..")
.build();
prometheusSummaryChild = prometheusSummary.newPartial().apply();
prometheusSimpleSummary = io.prometheus.client.Summary.build()
.name("name")
.help("some description..")
.labelNames("some", "group").create();
prometheusSimpleSummaryChild = prometheusSimpleSummary.labels("test", "group");
prometheusSimpleSummaryNoLabels = io.prometheus.client.Summary.build()
.name("name")
.help("some description..")
.create();
prometheusSimpleHistogram = io.prometheus.client.Histogram.build()
.name("name")
.help("some description..")
.labelNames("some", "group").create();
prometheusSimpleHistogramChild = prometheusSimpleHistogram.labels("test", "group");
prometheusSimpleHistogramNoLabels = io.prometheus.client.Histogram.build()
.name("name")
.help("some description..")
.create();
registry = new MetricRegistry();
codahaleHistogram = registry.histogram("name");
}
代码示例来源:origin: alibaba/canal
@Override
public void start() {
if (outboundCounter != null) {
outboundCounter.register();
}
if (packetsCounter != null) {
packetsCounter.register();
}
if (emptyBatchesCounter != null) {
emptyBatchesCounter.register();
}
if (errorsCounter != null) {
errorsCounter.register();
}
if (responseLatency != null) {
responseLatency.register();
}
running = true;
}
代码示例来源:origin: micrometer-metrics/micrometer
public void prometheusHistogram(PrometheusState state, Data data) {
state.histogram.observe(data.dataIterator.next());
}
代码示例来源:origin: marcelmay/hadoop-hdfs-fsimage-exporter
Histogram overallHistogram = Histogram.build()
.name(METRIC_PREFIX + FSIZE)
.buckets(configuredBuckets)
.name(FsImageCollector.METRIC_PREFIX + REPLICATION)
.help("Overall file replication").create();
overallStats = new OverallStats(new HistogramMetricAdapter(overallHistogram.labels()), overallReplication);
groupFileSizeDistribution = summary;
} else {
Histogram histogram = Histogram.build()
.name(FsImageCollector.METRIC_PREFIX_GROUP + FSIZE)
.labelNames(FsImageCollector.LABEL_GROUP_NAME)
.buckets(configuredBuckets)
.help("Per group file size distribution.").create();
createGroupStats = groupName -> new GroupStats(groupName, new HistogramMetricAdapter(histogram.labels(groupName)));
groupFileSizeDistribution = histogram;
userFileSizeDistribution = summary;
} else {
Histogram histogram = Histogram.build()
.name(FsImageCollector.METRIC_PREFIX_USER + FSIZE)
.labelNames(FsImageCollector.LABEL_USER_NAME)
.help("Per user file size distribution").create();
createUserStat = userName -> new UserStats(userName,
new HistogramMetricAdapter(histogram.labels(userName)),
new SummaryMetricAdapter(userReplication.labels(userName)));
userFileSizeDistribution = histogram;
代码示例来源:origin: com.jonnymatts.prometheus/metrics-core
public PrometheusHistogram register(CollectorRegistry registry) {
histogram.register(registry);
return this;
}
代码示例来源:origin: zalando/zalenium
private boolean takeRequestHandler(RequestHandler handler) {
final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities());
final boolean sessionCreated = session != null;
if (sessionCreated) {
String remoteName = session.getSlot().getProxy().getId();
long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime();
LOG.info("Test session with internal key {} assigned to remote ({}) after {} seconds ({} ms).",
session.getInternalKey(),
remoteName,
timeToAssignProxy / 1000,
timeToAssignProxy);
seleniumTestSessionStartLatency.observe(timeToAssignProxy / Collector.MILLISECONDS_PER_SECOND);
seleniumTestSessionsWaiting.dec();
activeTestSessions.add(session);
handler.bindSession(session);
}
return sessionCreated;
}
代码示例来源:origin: alibaba/canal
@Override
public void profiling(ClientRequestResult result) {
String destination = result.getDestination();
PacketType type = result.getType();
outboundCounter.labels(destination).inc(result.getAmount());
short errorCode = result.getErrorCode();
if (errorCode > 0) {
errorsCounter.labels(destination, Short.toString(errorCode)).inc();
}
long latency = result.getLatency();
responseLatency.labels(destination).observe(((double) latency) / NANO_PER_MILLI);
switch (type) {
case GET:
boolean empty = result.getEmpty();
// 区分一下空包
if (empty) {
emptyBatchesCounter.labels(destination).inc();
} else {
packetsCounter.labels(destination, type.name()).inc();
}
break;
// reserve for others
default:
packetsCounter.labels(destination, type.name()).inc();
break;
}
}
代码示例来源:origin: alibaba/canal
private PrometheusClientInstanceProfiler() {
this.outboundCounter = Counter.build()
.labelNames(DEST_LABELS)
.name(OUTBOUND_BYTES)
.help("Total bytes sent to client.")
.create();
this.packetsCounter = Counter.build()
.labelNames(new String[]{DEST, "packetType"})
.name(PACKET_TYPE)
.help("Total packets sent to client.")
.create();
this.emptyBatchesCounter = Counter.build()
.labelNames(DEST_LABELS)
.name(EMPTY_BATCHES)
.help("Total empty batches sent to client.")
.create();
this.errorsCounter = Counter.build()
.labelNames(new String[]{DEST, "errorCode"})
.name(ERRORS)
.help("Total client request errors.")
.create();
this.responseLatency = Histogram.build()
.labelNames(DEST_LABELS)
.name(LATENCY)
.help("Client request latency.")
// buckets in milliseconds
.buckets(2.5, 10.0, 25.0, 100.0)
.create();
}
代码示例来源:origin: no.skatteetaten.aurora/aurora-prometheus
@Override
public List<MetricFamilySamples> collect() {
return requests.collect();
}
代码示例来源:origin: com.jonnymatts.prometheus/metrics-core
public PrometheusHistogram register() {
histogram.register();
return this;
}
代码示例来源:origin: prometheus/client_java
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void prometheusSimpleHistogramNoLabelsBenchmark() {
prometheusSimpleHistogramNoLabels.observe(1);
}
代码示例来源:origin: prometheus/client_java
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
if (!(servletRequest instanceof HttpServletRequest)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
HttpServletRequest request = (HttpServletRequest) servletRequest;
String path = request.getRequestURI();
Histogram.Timer timer = histogram
.labels(getComponents(path), request.getMethod())
.startTimer();
try {
filterChain.doFilter(servletRequest, servletResponse);
} finally {
timer.observeDuration();
}
}
代码示例来源:origin: resilience4j/resilience4j
private CallCollectors createMetrics() {
final Counter totalCounter = Counter
.build()
.namespace(namespace)
.subsystem(subsystem)
.name(name + "_total")
.help(help + " total")
.labelNames(labelNames)
.create();
final Counter errorCounter = Counter
.build()
.namespace(namespace)
.subsystem(subsystem)
.name(name + "_failures_total")
.help(help + " failures total")
.labelNames(labelNames)
.create();
final Histogram histogram = Histogram
.build()
.namespace(namespace)
.subsystem(subsystem)
.name(name + "_latency")
.help(help + " latency")
.labelNames(labelNames)
.create();
return new CallCollectors(histogram, totalCounter, errorCounter);
}
}
代码示例来源:origin: no.skatteetaten.aurora/aurora-prometheus
@Override
public List<MetricFamilySamples> collect() {
return histogram.collect();
}
代码示例来源:origin: com.alibaba.otter/canal.prometheus
@Override
public void start() {
if (outboundCounter != null) {
outboundCounter.register();
}
if (packetsCounter != null) {
packetsCounter.register();
}
if (emptyBatchesCounter != null) {
emptyBatchesCounter.register();
}
if (errorsCounter != null) {
errorsCounter.register();
}
if (responseLatency != null) {
responseLatency.register();
}
running = true;
}
代码示例来源:origin: prometheus/client_java
@Benchmark
@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public void prometheusSimpleHistogramBenchmark() {
prometheusSimpleHistogram.labels("test", "group").observe(1) ;
}
内容来源于网络,如有侵权,请联系作者删除!