@Override public void onError() { collectors.errorCounter.inc(); }
private Counter counter(String name, List<String> labels) { String key = sanitizeName(name); return counters.computeIfAbsent(key, k-> Counter.build().name(k).help(k).labelNames(labels.stream().toArray(String[]::new)).register(registry)); }
@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"); }
public Counter.Child addCounter(String subsystem, String metric, String helpDoc, SortedMap<String, String> labels) { lock.writeLock().lock(); try { String name = name(subsystem, metric); Counter counter = counters.get(name); if (counter == null) { counter = Counter.build().name(name(subsystem, metric)).help(helpDoc). labelNames(labels.keySet().toArray(new String[]{})).create(); counter.register(registry); counters.put(name, counter); } return counter.labels(labels.values().toArray(new String[]{})); } finally { lock.writeLock().unlock(); } }
public void handleUnsubscribeMessage(UnsubscribeMessage unsubscribeMessage) { try { List<String> topicFilterSet = unsubscribeMessage.topicFilters(); for (String topicFilter : topicFilterSet) { if(subscriptions!=null) { subscriptions.remove(topicFilter); matchingSubscriptionsCache.clear(); PromMetrics.mqtt_unsubscribe_total.inc(); PromMetrics.mqtt_unsubscribe.labels(topicFilter).inc(); } } } catch(Throwable e) { logger.error(e.getMessage()); } }
protected void createAssertionCollector(){ if (!collectAssertions){ return; } String[] labelNames = new String[]{}; if (SampleEvent.getVarCount() > 0) { labelNames = this.combineAssertionLabelsWithSampleVars(); }else { labelNames = this.assertionConfig.getLabels(); } if(this.getSaveConfig().getAssertionClass().equals(Summary.class)) this.assertionsCollector = Summary.build().name("jmeter_assertions_total").help("Counter for assertions") .labelNames(labelNames).quantile(0.5, 0.1).quantile(0.99, 0.1) .create().register(CollectorRegistry.defaultRegistry); else if(this.getSaveConfig().getAssertionClass().equals(Counter.class)) this.assertionsCollector = Counter.build().name("jmeter_assertions_total").help("Counter for assertions") .labelNames(labelNames).create().register(CollectorRegistry.defaultRegistry); }
@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; }
@Override public List<MetricFamilySamples> collect() { return allocatedCounter.collect(); }
/** * Create a new instrumented appender using the default registry. */ public LogbackMetricsAppender(CollectorRegistry registry) { Counter counter = Counter.build().name("logback_appender_total") .help("Logback log statements at various log levels") .labelNames("level") .register(registry); traceLabel = counter.labels("trace"); debugLabel = counter.labels("debug"); infoLabel = counter.labels("info"); warnLabel = counter.labels("warn"); errorLabel = counter.labels("error"); }
private void registerMetrics(CollectorRegistry collectorRegistry){ CONNECTION_TIMEOUT_COUNTER.register(collectorRegistry); ELAPSED_ACQUIRED_SUMMARY.register(collectorRegistry); ELAPSED_BORROWED_SUMMARY.register(collectorRegistry); ELAPSED_CREATION_SUMMARY.register(collectorRegistry); }
@Override public List<MetricFamilySamples> collect() { return allocatedCounter.collect(); }
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(); } }
public void prometheusCounter(PrometheusState state) { state.counter.inc(); }
@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[]{}))); }
public PrometheusCounter register(CollectorRegistry registry) { counter.register(registry); return this; } }
public List<Collector.MetricFamilySamples> collect() { return counter.collect(); }
@Benchmark public void prometheusCounterWithTags(PrometheusState state) { state.counterWithTags.labels("value1", "value2").inc(); }
@Override public Timer startTimer() { final Histogram.Timer timer = collectors.histogram.startTimer(); collectors.totalCounter.inc(); return new Timer() { @Override public void onError() { collectors.errorCounter.inc(); } @Override public void onSuccess() { timer.observeDuration(); } }; }