mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-30 06:37:29 +00:00
feat(metrics): 指标信息增加 bot_id label.
由于 bot_name 不能作为机器人的唯一标识, 因此增加 bot_id 为监控平台提供唯一标识.
This commit is contained in:
parent
d3e18d80ca
commit
3ea0f4eacb
@ -50,6 +50,8 @@ internal class ScalaBot(
|
|||||||
extensionFinders = extensionFinders
|
extensionFinders = extensionFinders
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val accountIdString = accountId.toString()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
log.info { "[Bot $botUsername] 正在加载扩展..." }
|
log.info { "[Bot $botUsername] 正在加载扩展..." }
|
||||||
val extensionEntries = extensionLoader.getExtensions()
|
val extensionEntries = extensionLoader.getExtensions()
|
||||||
@ -66,18 +68,18 @@ internal class ScalaBot(
|
|||||||
override fun creatorId(): Long = creatorId
|
override fun creatorId(): Long = creatorId
|
||||||
|
|
||||||
override fun onUpdateReceived(update: Update?) {
|
override fun onUpdateReceived(update: Update?) {
|
||||||
botUpdateCounter.labels(botUsername).inc()
|
botUpdateCounter.labels(botUsername, accountIdString).inc()
|
||||||
botUpdateGauge.labels(botUsername).inc()
|
botUpdateGauge.labels(botUsername, accountIdString).inc()
|
||||||
|
|
||||||
val timer = updateProcessTime.labels(botUsername).startTimer()
|
val timer = updateProcessTime.labels(botUsername, accountIdString).startTimer()
|
||||||
try {
|
try {
|
||||||
super.onUpdateReceived(update)
|
super.onUpdateReceived(update)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
exceptionHandlingCounter.labels(botUsername).inc()
|
exceptionHandlingCounter.labels(botUsername, accountIdString).inc()
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
timer.observeDuration()
|
timer.observeDuration()
|
||||||
botUpdateGauge.labels(botUsername).dec()
|
botUpdateGauge.labels(botUsername, accountIdString).dec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +136,7 @@ internal class ScalaBot(
|
|||||||
private val botUpdateCounter = Counter.build()
|
private val botUpdateCounter = Counter.build()
|
||||||
.name("updates_total")
|
.name("updates_total")
|
||||||
.help("Total number of updates received by all bots.")
|
.help("Total number of updates received by all bots.")
|
||||||
.labelNames("bot_name")
|
.labelNames("bot_name", "bot_id")
|
||||||
.namespace(Const.METRICS_NAMESPACE)
|
.namespace(Const.METRICS_NAMESPACE)
|
||||||
.subsystem("telegrambots")
|
.subsystem("telegrambots")
|
||||||
.register()
|
.register()
|
||||||
@ -143,7 +145,7 @@ internal class ScalaBot(
|
|||||||
private val botUpdateGauge = Gauge.build()
|
private val botUpdateGauge = Gauge.build()
|
||||||
.name("updates_in_progress")
|
.name("updates_in_progress")
|
||||||
.help("Number of updates in process by all bots.")
|
.help("Number of updates in process by all bots.")
|
||||||
.labelNames("bot_name")
|
.labelNames("bot_name", "bot_id")
|
||||||
.namespace(Const.METRICS_NAMESPACE)
|
.namespace(Const.METRICS_NAMESPACE)
|
||||||
.subsystem("telegrambots")
|
.subsystem("telegrambots")
|
||||||
.register()
|
.register()
|
||||||
@ -164,7 +166,7 @@ internal class ScalaBot(
|
|||||||
"so it may be different from the actual execution time of ability. " +
|
"so it may be different from the actual execution time of ability. " +
|
||||||
"It is not recommended to use it as the accurate execution time of ability)"
|
"It is not recommended to use it as the accurate execution time of ability)"
|
||||||
)
|
)
|
||||||
.labelNames("bot_name")
|
.labelNames("bot_name", "bot_id")
|
||||||
.namespace(Const.METRICS_NAMESPACE)
|
.namespace(Const.METRICS_NAMESPACE)
|
||||||
.subsystem("telegrambots")
|
.subsystem("telegrambots")
|
||||||
.register()
|
.register()
|
||||||
@ -173,7 +175,7 @@ internal class ScalaBot(
|
|||||||
private val exceptionHandlingCounter = Counter.build()
|
private val exceptionHandlingCounter = Counter.build()
|
||||||
.name("updates_exception_handling")
|
.name("updates_exception_handling")
|
||||||
.help("Number of exceptions during processing.")
|
.help("Number of exceptions during processing.")
|
||||||
.labelNames("bot_name")
|
.labelNames("bot_name", "bot_id")
|
||||||
.namespace(Const.METRICS_NAMESPACE)
|
.namespace(Const.METRICS_NAMESPACE)
|
||||||
.subsystem("telegrambots")
|
.subsystem("telegrambots")
|
||||||
.register()
|
.register()
|
||||||
|
Loading…
Reference in New Issue
Block a user