Search in sources :

Example 1 with CounterMetricFamily

use of io.prometheus.client.CounterMetricFamily in project FredBoat by Frederikam.

the class FredBoatCollector method collect.

@Override
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<>();
    List<String> labelNames = Arrays.asList("shard", "entity");
    GaugeMetricFamily jdaEntities = new GaugeMetricFamily("fredboat_jda_entities", "Amount of JDA entities", labelNames);
    mfs.add(jdaEntities);
    GaugeMetricFamily playersPlaying = new GaugeMetricFamily("fredboat_playing_music_players", "Currently playing music players", labelNames);
    mfs.add(playersPlaying);
    CounterMetricFamily dockerPulls = new CounterMetricFamily("fredboat_docker_pulls", "Total fredboat docker image pulls as reported by the docker hub.", labelNames);
    mfs.add(dockerPulls);
    // global stats
    jdaEntities.addMetric(Arrays.asList("total", "User"), botMetrics.getTotalUniqueUsersCount());
    jdaEntities.addMetric(Arrays.asList("total", "Guild"), botMetrics.getTotalGuildsCount());
    jdaEntities.addMetric(Arrays.asList("total", "TextChannel"), botMetrics.getTotalTextChannelsCount());
    jdaEntities.addMetric(Arrays.asList("total", "VoiceChannel"), botMetrics.getTotalVoiceChannelsCount());
    jdaEntities.addMetric(Arrays.asList("total", "Category"), botMetrics.getTotalCategoriesCount());
    jdaEntities.addMetric(Arrays.asList("total", "Emote"), botMetrics.getTotalEmotesCount());
    jdaEntities.addMetric(Arrays.asList("total", "Role"), botMetrics.getTotalRolesCount());
    playersPlaying.addMetric(Arrays.asList("total", "Players"), playerRegistry.playingCount());
    // docker stats
    int dockerPullsBotCount = botMetrics.getDockerPullsBot();
    if (dockerPullsBotCount > 0) {
        dockerPulls.addMetric(Arrays.asList("total", "Bot"), dockerPullsBotCount);
    }
    int dockerPullsDbCount = botMetrics.getDockerPullsDb();
    if (dockerPullsDbCount > 0) {
        dockerPulls.addMetric(Arrays.asList("total", "Db"), dockerPullsDbCount);
    }
    // per shard stats
    shardProvider.streamShards().forEach(shard -> {
        String shardId = Integer.toString(shard.getShardInfo().getShardId());
        jdaEntities.addMetric(Arrays.asList(shardId, "User"), shard.getUserCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "Guild"), shard.getGuildCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "TextChannel"), shard.getTextChannelCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "VoiceChannel"), shard.getVoiceChannelCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "Category"), shard.getCategoryCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "Emote"), shard.getEmoteCache().size());
        jdaEntities.addMetric(Arrays.asList(shardId, "Role"), shard.getRoleCache().size());
    });
    return mfs;
}
Also used : ArrayList(java.util.ArrayList) CounterMetricFamily(io.prometheus.client.CounterMetricFamily) GaugeMetricFamily(io.prometheus.client.GaugeMetricFamily)

Example 2 with CounterMetricFamily

use of io.prometheus.client.CounterMetricFamily 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)

Aggregations

CounterMetricFamily (io.prometheus.client.CounterMetricFamily)2 GaugeMetricFamily (io.prometheus.client.GaugeMetricFamily)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1