mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-08 05:11:12 +00:00
[feature] metric related fixed.
This commit is contained in:
@@ -295,7 +295,7 @@ class UserHandler(
|
|||||||
|
|
||||||
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
|
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
|
||||||
streamStartTime = LocalDateTime.now()
|
streamStartTime = LocalDateTime.now()
|
||||||
Metrics.streaming++
|
Metrics.increaseStreaming()
|
||||||
|
|
||||||
if(!_isActive) {
|
if(!_isActive) {
|
||||||
_isActive = true
|
_isActive = true
|
||||||
@@ -332,7 +332,7 @@ class UserHandler(
|
|||||||
listener?.unsubscribeAsync(ChzzkSessionSubscriptionType.CHAT)?.join()
|
listener?.unsubscribeAsync(ChzzkSessionSubscriptionType.CHAT)?.join()
|
||||||
listener?.disconnectAsync()?.join()
|
listener?.disconnectAsync()?.join()
|
||||||
_isActive = false
|
_isActive = false
|
||||||
Metrics.streaming--;
|
Metrics.decreaseStreaming()
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
val events = listOf(
|
val events = listOf(
|
||||||
|
@@ -8,12 +8,12 @@ import space.mori.chzzk_bot.common.services.UserService
|
|||||||
object Metrics {
|
object Metrics {
|
||||||
val registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
|
val registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
|
||||||
|
|
||||||
var streamer = UserService.getAllUsers().size.toDouble()
|
var streamer = 0.0
|
||||||
val streamerGauge: Gauge = Gauge.builder("streamer_gauge", this) { streamer }
|
val streamerGauge: Gauge = Gauge.builder("streamer_gauge", this) { streamer }
|
||||||
.description("Current All Streamer Count")
|
.description("Current All Streamer Count")
|
||||||
.register(registry)
|
.register(registry)
|
||||||
|
|
||||||
var activeStreamer = UserService.getAllUsers().filter { !it.isDisabled }.size.toDouble()
|
var activeStreamer = 0.0
|
||||||
val activateGauge: Gauge = Gauge.builder("active_streamer_gauge", this) { streamer }
|
val activateGauge: Gauge = Gauge.builder("active_streamer_gauge", this) { streamer }
|
||||||
.description("Current Active Streamer Count")
|
.description("Current Active Streamer Count")
|
||||||
.register(registry)
|
.register(registry)
|
||||||
@@ -22,4 +22,16 @@ object Metrics {
|
|||||||
val streamingGauge: Gauge = Gauge.builder("streaming_gauge", this) { streaming }
|
val streamingGauge: Gauge = Gauge.builder("streaming_gauge", this) { streaming }
|
||||||
.description("Current Streaming Streamer Count")
|
.description("Current Streaming Streamer Count")
|
||||||
.register(registry)
|
.register(registry)
|
||||||
|
|
||||||
|
fun refreshStreamerMetrics() {
|
||||||
|
streamer = UserService.getAllUsers().size.toDouble()
|
||||||
|
activeStreamer = UserService.getAllUsers().filter { !it.isDisabled }.size.toDouble()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun increaseStreaming(inc: Int = 1) {
|
||||||
|
streaming += inc
|
||||||
|
}
|
||||||
|
fun decreaseStreaming(dec: Int = 1) {
|
||||||
|
streaming -= dec
|
||||||
|
}
|
||||||
}
|
}
|
@@ -16,7 +16,7 @@ import kotlinx.coroutines.CompletableDeferred
|
|||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import space.mori.chzzk_bot.common.events.ChzzkUserFindEvent
|
import space.mori.chzzk_bot.common.events.ChzzkUserFindEvent
|
||||||
import space.mori.chzzk_bot.common.events.ChzzkUserReceiveEvent
|
import space.mori.chzzk_bot.common.events.ChzzkUserReceiveEvent
|
||||||
import space.mori.chzzk_bot.webserver.routes.GuildSettings
|
import space.mori.chzzk_bot.common.metrics.Metrics
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetUserDTO(
|
data class GetUserDTO(
|
||||||
@@ -184,6 +184,8 @@ fun Routing.apiRoutes() {
|
|||||||
UserService.setIsDisabled(user, body.isBotDisabled)
|
UserService.setIsDisabled(user, body.isBotDisabled)
|
||||||
UserService.setIsStartupDisabled(user, body.isBotMsgDisabled)
|
UserService.setIsStartupDisabled(user, body.isBotMsgDisabled)
|
||||||
|
|
||||||
|
Metrics.refreshStreamerMetrics()
|
||||||
|
|
||||||
call.respond(HttpStatusCode.OK, body)
|
call.respond(HttpStatusCode.OK, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ fun Routing.metricRoutes() {
|
|||||||
val registry: PrometheusMeterRegistry by inject(PrometheusMeterRegistry::class.java)
|
val registry: PrometheusMeterRegistry by inject(PrometheusMeterRegistry::class.java)
|
||||||
|
|
||||||
dispatcher.subscribe(UserRegisterEvent::class) {
|
dispatcher.subscribe(UserRegisterEvent::class) {
|
||||||
Metrics.streamer++
|
Metrics.refreshStreamerMetrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/metrics") {
|
get("/metrics") {
|
||||||
|
Reference in New Issue
Block a user