@Override public Child labels(String... labels) { return new CallMeterChildImpl( collectors.histogram.labels(labels), collectors.totalCounter.labels(labels), collectors.errorCounter.labels(labels)); }
@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(); }
@TearDown(Level.Iteration) public void tearDown(Blackhole hole) { hole.consume(histogram.collect()); } }
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(); } }
@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"); }
@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; }
public void prometheusHistogram(PrometheusState state, Data data) { state.histogram.observe(data.dataIterator.next()); }
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;
public PrometheusHistogram register(CollectorRegistry registry) { histogram.register(registry); return this; }
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; }
@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; } }
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(); }
@Override public List<MetricFamilySamples> collect() { return requests.collect(); }
public PrometheusHistogram register() { histogram.register(); return this; }
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleHistogramNoLabelsBenchmark() { prometheusSimpleHistogramNoLabels.observe(1); }
@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(); } }
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); } }
@Override public List<MetricFamilySamples> collect() { return histogram.collect(); }
@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; }
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleHistogramBenchmark() { prometheusSimpleHistogram.labels("test", "group").observe(1) ; }