mirror of
https://github.com/lichess-org/lila.git
synced 2026-05-26 13:51:00 +00:00
monitor mod queue stats with grafana
This commit is contained in:
@@ -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(_))
|
||||
|
||||
@@ -80,7 +80,6 @@ final class ModQueueStats(
|
||||
object ModQueueStats:
|
||||
|
||||
type Score = Int
|
||||
type Nb = Int
|
||||
|
||||
val scores = List[Score](20, 40, 60, 80)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user