Search in sources :

Example 6 with GaugeMetricFamily

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;
}
Also used : ArrayList(java.util.ArrayList) CounterMetricFamily(io.prometheus.client.CounterMetricFamily) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GaugeMetricFamily(io.prometheus.client.GaugeMetricFamily)

Example 7 with GaugeMetricFamily

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);
}
Also used : CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker) GaugeMetricFamily(io.prometheus.client.GaugeMetricFamily)

Aggregations

GaugeMetricFamily (io.prometheus.client.GaugeMetricFamily)7 ArrayList (java.util.ArrayList)4 CounterMetricFamily (io.prometheus.client.CounterMetricFamily)2 CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)1 RateLimiter (io.github.resilience4j.ratelimiter.RateLimiter)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1