use of io.prometheus.client.GaugeMetricFamily in project FredBoat by Frederikam.
the class ThreadPoolCollector method collect.
@Override
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> mfs = new ArrayList<>();
List<String> labelNames = Collections.singletonList("name");
GaugeMetricFamily activeThreads = new GaugeMetricFamily("fredboat_threadpool_active_threads_current", "Amount of active threads in a thread pool", labelNames);
mfs.add(activeThreads);
GaugeMetricFamily queueSize = new GaugeMetricFamily("fredboat_threadpool_queue_size_current", "Size of queue of a thread pool (including scheduled tasks)", labelNames);
mfs.add(queueSize);
CounterMetricFamily completedTasks = new CounterMetricFamily("fredboat_threadpool_completed_tasks_total", "Total completed tasks by a thread pool", labelNames);
mfs.add(completedTasks);
for (Map.Entry<String, ThreadPoolExecutor> entry : pools.entrySet()) {
String poolName = entry.getKey();
ThreadPoolExecutor pool = entry.getValue();
List<String> labels = Collections.singletonList(poolName);
activeThreads.addMetric(labels, pool.getActiveCount());
queueSize.addMetric(labels, pool.getQueue().size());
// guaranteed to always increase, ergo good fit for a counter
completedTasks.addMetric(labels, pool.getCompletedTaskCount());
}
return mfs;
}
use of io.prometheus.client.GaugeMetricFamily in project resilience4j by resilience4j.
the class CircuitBreakerExports method collect.
/**
* {@inheritDoc}
*/
@Override
public List<MetricFamilySamples> collect() {
final GaugeMetricFamily states = new GaugeMetricFamily(prefix + "_states", "Circuit Breaker States", asList("name", "state"));
final GaugeMetricFamily calls = new GaugeMetricFamily(prefix + "_calls", "Circuit Breaker Call Stats", asList("name", "call_result"));
for (CircuitBreaker circuitBreaker : circuitBreakersSupplier.get()) {
STATE_NAME_MAP.forEach(e -> {
final CircuitBreaker.State state = e._1;
final String name = e._2;
final double value = state == circuitBreaker.getState() ? 1.0 : 0.0;
states.addMetric(asList(circuitBreaker.getName(), name), value);
});
final CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics();
calls.addMetric(asList(circuitBreaker.getName(), "successful"), metrics.getNumberOfSuccessfulCalls());
calls.addMetric(asList(circuitBreaker.getName(), "failed"), metrics.getNumberOfFailedCalls());
calls.addMetric(asList(circuitBreaker.getName(), "not_permitted"), metrics.getNumberOfNotPermittedCalls());
calls.addMetric(asList(circuitBreaker.getName(), "buffered"), metrics.getNumberOfBufferedCalls());
calls.addMetric(asList(circuitBreaker.getName(), "buffered_max"), metrics.getMaxNumberOfBufferedCalls());
}
return asList(calls, states);
}
Aggregations