使用 Prometheus 计算 DAU 和 MAU

Calculating DAU and MAU using Prometheus

我的任务是使用 Prometheus 作为数据存储来实现 DAU 和 MAU 指标。

为了做到这一点,我创建了计数器 active_users

Counter activeUsers = new Counter().build().name("active_users").labelNames("username").register();

并且在每个新连接上我都这样做

activeUsers.labels(user.name).inc();

我的问题是如何向 Prometheus 写入查询以从 active_users 时间序列中提取 DAU 和 MAU?如何计算 distinct username 在 24 hours/30 天 window 内的增量?

Prometheus 并不是真正适用于此的工具,因为它更多地是关于系统级指标而不是单个请求的指标。我建议通过像 ELK 堆栈这样的事件日志系统来执行此操作。