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(); } }
@Benchmark public void prometheusCounterWithTags(PrometheusState state) { state.counterWithTags.labels("value1", "value2").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; } }
PrometheusMetricsTracker(String poolName, CollectorRegistry collectorRegistry) { registerMetrics(collectorRegistry); this.connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labels(poolName); this.elapsedAcquiredSummaryChild = ELAPSED_ACQUIRED_SUMMARY.labels(poolName); this.elapsedBorrowedSummaryChild = ELAPSED_BORROWED_SUMMARY.labels(poolName); this.elapsedCreationSummaryChild = ELAPSED_CREATION_SUMMARY.labels(poolName); }
counter.labels(memoryPool).inc(increase);
@Benchmark @BenchmarkMode({Mode.AverageTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public void prometheusSimpleCounterIncBenchmark() { prometheusSimpleCounter.labels("test", "group").inc(); }
@Setup public void setup() { prometheusCounter = io.prometheus.client.metrics.Counter.newBuilder() .name("name") .documentation("some description..") .build(); prometheusCounterChild = prometheusCounter.newPartial().apply(); prometheusSimpleCounter = io.prometheus.client.Counter.build() .name("name") .help("some description..") .labelNames("some", "group").create(); prometheusSimpleCounterChild = prometheusSimpleCounter.labels("test", "group"); prometheusSimpleCounterNoLabels = io.prometheus.client.Counter.build() .name("name") .help("some description..") .create(); registry = new MetricRegistry(); codahaleCounter = registry.counter("counter"); codahaleMeter = registry.meter("meter"); }
/** * @see io.apicurio.hub.editing.metrics.IEditingMetrics#editingSessionCreated(java.lang.String) */ @Override public void editingSessionCreated(String designId) { sessions.labels(designId).inc(); }
/** * @see io.apicurio.hub.api.metrics.IApiMetrics#apiCreate(java.lang.String) */ @Override public void apiCreate(String specVersion) { apisCreated.labels(specVersion).inc(); }
/** * @see io.apicurio.hub.editing.metrics.IEditingMetrics#socketConnected(java.lang.String, java.lang.String) */ @Override public void socketConnected(String designId, String user) { sockets.labels(designId, user).inc(); }
/** * @see io.apicurio.hub.editing.metrics.IEditingMetrics#contentCommand(java.lang.String) */ @Override public void contentCommand(String designId) { commands.labels(designId).inc(); }
/** * @see io.apicurio.hub.api.metrics.IApiMetrics#accountLinkInitiated(io.apicurio.hub.api.beans.LinkedAccountType) */ @Override public void accountLinkInitiated(LinkedAccountType type) { accountLinksInitiated.labels(type.name()).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(); } }
public boolean registerIntent(Intent intent) { if (!isEnabled()) { return false; } Metrics.aiRequestsExecuted.labels(intent.getClass().getSimpleName()).inc(0D); intents.put(new IntentAction(intent.getAction()), intent); return true; }
@Override public Counter newCounter(Meter.Id id) { io.prometheus.client.Counter counter = collectorByName(io.prometheus.client.Counter.class, id.getConventionName(), n -> buildCollector(id, io.prometheus.client.Counter.build())); return new PrometheusCounter(id, counter.labels(id.getConventionTags().stream() .map(Tag::getValue) .collect(Collectors.toList()) .toArray(new String[]{}))); }
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(); }
protected void doRequestsCtr(Counter ctr, RequestMetric metric) { ctr.labels(nullToEmpty(metric.getMethod(), Integer.toString(metric.getResponseCode()), metric.getApiId(), metric.getApiVersion(), metric.getClientId())).inc(); }
protected void doRequestsCtr(Counter ctr, RequestMetric metric) { ctr.labels(nullToEmpty(metric.getMethod(), Integer.toString(metric.getResponseCode()), metric.getApiId(), metric.getApiVersion(), metric.getClientId())).inc(); }