private void incCounterForStatusCode(int statusCode, List<String> labels, List<String> labelValues) { counter(REQUEST_TOTAL, labels).labels(labelValues.stream().toArray(String[]::new)).inc(); if(statusCode >= 200 && statusCode < 400) { counter(SUCCESS_TOTAL , labels).labels(labelValues.stream().toArray(String[]::new)).inc(); } else if(statusCode == 401 || statusCode == 403) { counter(AUTO_ERROR_TOTAL , labels).labels(labelValues.stream().toArray(String[]::new)).inc(); } else if(statusCode >= 400 && statusCode < 500) { counter(REQUEST_ERROR_TOTAL , labels).labels(labelValues.stream().toArray(String[]::new)).inc(); } else if(statusCode >= 500) { counter(SERVER_ERROR_TOTAL , labels).labels(labelValues.stream().toArray(String[]::new)).inc(); } }
@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 protected void append(LoggingEvent event) { switch (event.getLevel().toInt()) { case Level.TRACE_INT: TRACE_LABEL.inc(); break; case Level.DEBUG_INT: DEBUG_LABEL.inc(); break; case Level.INFO_INT: INFO_LABEL.inc(); break; case Level.WARN_INT: WARN_LABEL.inc(); break; case Level.ERROR_INT: ERROR_LABEL.inc(); break; case Level.FATAL_INT: FATAL_LABEL.inc(); break; default: break; } }
protected void doRequestsCtr(Counter ctr, RequestMetric metric) { ctr.labels(nullToEmpty(metric.getMethod(), Integer.toString(metric.getResponseCode()), metric.getApiId(), metric.getApiVersion(), metric.getClientId())).inc(); }
/** * @see io.apicurio.hub.api.metrics.IApiMetrics#accountLinkCompleted(io.apicurio.hub.api.beans.LinkedAccountType) */ @Override public void accountLinkCompleted(LinkedAccountType type) { accountLinksCompleted.labels(type.name()).inc(); } }
/** * @see io.apicurio.hub.api.metrics.IApiMetrics#apiImport(io.apicurio.hub.api.beans.LinkedAccountType) */ @Override public void apiImport(LinkedAccountType from) { if (from == null) { apisImported.labels("url"); } else { apisImported.labels(from.name()).inc(); } }
@Override public void recordConnectionTimeout() { connectionTimeoutCounter.inc(); } }
/** * @see io.apicurio.hub.editing.metrics.IEditingMetrics#editingSessionCreated(java.lang.String) */ @Override public void editingSessionCreated(String designId) { sessions.labels(designId).inc(); }
private void doFailureCtr(RequestMetric metric) { failureCtr.labels(nullToEmpty(metric.getMethod(), Integer.toString(metric.getResponseCode()), Integer.toString(metric.getFailureCode()), metric.getApiId(), metric.getApiVersion(), metric.getClientId())).inc(); }
counter.labels(memoryPool).inc(increase);
@Override protected void append(ILoggingEvent event) { switch (event.getLevel().toInt()) { case Level.TRACE_INT: TRACE_LABEL.inc(); break; case Level.DEBUG_INT: DEBUG_LABEL.inc(); break; case Level.INFO_INT: INFO_LABEL.inc(); break; case Level.WARN_INT: WARN_LABEL.inc(); break; case Level.ERROR_INT: ERROR_LABEL.inc(); break; default: break; } } }
/** * Increment the counter with no labels by the given amount. * @throws IllegalArgumentException If amt is negative. */ public void inc(double amt) { noLabelsChild.inc(amt); }
/** * Increment the counter by 1. */ public void inc() { inc(1); } /**
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleCounterIncBenchmark() { prometheusSimpleCounter.labels("test", "group").inc(); }
@Override public void append(LogEvent event) { Level level = event.getLevel(); if (TRACE.equals(level)) TRACE_LABEL.inc(); else if (DEBUG.equals(level)) DEBUG_LABEL.inc(); else if (INFO.equals(level)) INFO_LABEL.inc(); else if (WARN.equals(level)) WARN_LABEL.inc(); else if (ERROR.equals(level)) ERROR_LABEL.inc(); else if (FATAL.equals(level)) FATAL_LABEL.inc(); }
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleCounterChildIncBenchmark() { prometheusSimpleCounterChild.inc(); }
@Override public void recordConnectionTimeout() { connectionTimeoutCounterChild.inc(); } }
@Override public Timer startTimer() { final Histogram.Timer timer = histogram.startTimer(); totalCounter.inc(); return new Timer() { @Override public void onError() { errorCounter.inc(); } @Override public void onSuccess() { timer.observeDuration(); } }; } }
@Benchmark public void prometheusCounterWithTags(PrometheusState state) { state.counterWithTags.labels("value1", "value2").inc(); }
@Override public void onError() { errorCounter.inc(); }