implemented 09-system-metrics.md: added system metrics: introduced system monitoring with a metrics collector, REST API endpoint, Thymeleaf UI rendering, and lifecycle management
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package de.hoennig.gittally.server
|
||||
|
||||
import de.hoennig.gittally.metrics.SystemMetricsCollector
|
||||
import jakarta.annotation.PreDestroy
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* Starts the system-metrics sampling loop once the server context is ready and
|
||||
* stops it on shutdown. Only in the `server` profile, like [ServerWatcherLifecycle].
|
||||
*/
|
||||
@Component
|
||||
@Profile("server")
|
||||
class ServerMetricsLifecycle(
|
||||
private val collector: SystemMetricsCollector,
|
||||
) {
|
||||
@EventListener(ApplicationReadyEvent::class)
|
||||
fun onApplicationReady() {
|
||||
collector.start()
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
fun onShutdown() {
|
||||
collector.stop()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user