@Override public Child labels(String... labels) { return new CallMeterChildImpl( collectors.histogram.labels(labels), collectors.totalCounter.labels(labels), collectors.errorCounter.labels(labels)); }
@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; } }
@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(); } }
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleHistogramBenchmark() { prometheusSimpleHistogram.labels("test", "group").observe(1) ; }
public Histogram.Child labels(String... labels) { return histogram.labels(labels); }
public AutoCloseable start(final String... labels) { long startTime = System.nanoTime(); return () -> histogram.labels(labels).observe((System.nanoTime() - startTime) / 1e9); }
@Override protected String reportQuery(String query, Object[] args, final String name, long start, long delta) { String sql = super.reportQuery(query, args, name, start, delta); globalQueryStats.labels(SUCCESS_QUERY_STATUS).observe((double) delta/1000); if (slowQueryStatsEnabled && delta >= slowQueryThreshold) { slowQueryStats.labels(sql).observe((double) delta/1000); } return sql; }
@Override protected String reportSlowQuery(String query, Object[] args, String name, long start, long delta) { String sql = super.reportSlowQuery(query, args, name, start, delta); globalQueryStats.labels(SUCCESS_QUERY_STATUS).observe((double) delta/1000); if (slowQueryStatsEnabled && delta >= slowQueryThreshold) { slowQueryStats.labels(sql).observe((double) delta/1000); } return sql; }
@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"); }
public static <T> T withMetrics(String name, String type, Supplier<T> s) { SimpleTimer requestTimer = new SimpleTimer(); String result = "success"; try { return s.get(); } catch (Exception e) { result = e.getClass().getSimpleName(); throw e; } finally { instance.executions.labels(result, type, name) .observe(requestTimer.elapsedSeconds()); } }
private void invokeIntent(Message message, DatabaseEventHolder databaseEventHolder, AIResponse response, Intent intent) { Metrics.aiRequestsExecuted.labels(intent.getClass().getSimpleName()).inc(); Histogram.Timer timer = Metrics.aiExecutionTime.labels(intent.getClass().getSimpleName()).startTimer(); intent.onIntent(new CommandMessage( null, databaseEventHolder, message ), response); timer.observeDuration(); }
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(); } }
@Override protected String reportFailedQuery(String query, Object[] args, String name, long start, Throwable t) { String sql = super.reportFailedQuery(query, args, name, start, t); long now = System.currentTimeMillis(); long delta = now - start; globalQueryStats.labels(FAILED_QUERY_STATUS).observe((double) delta/1000); if (failedQueryStatsEnabled) { failedQueryStats.labels(sql).inc(); } return sql; }
public void record(String method, String requestUri, int statusCode, long start) { long duration = System.nanoTime() - start; if (!config.shouldRecord(requestUri)) { return; } String path = config.groupUrl(requestUri).orElse(normalize(requestUri, isClient)); requests.labels( method, String.valueOf(statusCode), HttpStatusSeries.valueOf(statusCode).name(), path ).observe(duration / Collector.NANOSECONDS_PER_SECOND); }
@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; if (!request.isAsyncStarted()) { String context = getContext(request); servletConcurrentRequest.labels(context).inc(); Histogram.Timer timer = servletLatency .labels(context, request.getMethod()) .startTimer(); try { filterChain.doFilter(servletRequest, servletResponse); } finally { timer.observeDuration(); servletConcurrentRequest.labels(context).dec(); servletStatusCodes.labels(context, Integer.toString(getStatus((HttpServletResponse) servletResponse))).inc(); } } else { filterChain.doFilter(servletRequest, servletResponse); } }
Histogram.Timer requestTimer = commandLatency.labels(shard, command.getNames()[0]).startTimer(); try { command.on(context);
Histogram.Timer executionTimer = Metrics.commandExecutionTime.labels(cmd.getClass().getSimpleName()).startTimer(); cmd.onCommand(event.getAuthor(), guild, event.getChannel(), event.getMessage(), args, event .getMember());
timer = Metrics.executionTime.labels(stack.getCommand().getClass().getSimpleName()).startTimer();
@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; } }
.name(FsImageCollector.METRIC_PREFIX + REPLICATION) .help("Overall file replication").create(); overallStats = new OverallStats(new HistogramMetricAdapter(overallHistogram.labels()), overallReplication); .buckets(configuredBuckets) .help("Per group file size distribution.").create(); createGroupStats = groupName -> new GroupStats(groupName, new HistogramMetricAdapter(histogram.labels(groupName))); groupFileSizeDistribution = histogram; .help("Per user file size distribution").create(); createUserStat = userName -> new UserStats(userName, new HistogramMetricAdapter(histogram.labels(userName)), new SummaryMetricAdapter(userReplication.labels(userName))); userFileSizeDistribution = histogram; .labelNames(FsImageCollector.LABEL_PATH) .help("Path specific file size distribution").create(); createPathStat = path -> new PathStats(path, new HistogramMetricAdapter(histogram.labels(path))); pathFileSizeDistribution = histogram; .labelNames(FsImageCollector.LABEL_PATH_SET) .help("Path set specific file size distribution").create(); createPathSetStat = path -> new PathStats(path, new HistogramMetricAdapter(histogram.labels(path))); pathSetFileSizeDistribution = histogram;