diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4683de9..f82ffaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,62 +1,72 @@ -#name: CI (ktlint auto-format & build) -# -##on: ci 잠시 무력화 ^^ TODO 모듈 맞춰서 하기 -## pull_request: -## branches: [ "master" ] -## push: -## branches: [ "master" ] -# -#permissions: -# contents: write # commit/push 권한 -# pull-requests: write -# -#jobs: -# build-and-format: -# runs-on: ubuntu-latest -# -# steps: -# - name: Checkout repository (with history) -# uses: actions/checkout@v3 -# with: -# fetch-depth: 0 -# token: ${{ secrets.GITHUB_TOKEN }} -# -# - name: Set up JDK 17 -# uses: actions/setup-java@v3 -# with: -# java-version: '17' -# distribution: 'temurin' -# -# - name: Ensure gradlew is executable -# run: chmod +x ./gradlew -# -# # 🔹 코드스타일 체크 -# - name: Run ktlint check -# run: ./gradlew ktlintCheck || true -# -# # 🔹 코드스타일 자동 포맷 -# - name: Run ktlint format -# run: ./gradlew ktlintFormat || true -# -# # 🔹 PR 브랜치일 때만 커밋/푸시 -# - name: Commit and push ktlint fixes (only for PRs, not master) -# if: github.event_name == 'pull_request' -# run: | -# git config user.name "github-actions[bot]" -# git config user.email "41898282+github-actions[bot]@users.noreply.github.com" -# -# if git diff --quiet && git diff --staged --quiet; then -# echo "No formatting changes to commit." -# else -# git add -A -# if git diff --staged --quiet; then -# echo "No staged changes." -# else -# git commit -m "chore: apply ktlintFormat (auto-format by CI)" -# git push origin HEAD:${{ github.head_ref }} -# fi -# fi -# -# # 🔹 빌드 (테스트 제외) -# - name: Build with Gradle (skip tests) -# run: ./gradlew build -x test +name: CI (ktlint for PR / selective build manual) + +on: + pull_request: + branches: [ "master" ] + workflow_dispatch: + inputs: + BUILD_MODULES: + description: "Space-separated list of modules to build (e.g. core api cli)" + required: false + default: "" + +permissions: + contents: write + pull-requests: write + +jobs: + ktlint-or-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Ensure gradlew executable + run: chmod +x ./gradlew + + - name: Run ktlint (on Pull Request) + if: github.event_name == 'pull_request' + run: | + echo "🔹 Running ktlint for pull request..." + ./gradlew ktlintCheck || true + ./gradlew ktlintFormat || true + + - name: Commit and push ktlint fixes (only for PRs) + if: github.event_name == 'pull_request' + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + if git diff --quiet && git diff --staged --quiet; then + echo "No formatting changes to commit." + else + git add -A + git commit -m "chore: auto-format by ktlint (CI)" + git push origin HEAD:${{ github.head_ref }} + fi + - name: Selective build (manual trigger) + if: github.event_name == 'workflow_dispatch' + run: | + if [ -z "${{ github.event.inputs.BUILD_MODULES }}" ]; then + echo "No modules specified, skipping build." + exit 0 + fi + + echo "🔹 Building selected modules: ${{ github.event.inputs.BUILD_MODULES }}" + for module in ${{ github.event.inputs.BUILD_MODULES }}; do + if [ -d "$module" ]; then + echo "🚀 Building module: $module" + ./gradlew :"$module":build -x test + else + echo "⚠️ Module '$module' not found, skipping." + fi + done diff --git a/ai/src/main/kotlin/lab/Application.kt b/ai/src/main/kotlin/lab/Application.kt index b442ad4..51dbef0 100644 --- a/ai/src/main/kotlin/lab/Application.kt +++ b/ai/src/main/kotlin/lab/Application.kt @@ -4,11 +4,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @SpringBootApplication( - scanBasePackages = ["lab.api", "lab.`ai-model`"] + scanBasePackages = ["lab.api", "lab.`ai-model`"], ) class Application fun main(args: Array) { runApplication(*args) } - diff --git a/ai/src/main/kotlin/lab/ai-model/NormalizationUtil.kt b/ai/src/main/kotlin/lab/ai-model/NormalizationUtil.kt index f6f11d2..85e4cef 100644 --- a/ai/src/main/kotlin/lab/ai-model/NormalizationUtil.kt +++ b/ai/src/main/kotlin/lab/ai-model/NormalizationUtil.kt @@ -8,8 +8,11 @@ object NormalizationUtil { return features.map { f -> DoubleArray(numFeatures) { i -> - if (maxVals[i] == minVals[i]) 0.0 - else (f[i] - minVals[i]) / (maxVals[i] - minVals[i]) + if (maxVals[i] == minVals[i]) { + 0.0 + } else { + (f[i] - minVals[i]) / (maxVals[i] - minVals[i]) + } } }.toTypedArray() } diff --git a/ai/src/main/kotlin/lab/ai-model/gc/GcAnomalyDetector.kt b/ai/src/main/kotlin/lab/ai-model/gc/GcAnomalyDetector.kt index 7786ec2..21c13da 100644 --- a/ai/src/main/kotlin/lab/ai-model/gc/GcAnomalyDetector.kt +++ b/ai/src/main/kotlin/lab/ai-model/gc/GcAnomalyDetector.kt @@ -10,7 +10,6 @@ import java.io.ObjectOutputStream @Component class GcAnomalyDetector { - private val extractor: GcFeatureExtractor by lazy { GcFeatureExtractor } private val normalizationUtil: NormalizationUtil by lazy { NormalizationUtil } @@ -58,13 +57,13 @@ class GcAnomalyDetector { } private fun getDataList(isTestSet: Boolean = true): List { - return if(isTestSet) { + return if (isTestSet) { listOf( GcTrainData(120, 500, 40, 1.2, 400_000, "G1", label = 1), GcTrainData(200, 800, 350, 3.8, 1_200_000, "G1", label = 1), GcTrainData(85, 260, 12, 0.9, 250_000, "Parallel", label = 1), GcTrainData(600, 1500, 900, 6.8, 2_200_000, "G1", label = 1), - GcTrainData(95, 340, 18, 1.4, 370_000, "Serial", label = 1) + GcTrainData(95, 340, 18, 1.4, 370_000, "Serial", label = 1), ) } else { // TODO heesung feature diff --git a/ai/src/main/kotlin/lab/ai-model/gc/GcFeatureExtractor.kt b/ai/src/main/kotlin/lab/ai-model/gc/GcFeatureExtractor.kt index 545df31..6112d50 100644 --- a/ai/src/main/kotlin/lab/ai-model/gc/GcFeatureExtractor.kt +++ b/ai/src/main/kotlin/lab/ai-model/gc/GcFeatureExtractor.kt @@ -1,13 +1,13 @@ package lab.`ai-model`.gc - object GcFeatureExtractor { - private val gcStrategyMap = mapOf( - "G1" to 0.0, - "Parallel" to 1.0, - "Serial" to 2.0, - "ZGC" to 3.0 - ) + private val gcStrategyMap = + mapOf( + "G1" to 0.0, + "Parallel" to 1.0, + "Serial" to 2.0, + "ZGC" to 3.0, + ) fun extract(gc: GcTrainData): DoubleArray { return doubleArrayOf( @@ -16,7 +16,7 @@ object GcFeatureExtractor { gc.pause.toDouble(), gc.allocationRate, gc.liveDataSize.toDouble(), - gcStrategyMap[gc.gcStrategy] ?: -1.0 + gcStrategyMap[gc.gcStrategy] ?: -1.0, ) } } diff --git a/ai/src/main/kotlin/lab/ai-model/gc/GcLogisticRegressionTrainer.kt b/ai/src/main/kotlin/lab/ai-model/gc/GcLogisticRegressionTrainer.kt index 0813228..882fc71 100644 --- a/ai/src/main/kotlin/lab/ai-model/gc/GcLogisticRegressionTrainer.kt +++ b/ai/src/main/kotlin/lab/ai-model/gc/GcLogisticRegressionTrainer.kt @@ -44,23 +44,25 @@ class GcLogisticRegressionTrainer { val normalizedFeatures = normalizationUtil.normalize(features) val labels = dataList.map { it.label }.toIntArray() - val df = DataFrame.of( - DoubleVector.of("count", normalizedFeatures.map { it[0] }.toDoubleArray()), - DoubleVector.of("time", normalizedFeatures.map { it[1] }.toDoubleArray()), - DoubleVector.of("pause", normalizedFeatures.map { it[2] }.toDoubleArray()), - DoubleVector.of("allocationRate", normalizedFeatures.map { it[3] }.toDoubleArray()), - DoubleVector.of("liveDataSize", normalizedFeatures.map { it[4] }.toDoubleArray()), - DoubleVector.of("gcStrategy", normalizedFeatures.map { it[5] }.toDoubleArray()), - IntVector.of("label", labels) - ) + val df = + DataFrame.of( + DoubleVector.of("count", normalizedFeatures.map { it[0] }.toDoubleArray()), + DoubleVector.of("time", normalizedFeatures.map { it[1] }.toDoubleArray()), + DoubleVector.of("pause", normalizedFeatures.map { it[2] }.toDoubleArray()), + DoubleVector.of("allocationRate", normalizedFeatures.map { it[3] }.toDoubleArray()), + DoubleVector.of("liveDataSize", normalizedFeatures.map { it[4] }.toDoubleArray()), + DoubleVector.of("gcStrategy", normalizedFeatures.map { it[5] }.toDoubleArray()), + IntVector.of("label", labels), + ) val formula = Formula.lhs("label") - val props = Properties().apply { - // 하이퍼파라미터 설정 - setProperty("lambda", "1e-4") - setProperty("tol", "1e-5") - setProperty("maxIter", "500") - } + val props = + Properties().apply { + // 하이퍼파라미터 설정 + setProperty("lambda", "1e-4") + setProperty("tol", "1e-5") + setProperty("maxIter", "500") + } model = LogisticRegression.fit(formula, df, props) log.info("GcTrainer training completed.") @@ -73,10 +75,11 @@ class GcLogisticRegressionTrainer { } private fun saveModel(key: String) { - val m = model ?: run { - log.error("Model not trained. Cannot save [$key].") - return - } + val m = + model ?: run { + log.error("Model not trained. Cannot save [$key].") + return + } val file = File(modelDir, "gc_$key.model") @@ -88,13 +91,13 @@ class GcLogisticRegressionTrainer { } private fun getDataList(isTestSet: Boolean = true): List { - return if(isTestSet) { + return if (isTestSet) { listOf( GcTrainData(120, 500, 40, 1.2, 400_000, "G1", label = 1), GcTrainData(200, 800, 350, 3.8, 1_200_000, "G1", label = 1), GcTrainData(85, 260, 12, 0.9, 250_000, "Parallel", label = 1), GcTrainData(600, 1500, 900, 6.8, 2_200_000, "G1", label = 1), - GcTrainData(95, 340, 18, 1.4, 370_000, "Serial", label = 1) + GcTrainData(95, 340, 18, 1.4, 370_000, "Serial", label = 1), ) } else { // TODO heesung feature diff --git a/ai/src/main/kotlin/lab/ai-model/gc/GcTrainData.kt b/ai/src/main/kotlin/lab/ai-model/gc/GcTrainData.kt index 4750f62..7f73eb6 100644 --- a/ai/src/main/kotlin/lab/ai-model/gc/GcTrainData.kt +++ b/ai/src/main/kotlin/lab/ai-model/gc/GcTrainData.kt @@ -7,5 +7,5 @@ data class GcTrainData( val allocationRate: Double, val liveDataSize: Long, val gcStrategy: String, - val label: Int // 1 정상, 0 비정상 + val label: Int, // 1 정상, 0 비정상 ) diff --git a/ai/src/main/kotlin/lab/api/ApiController.kt b/ai/src/main/kotlin/lab/api/ApiController.kt index 1855e0a..177c1ec 100644 --- a/ai/src/main/kotlin/lab/api/ApiController.kt +++ b/ai/src/main/kotlin/lab/api/ApiController.kt @@ -11,10 +11,11 @@ class ApiController( private val gcLogisticRegressionTrainer: GcLogisticRegressionTrainer, private val gcAnomalyDetector: GcAnomalyDetector, ) { - @GetMapping("/api/train") - fun train(@RequestParam trainModelName: String?) { - when(trainModelName) { + fun train( + @RequestParam trainModelName: String?, + ) { + when (trainModelName) { "gc_logistic_regression" -> gcLogisticRegressionTrainer.train() "gc_anomaly_detector" -> gcAnomalyDetector.train() else -> throw IllegalArgumentException("Unknown model name: $trainModelName") diff --git a/cli/src/main/kotlin/lab/cli/Main.kt b/cli/src/main/kotlin/lab/cli/Main.kt index 2c22b5d..2eae9c5 100644 --- a/cli/src/main/kotlin/lab/cli/Main.kt +++ b/cli/src/main/kotlin/lab/cli/Main.kt @@ -7,11 +7,12 @@ import org.springframework.boot.WebApplicationType import org.springframework.boot.builder.SpringApplicationBuilder fun main(args: Array) { - val context = SpringApplicationBuilder(ExporterConfig::class.java) - .web(WebApplicationType.NONE) - .bannerMode(Banner.Mode.OFF) - .logStartupInfo(false) - .run(*args) + val context = + SpringApplicationBuilder(ExporterConfig::class.java) + .web(WebApplicationType.NONE) + .bannerMode(Banner.Mode.OFF) + .logStartupInfo(false) + .run(*args) val exporter = context.getBean(JvmExporter::class.java) @@ -38,24 +39,25 @@ private fun loop(action: () -> Unit) { } } -private fun printSummary(exporter: JvmExporter) = loop { - val mem = exporter.getMemoryInfo() - val gc = exporter.getGcInfo() - val cpu = exporter.getCpuInfo() - val threads = exporter.getThreadInfo() +private fun printSummary(exporter: JvmExporter) = + loop { + val mem = exporter.getMemoryInfo() + val gc = exporter.getGcInfo() + val cpu = exporter.getCpuInfo() + val threads = exporter.getThreadInfo() - println( - """ - ==== JVM Summary ==== - Host: ${exporter.getHostname()} - Memory Used: ${mem.used / 1024 / 1024} MB / ${mem.max / 1024 / 1024} MB - GC Count: ${gc.count}, Time: ${gc.time} ms - CPU Usage: ${"%.2f".format(cpu.processUsage * 100)} % - Threads: ${threads.count} (Daemon: ${threads.daemonCount}) - ===================== - """.trimIndent() - ) -} + println( + """ + ==== JVM Summary ==== + Host: ${exporter.getHostname()} + Memory Used: ${mem.used / 1024 / 1024} MB / ${mem.max / 1024 / 1024} MB + GC Count: ${gc.count}, Time: ${gc.time} ms + CPU Usage: ${"%.2f".format(cpu.processUsage * 100)} % + Threads: ${threads.count} (Daemon: ${threads.daemonCount}) + ===================== + """.trimIndent(), + ) + } private fun printGc(exporter: JvmExporter) { val gc = exporter.getGcInfo() diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/api/MetricController.kt b/exporter/src/main/kotlin/lab/monilabexporterex/api/MetricController.kt index 38c47fc..ead724f 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/api/MetricController.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/api/MetricController.kt @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController class MetricController( private val metricService: MetricService, ) { - @GetMapping("/metric") fun getGcMetrics(): ResponseEntity> { val data = metricService.getAllGcMetrics() diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/config/ExporterConfig.kt b/exporter/src/main/kotlin/lab/monilabexporterex/config/ExporterConfig.kt index c25c9c5..676e97d 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/config/ExporterConfig.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/config/ExporterConfig.kt @@ -25,7 +25,7 @@ class ExporterConfig { fun applicationExporter( meterRegistry: MeterRegistry, dataSource: HikariDataSource? = null, - taskQueue: BlockingQueue<*>? = null + taskQueue: BlockingQueue<*>? = null, ): ApplicationExporter = DefaultApplicationExporter(meterRegistry, dataSource, taskQueue) @Bean @@ -54,14 +54,15 @@ class ExporterConfig { cpuExporter: CpuExporter, classLoadingExporter: ClassLoadingExporter, networkExporter: NetworkExporter, - applicationExporter: ApplicationExporter - ): JvmExporter = JvmExporterImpl( - memoryExporter, - gcExporter, - threadExporter, - cpuExporter, - classLoadingExporter, - networkExporter, - applicationExporter - ) + applicationExporter: ApplicationExporter, + ): JvmExporter = + JvmExporterImpl( + memoryExporter, + gcExporter, + threadExporter, + cpuExporter, + classLoadingExporter, + networkExporter, + applicationExporter, + ) } diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/config/SchedulerConfig.kt b/exporter/src/main/kotlin/lab/monilabexporterex/config/SchedulerConfig.kt index a296b3c..5e1e7b5 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/config/SchedulerConfig.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/config/SchedulerConfig.kt @@ -6,7 +6,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler @Configuration class SchedulerConfig { - @Bean fun taskScheduler(): ThreadPoolTaskScheduler { val scheduler = ThreadPoolTaskScheduler() @@ -14,5 +13,4 @@ class SchedulerConfig { scheduler.setThreadNamePrefix("metric-scheduler-") return scheduler } - } diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/exporter/jvm/thread/DefaultThreadExporter.kt b/exporter/src/main/kotlin/lab/monilabexporterex/exporter/jvm/thread/DefaultThreadExporter.kt index 9030f17..f04294d 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/exporter/jvm/thread/DefaultThreadExporter.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/exporter/jvm/thread/DefaultThreadExporter.kt @@ -27,17 +27,17 @@ class DefaultThreadExporter : ThreadExporter { peakCount = threadBean.peakThreadCount, deadlockedCount = threadBean.findDeadlockedThreads()?.size ?: 0, cpuTime = - if (threadBean.isThreadCpuTimeSupported) { - threadBean.allThreadIds.sumOf { id -> - try { - threadBean.getThreadCpuTime(id).takeIf { it > 0 } ?: 0 - } catch (_: Exception) { - 0 + if (threadBean.isThreadCpuTimeSupported) { + threadBean.allThreadIds.sumOf { id -> + try { + threadBean.getThreadCpuTime(id).takeIf { it > 0 } ?: 0 + } catch (_: Exception) { + 0 + } } - } - } else { - 0 - }, + } else { + 0 + }, states = states, ) } diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/ApplicationEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/ApplicationEntity.kt index 94bfdc9..feab1ba 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/ApplicationEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/ApplicationEntity.kt @@ -10,30 +10,22 @@ class ApplicationEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "http_requests_count", nullable = false) val httpRequestsCount: Long, - @Column(name = "http_latency", nullable = false) val httpLatency: Double, - @Column(name = "db_connections_active", nullable = false) val dbConnectionsActive: Int, - @Column(name = "db_connections_max", nullable = false) val dbConnectionsMax: Int, - @Column(name = "queue_tasks_pending", nullable = false) val queueTasksPending: Int, - @Lob @Column(name = "custom_metrics", columnDefinition = "TEXT", nullable = false) val customMetrics: String, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/ClassLoadingInfoEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/ClassLoadingInfoEntity.kt index fa365e6..39923fd 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/ClassLoadingInfoEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/ClassLoadingInfoEntity.kt @@ -10,29 +10,21 @@ class ClassLoadingInfoEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "loaded", nullable = false) val loaded: Int, - @Column(name = "unloaded", nullable = false) val unloaded: Long, - @Column(name = "code_cache_used", nullable = false) val codeCacheUsed: Long, - @Column(name = "code_cache_max", nullable = false) val codeCacheMax: Long, - @Column(name = "compilation_time", nullable = false) val compilationTime: Long, - @Column(name = "reserved_code_cache_size", nullable = false) val reservedCodeCacheSize: Long, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/CpuEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/CpuEntity.kt index 84394b2..5dff12a 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/CpuEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/CpuEntity.kt @@ -10,29 +10,21 @@ class CpuEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "process_usage", nullable = false) val processUsage: Double, - @Column(name = "system_usage", nullable = false) val systemUsage: Double, - @Column(name = "uptime", nullable = false) val uptime: Long, - @Column(name = "start_time", nullable = false) val startTime: Long, - @Column(name = "load_average", nullable = false) val loadAverage: Double, - @Column(name = "open_fds", nullable = false) val openFds: Long, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/GcEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/GcEntity.kt index 5fe19f0..036e62f 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/GcEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/GcEntity.kt @@ -10,29 +10,21 @@ class GcEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "count", nullable = false) val count: Long, - @Column(name = "time", nullable = false) val time: Long, - @Column(name = "pause", nullable = false) val pause: Long, - @Column(name = "allocation_rate", nullable = false) val allocationRate: Double, - @Column(name = "live_data_size", nullable = false) val liveDataSize: Long, - @Column(name = "gc_strategy", nullable = false) val gcStrategy: String, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/Label.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/Label.kt index 66292c9..e244a52 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/Label.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/Label.kt @@ -1,5 +1,6 @@ package lab.monilabexporterex.model enum class Label { - TEST, TRAIN + TEST, + TRAIN, } diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/MemoryEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/MemoryEntity.kt index b69d6c5..0d4be80 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/MemoryEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/MemoryEntity.kt @@ -10,35 +10,25 @@ class MemoryEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false) val label: Label, - @Column(name = "used", nullable = false) val used: Long, - @Column(name = "max", nullable = false) val max: Long, - @Column(name = "committed", nullable = false) val committed: Long, - @Column(name = "eden", nullable = false) val eden: Long, - @Column(name = "survivor", nullable = false) val survivor: Long, - @Column(name = "old", nullable = false) val old: Long, - @Column(name = "buffer_pool_used", nullable = false) val bufferPoolUsed: Long, - @Column(name = "max_direct_memory_size", nullable = false) val maxDirectMemorySize: Long, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/NetworkEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/NetworkEntity.kt index 865dbe4..e74b9c1 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/NetworkEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/NetworkEntity.kt @@ -10,29 +10,21 @@ class NetworkEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "bytes_sent", nullable = false) val bytesSent: Long, - @Column(name = "bytes_received", nullable = false) val bytesReceived: Long, - @Column(name = "tcp_connections", nullable = false) val tcpConnections: Int, - @Column(name = "tcp_established", nullable = false) val tcpEstablished: Int, - @Column(name = "open_sockets", nullable = false) val openSockets: Int, - @Column(name = "prefer_ipv4", nullable = false) val preferIPv4: Boolean, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/ThreadsEntity.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/ThreadsEntity.kt index e7b03e1..fef1a8f 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/ThreadsEntity.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/ThreadsEntity.kt @@ -10,30 +10,22 @@ class ThreadsEntity( @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") val id: Long = 0, - @Enumerated(EnumType.STRING) @Column(name = "label", nullable = false, length = 10) val label: Label, - @Column(name = "count", nullable = false) val count: Int, - @Column(name = "daemon_count", nullable = false) val daemonCount: Int, - @Column(name = "peak_count", nullable = false) val peakCount: Int, - @Column(name = "deadlocked_count", nullable = false) val deadlockedCount: Int, - @Column(name = "cpu_time", nullable = false) val cpuTime: Long, - @Lob @Column(name = "states", columnDefinition = "TEXT", nullable = false) val states: String, - @Column(name = "registered_date_time", nullable = false, updatable = false) - var registeredDateTime: LocalDateTime = LocalDateTime.now() + var registeredDateTime: LocalDateTime = LocalDateTime.now(), ) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/model/mapper/MetricMapper.kt b/exporter/src/main/kotlin/lab/monilabexporterex/model/mapper/MetricMapper.kt index a0a731d..31a0eb5 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/model/mapper/MetricMapper.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/model/mapper/MetricMapper.kt @@ -5,8 +5,10 @@ import lab.monilabexporterex.model.* import java.time.LocalDateTime object JvmMonitoringMapper { - - fun toEntity(data: JvmMonitoringData.Memory, label: Label): MemoryEntity = + fun toEntity( + data: JvmMonitoringData.Memory, + label: Label, + ): MemoryEntity = MemoryEntity( label = label, used = data.used, @@ -17,7 +19,7 @@ object JvmMonitoringMapper { old = data.old, bufferPoolUsed = data.bufferPoolUsed, maxDirectMemorySize = data.maxDirectMemorySize, - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: MemoryEntity): JvmMonitoringData.Memory = @@ -29,10 +31,13 @@ object JvmMonitoringMapper { survivor = entity.survivor, old = entity.old, bufferPoolUsed = entity.bufferPoolUsed, - maxDirectMemorySize = entity.maxDirectMemorySize + maxDirectMemorySize = entity.maxDirectMemorySize, ) - fun toEntity(data: JvmMonitoringData.Gc, label: Label): GcEntity = + fun toEntity( + data: JvmMonitoringData.Gc, + label: Label, + ): GcEntity = GcEntity( label = label, count = data.count, @@ -41,7 +46,7 @@ object JvmMonitoringMapper { allocationRate = data.allocationRate, liveDataSize = data.liveDataSize, gcStrategy = data.gcStrategy, - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: GcEntity): JvmMonitoringData.Gc = @@ -51,10 +56,13 @@ object JvmMonitoringMapper { pause = entity.pause, allocationRate = entity.allocationRate, liveDataSize = entity.liveDataSize, - gcStrategy = entity.gcStrategy + gcStrategy = entity.gcStrategy, ) - fun toEntity(data: JvmMonitoringData.Threads, label: Label): ThreadsEntity = + fun toEntity( + data: JvmMonitoringData.Threads, + label: Label, + ): ThreadsEntity = ThreadsEntity( label = label, count = data.count, @@ -63,7 +71,7 @@ object JvmMonitoringMapper { deadlockedCount = data.deadlockedCount, cpuTime = data.cpuTime, states = data.states.toString(), - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: ThreadsEntity): JvmMonitoringData.Threads = @@ -73,7 +81,7 @@ object JvmMonitoringMapper { peakCount = entity.peakCount, deadlockedCount = entity.deadlockedCount, cpuTime = entity.cpuTime, - states = parseStates(entity.states) + states = parseStates(entity.states), ) private fun parseStates(json: String): Map { @@ -86,7 +94,10 @@ object JvmMonitoringMapper { }.toMap() } - fun toEntity(data: JvmMonitoringData.Cpu, label: Label): CpuEntity = + fun toEntity( + data: JvmMonitoringData.Cpu, + label: Label, + ): CpuEntity = CpuEntity( label = label, processUsage = data.processUsage, @@ -95,7 +106,7 @@ object JvmMonitoringMapper { startTime = data.startTime, loadAverage = data.loadAverage, openFds = data.openFds, - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: CpuEntity): JvmMonitoringData.Cpu = @@ -105,10 +116,13 @@ object JvmMonitoringMapper { uptime = entity.uptime, startTime = entity.startTime, loadAverage = entity.loadAverage, - openFds = entity.openFds + openFds = entity.openFds, ) - fun toEntity(data: JvmMonitoringData.Network, label: Label): NetworkEntity = + fun toEntity( + data: JvmMonitoringData.Network, + label: Label, + ): NetworkEntity = NetworkEntity( label = label, bytesSent = data.bytesSent, @@ -117,7 +131,7 @@ object JvmMonitoringMapper { tcpEstablished = data.tcpEstablished, openSockets = data.openSockets, preferIPv4 = data.preferIPv4, - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: NetworkEntity): JvmMonitoringData.Network = @@ -127,10 +141,13 @@ object JvmMonitoringMapper { tcpConnections = entity.tcpConnections, tcpEstablished = entity.tcpEstablished, openSockets = entity.openSockets, - preferIPv4 = entity.preferIPv4 + preferIPv4 = entity.preferIPv4, ) - fun toEntity(data: JvmMonitoringData.ClassLoadingInfo, label: Label): ClassLoadingInfoEntity = + fun toEntity( + data: JvmMonitoringData.ClassLoadingInfo, + label: Label, + ): ClassLoadingInfoEntity = ClassLoadingInfoEntity( label = label, loaded = data.loaded, @@ -139,7 +156,7 @@ object JvmMonitoringMapper { codeCacheMax = data.codeCacheMax, compilationTime = data.compilationTime, reservedCodeCacheSize = data.reservedCodeCacheSize, - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: ClassLoadingInfoEntity): JvmMonitoringData.ClassLoadingInfo = @@ -149,10 +166,13 @@ object JvmMonitoringMapper { codeCacheUsed = entity.codeCacheUsed, codeCacheMax = entity.codeCacheMax, compilationTime = entity.compilationTime, - reservedCodeCacheSize = entity.reservedCodeCacheSize + reservedCodeCacheSize = entity.reservedCodeCacheSize, ) - fun toEntity(data: JvmMonitoringData.Application, label: Label): ApplicationEntity = + fun toEntity( + data: JvmMonitoringData.Application, + label: Label, + ): ApplicationEntity = ApplicationEntity( label = label, httpRequestsCount = data.httpRequestsCount, @@ -161,7 +181,7 @@ object JvmMonitoringMapper { dbConnectionsMax = data.dbConnectionsMax, queueTasksPending = data.queueTasksPending, customMetrics = data.customMetrics.toString(), - registeredDateTime = LocalDateTime.now() + registeredDateTime = LocalDateTime.now(), ) fun toData(entity: ApplicationEntity): JvmMonitoringData.Application = @@ -171,7 +191,7 @@ object JvmMonitoringMapper { dbConnectionsActive = entity.dbConnectionsActive, dbConnectionsMax = entity.dbConnectionsMax, queueTasksPending = entity.queueTasksPending, - customMetrics = parseCustomMetrics(entity.customMetrics) + customMetrics = parseCustomMetrics(entity.customMetrics), ) private fun parseCustomMetrics(json: String): Map { diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt index 865826b..b8feb81 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt @@ -16,9 +16,8 @@ class JvmMonitoringScheduler( private val cpuRepository: CpuRepository, private val networkRepository: NetworkRepository, private val classLoadingRepository: ClassLoadingInfoRepository, - private val applicationRepository: ApplicationRepository + private val applicationRepository: ApplicationRepository, ) { - @Scheduled(fixedRate = 1000) fun collectAndSaveJvmMetrics() { val memoryEntity = JvmMonitoringMapper.toEntity(jvmExporter.getMemoryInfo(), TEST) @@ -42,5 +41,4 @@ class JvmMonitoringScheduler( val applicationEntity = JvmMonitoringMapper.toEntity(jvmExporter.getApplicationInfo(), TEST) applicationRepository.save(applicationEntity) } - }