mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-09 22:01:13 +00:00
Compare commits
5 Commits
66df771cb7
...
b1432c662f
Author | SHA1 | Date | |
---|---|---|---|
|
b1432c662f | ||
|
19fcc15fe1 | ||
|
b497c690af | ||
|
866fe19cb9 | ||
|
e21641da7b |
@@ -29,6 +29,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
|
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
|
||||||
implementation("ch.qos.logback:logback-classic:1.5.13")
|
implementation("ch.qos.logback:logback-classic:1.5.13")
|
||||||
|
implementation("com.github.loki4j:loki-logback-appender:2.0.0")
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
|
||||||
|
@@ -204,6 +204,7 @@ class UserHandler(
|
|||||||
val logger: Logger,
|
val logger: Logger,
|
||||||
private var user: User,
|
private var user: User,
|
||||||
var streamStartTime: LocalDateTime?,
|
var streamStartTime: LocalDateTime?,
|
||||||
|
val chatLogger: Logger = LoggerFactory.getLogger("${channel.channelName}-chat"),
|
||||||
) {
|
) {
|
||||||
lateinit var client: ChzzkClient
|
lateinit var client: ChzzkClient
|
||||||
lateinit var chatChannelId: String
|
lateinit var chatChannelId: String
|
||||||
@@ -294,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
|
||||||
@@ -331,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(
|
||||||
@@ -370,6 +371,7 @@ class UserHandler(
|
|||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
delay(100L)
|
delay(100L)
|
||||||
client.sendChatToLoggedInChannel(msg.limitUtf8Length(100))
|
client.sendChatToLoggedInChannel(msg.limitUtf8Length(100))
|
||||||
|
chatLogger.info("[SEND]${channel.channelName}: ${msg.limitUtf8Length(100)}{${msg.length} / 100}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ class MessageHandler(
|
|||||||
|
|
||||||
private val channel = handler.channel
|
private val channel = handler.channel
|
||||||
private val logger = handler.logger
|
private val logger = handler.logger
|
||||||
|
private val chatLogger = handler.chatLogger
|
||||||
private val listener = handler.listener
|
private val listener = handler.listener
|
||||||
|
|
||||||
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||||
@@ -372,7 +373,7 @@ class MessageHandler(
|
|||||||
|
|
||||||
internal fun handle(msg: SessionChatMessage, user: User) {
|
internal fun handle(msg: SessionChatMessage, user: User) {
|
||||||
if(msg.senderChannelId == ChzzkHandler.botUid) return
|
if(msg.senderChannelId == ChzzkHandler.botUid) return
|
||||||
|
chatLogger.info("[RECV]${channel.channelName}: ${msg.content}{${msg.content.length} / 100}")
|
||||||
val commandKey = msg.content.split(' ')[0]
|
val commandKey = msg.content.split(' ')[0]
|
||||||
commands[commandKey.lowercase()]?.let { it(msg, user) }
|
commands[commandKey.lowercase()]?.let { it(msg, user) }
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
|
<property name="lokiUrl" value="${LOKI_ENDPOINT}"/>
|
||||||
<!-- 콘솔에 출력하는 기본 로그 설정 -->
|
<!-- 콘솔에 출력하는 기본 로그 설정 -->
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
@@ -10,6 +10,15 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
|
||||||
|
<http>
|
||||||
|
<url>${lokiUrl}</url>
|
||||||
|
</http>
|
||||||
|
<labels>
|
||||||
|
app = chibot-chzzk-bot
|
||||||
|
</labels>
|
||||||
|
</appender>
|
||||||
|
|
||||||
<!-- HikariCP 로그 레벨 설정 -->
|
<!-- HikariCP 로그 레벨 설정 -->
|
||||||
<logger name="com.zaxxer.hikari" level="INFO" />
|
<logger name="com.zaxxer.hikari" level="INFO" />
|
||||||
<logger name="o.m.jdbc.client.impl.StandardClient" level="INFO" />
|
<logger name="o.m.jdbc.client.impl.StandardClient" level="INFO" />
|
||||||
@@ -31,5 +40,8 @@
|
|||||||
<root level="DEBUG">
|
<root level="DEBUG">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
</root>
|
</root>
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="LOKI" />
|
||||||
|
</root>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
@@ -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