Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로메테우스 설정 추가 #13

Open
wants to merge 1 commit into
base: lecture/operation-01-start
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ val h2_version: String by project
val hikaricp_version: String by project
val koin_version: String by project
val jbcrypt_version: String by project
val prometeus_version: String by project

plugins {
kotlin("jvm") version "1.9.23"
Expand Down Expand Up @@ -37,6 +38,7 @@ dependencies {
implementation("io.ktor:ktor-server-sessions-jvm")
implementation("io.ktor:ktor-server-auth-jvm")
implementation("io.ktor:ktor-server-status-pages-jvm")
implementation("io.ktor:ktor-server-metrics-micrometer-jvm")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("org.jetbrains.exposed:exposed-core:$exposed_version")
Expand All @@ -47,6 +49,7 @@ dependencies {
implementation("io.insert-koin:koin-ktor:$koin_version")
implementation("io.insert-koin:koin-logger-slf4j:$koin_version")
implementation("org.mindrot:jbcrypt:$jbcrypt_version")
implementation("io.micrometer:micrometer-registry-prometheus:$prometeus_version")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ h2_version=2.1.214
hikaricp_version=5.1.0
koin_version=3.5.0
jbcrypt_version=0.4
prometeus_version=1.6.3
2 changes: 2 additions & 0 deletions src/main/kotlin/com/example/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.example.config.configureDependencyInjection
import com.example.config.configureErrorHandling
import com.example.config.configureHttp
import com.example.config.configureLogging
import com.example.config.configureMonitoring
import com.example.config.configureRouting
import com.example.config.configureSecurity
import com.example.config.configureSerialization
Expand All @@ -28,4 +29,5 @@ fun Application.module() {
configureRouting()
configureErrorHandling()
configureLogging()
configureMonitoring()
}
31 changes: 31 additions & 0 deletions src/main/kotlin/com/example/config/Monitoring.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.config

import io.ktor.server.application.*
import io.ktor.server.metrics.micrometer.*
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics
import io.micrometer.core.instrument.binder.system.ProcessorMetrics
import io.micrometer.core.instrument.binder.system.UptimeMetrics
import io.micrometer.prometheus.PrometheusConfig
import io.micrometer.prometheus.PrometheusMeterRegistry


val appMicrometerRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
fun Application.configureMonitoring() {
install(MicrometerMetrics) {
registry = appMicrometerRegistry
meterBinders =
listOf(
ClassLoaderMetrics(),
JvmMemoryMetrics(),
JvmGcMetrics(),
ProcessorMetrics(),
JvmThreadMetrics(),
FileDescriptorMetrics(),
UptimeMetrics()
)
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/com/example/config/Routing.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.config

import com.example.route.menuRoute
import com.example.route.monitorRoute
import com.example.route.orderRoute
import com.example.route.userRoute
import io.ktor.server.application.*
Expand All @@ -15,6 +16,7 @@ fun Application.configureRouting() {
orderRoute()
}

monitorRoute()
singlePageApplication {
react("frontend")
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/com/example/route/MonitorRoute.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.route

import com.example.config.appMicrometerRegistry
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Route.monitorRoute() {
get("/metrics") {
call.respond(appMicrometerRegistry.scrape())
}
}