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;
}
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;
}
Aggregations