monitor mod queue stats with grafana

This commit is contained in:
Thibault Duplessis
2026-05-06 12:38:54 +02:00
parent 73be33a28d
commit 869bc73962
5 changed files with 48 additions and 2 deletions
+4 -1
View File
@@ -9,10 +9,13 @@ final class Env(
db: lila.db.Db,
userRepo: lila.core.user.UserRepo,
cacheApi: lila.memo.CacheApi
)(using Executor):
)(using Executor)(using scheduler: Scheduler):
private val coll = db(CollName("appeal"))
private lazy val snoozer = lila.memo.Snoozer[Appeal.SnoozeKey]("appeal.snooze", cacheApi)
lazy val api: AppealApi = wire[AppealApi]
scheduler.scheduleWithFixedDelay(55.minutes, 1.day): () =>
api.countUnread.foreach(lila.mon.mod.queueStatus("appeal", 40).update(_))
-1
View File
@@ -80,7 +80,6 @@ final class ModQueueStats(
object ModQueueStats:
type Score = Int
type Nb = Int
val scores = List[Score](20, 40, 60, 80)
+3
View File
@@ -256,6 +256,9 @@ object user:
object actor:
def queueSize(name: String) = gauge("trouper.queueSize").withTag("name", name)
object mod:
def queueStatus(room: String, score: Int) =
gauge("mod.queueStatus").withTags:
tags("room" -> room, "score" -> score)
object report:
val highest = gauge("mod.report.highest").withoutTags()
def close(mod: UserId, room: String) = counter("mod.report.close").withTags:
+3
View File
@@ -51,5 +51,8 @@ final class Env(
scheduler.scheduleWithFixedDelay(1.minute, 1.minute): () =>
api.inquiries.expire
scheduler.scheduleWithFixedDelay(55.minutes, 1.day): () =>
ReportQueueMonitor.push(reportColl)
lila.common.Bus.sub[lila.core.playban.Playban]:
case lila.core.playban.Playban(userId, mins, _) => api.maybeAutoPlaybanReport(userId, mins)
@@ -0,0 +1,38 @@
package lila.report
import lila.db.dsl.*
private object ReportQueueMonitor:
def push(reportColl: Coll)(using Executor): Unit =
reportColl
.aggregateList(50): framework =>
import framework.*
Match($doc("open" -> true, "score" -> $doc("$gte" -> 20))) -> List(
Group(
$arr(
"$room",
$doc(
"$min" -> $arr(
80,
$doc("$multiply" -> $arr(20, $doc("$floor" -> $doc("$divide" -> $arr("$score", 20)))))
)
)
)
)("nb" -> SumAll),
Project(
$doc(
"_id" -> 0,
"room" -> $doc("$first" -> "$_id"),
"score" -> $doc("$last" -> "$_id"),
"nb" -> 1
)
)
)
.map: docs =>
for
doc <- docs
room <- doc.string("room")
nb <- doc.int("nb")
score <- doc.int("score")
do lila.mon.mod.queueStatus(room, score).update(nb)