1
0
mirror of https://github.com/sadfsdfdsa/allbot.git synced 2024-11-19 00:31:42 +02:00

feat(infra): prometheus metrics improvements

This commit is contained in:
Artem Shuvaev 2023-11-11 16:40:47 +05:00
parent bd5b875fb7
commit 88014e074c
8 changed files with 58 additions and 32 deletions

View File

@ -333,10 +333,6 @@ Commands:
withPayments: String(includePay),
})
this.metricsService.replyCounter.inc({
chatId: 'all_chats',
})
ctx.reply(msg, {
reply_to_message_id: messageId,
})

View File

@ -45,7 +45,6 @@ export class CacheService {
if (arr.length < this.MAX_CACHE_SIZE) return
this.metricsService.cacheCounter.reset()
this.metricsService.teamsCacheCounter.reset()
const date = new Date()
this.metricsService.cacheClearingCounter.inc({
@ -67,13 +66,8 @@ export class CacheService {
chatId: chatId.toString(),
})
this.metricsService.cacheCounter.inc({
chatId: 'all_chats',
})
if (!this.cachedChats.has(chatId)) {
this.cachedChats.set(chatId, new Set())
this.metricsService.teamsCacheCounter.inc()
}
this.cachedChats.get(chatId)?.add(username)

View File

@ -12,8 +12,6 @@ export class MetricsService {
public readonly cacheCounter: Counter
public readonly teamsCacheCounter: Counter
public readonly cacheClearingCounter: Counter
public readonly groupsCounter: Counter
@ -56,12 +54,6 @@ export class MetricsService {
})
this.registry.registerMetric(this.cacheCounter)
this.teamsCacheCounter = new Counter({
name: 'allbot_teams_cache',
help: 'The number of total teams in cache right now',
})
this.registry.registerMetric(this.teamsCacheCounter)
this.groupsCounter = new Counter({
name: 'allbot_groups',
help: 'The number of new added/deleted groups',

3
dist/core/bot.js vendored
View File

@ -232,9 +232,6 @@ Commands:
chatId: chatId.toString(),
withPayments: String(includePay),
});
this.metricsService.replyCounter.inc({
chatId: 'all_chats',
});
ctx.reply(msg, {
reply_to_message_id: messageId,
});

5
dist/core/cache.js vendored
View File

@ -34,7 +34,6 @@ export class CacheService {
if (arr.length < this.MAX_CACHE_SIZE)
return;
this.metricsService.cacheCounter.reset();
this.metricsService.teamsCacheCounter.reset();
const date = new Date();
this.metricsService.cacheClearingCounter.inc({
time: date.toLocaleString('ru-RU', { timeZone: 'Asia/Yekaterinburg' }),
@ -48,12 +47,8 @@ export class CacheService {
this.metricsService.cacheCounter.inc({
chatId: chatId.toString(),
});
this.metricsService.cacheCounter.inc({
chatId: 'all_chats',
});
if (!this.cachedChats.has(chatId)) {
this.cachedChats.set(chatId, new Set());
this.metricsService.teamsCacheCounter.inc();
}
this.cachedChats.get(chatId)?.add(username);
const size = this.cachedChats.get(chatId)?.size ?? 0;

View File

@ -7,7 +7,6 @@ export class MetricsService {
registry;
replyCounter;
cacheCounter;
teamsCacheCounter;
cacheClearingCounter;
groupsCounter;
commandsCounter;
@ -37,11 +36,6 @@ export class MetricsService {
labelNames: ['chatId'],
});
this.registry.registerMetric(this.cacheCounter);
this.teamsCacheCounter = new Counter({
name: 'allbot_teams_cache',
help: 'The number of total teams in cache right now',
});
this.registry.registerMetric(this.teamsCacheCounter);
this.groupsCounter = new Counter({
name: 'allbot_groups',
help: 'The number of new added/deleted groups',

41
docker-compose.yml Normal file
View File

@ -0,0 +1,41 @@
version: '3.8'
networks:
monitoring:
driver: bridge
volumes:
prometheus_data: {}
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: unless-stopped
volumes:
- ./infra/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
ports:
- 9090:9090
networks:
- monitoring
grafana:
image: grafana/grafana
container_name: grafana
ports:
- 3000:3000
restart: unless-stopped
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- ./grafana:/etc/grafana/provisioning/datasources
networks:
- monitoring

17
infra/prometheus.yml Normal file
View File

@ -0,0 +1,17 @@
global:
scrape_interval: 1m # By default, scrape targets every 15 seconds.
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'allbot'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 1m
metrics_path: "/metrics"
scheme: "http"
static_configs:
- targets: ['allbot-vartose.eu-4.evennode.com']