prometheus hotfix (#670)
This commit is contained in:
@@ -91,41 +91,43 @@ class MonitoringSetup(
|
|||||||
if (monitoringConfig.prometheus.enabled) {
|
if (monitoringConfig.prometheus.enabled) {
|
||||||
// use standard JVM server with a single thread blocking processing
|
// use standard JVM server with a single thread blocking processing
|
||||||
// prometheus is a single thread periodic call, no reason to setup anything complex
|
// prometheus is a single thread periodic call, no reason to setup anything complex
|
||||||
var started = false
|
Thread {
|
||||||
while (true) {
|
var started = false
|
||||||
if (isTcpPortAvailable(monitoringConfig.prometheus.host, monitoringConfig.prometheus.port)) {
|
while (true) {
|
||||||
started = true
|
if (isTcpPortAvailable(monitoringConfig.prometheus.host, monitoringConfig.prometheus.port)) {
|
||||||
try {
|
started = true
|
||||||
log.info("Run Prometheus metrics on ${monitoringConfig.prometheus.host}:${monitoringConfig.prometheus.port}${monitoringConfig.prometheus.path}")
|
try {
|
||||||
val server = HttpServer.create(
|
log.info("Run Prometheus metrics on ${monitoringConfig.prometheus.host}:${monitoringConfig.prometheus.port}${monitoringConfig.prometheus.path}")
|
||||||
InetSocketAddress(
|
val server = HttpServer.create(
|
||||||
monitoringConfig.prometheus.host,
|
InetSocketAddress(
|
||||||
monitoringConfig.prometheus.port,
|
monitoringConfig.prometheus.host,
|
||||||
),
|
monitoringConfig.prometheus.port,
|
||||||
0,
|
),
|
||||||
)
|
0,
|
||||||
server.createContext(monitoringConfig.prometheus.path) { httpExchange ->
|
)
|
||||||
val response = prometheusRegistry.scrape()
|
server.createContext(monitoringConfig.prometheus.path) { httpExchange ->
|
||||||
httpExchange.responseHeaders.add("Content-Encoding", "gzip")
|
val response = prometheusRegistry.scrape()
|
||||||
httpExchange.responseHeaders.add("Content-Type", "text/plain")
|
httpExchange.responseHeaders.add("Content-Encoding", "gzip")
|
||||||
httpExchange.sendResponseHeaders(200, 0)
|
httpExchange.responseHeaders.add("Content-Type", "text/plain")
|
||||||
httpExchange.responseBody.use { os ->
|
httpExchange.sendResponseHeaders(200, 0)
|
||||||
GZIPOutputStream(os).use { gzos ->
|
httpExchange.responseBody.use { os ->
|
||||||
gzos.write(response.toByteArray())
|
GZIPOutputStream(os).use { gzos ->
|
||||||
|
gzos.write(response.toByteArray())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Thread(server::start).start()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
log.error("Failed to start Prometheus Server", e)
|
||||||
}
|
}
|
||||||
Thread(server::start).start()
|
} else {
|
||||||
} catch (e: IOException) {
|
if (!started) {
|
||||||
log.error("Failed to start Prometheus Server", e)
|
log.error("Can't start prometheus metrics on ${monitoringConfig.prometheus.host}:${monitoringConfig.prometheus.port}${monitoringConfig.prometheus.path}")
|
||||||
|
}
|
||||||
|
Thread.sleep(1000)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!started) {
|
|
||||||
log.error("Can't start prometheus metrics on ${monitoringConfig.prometheus.host}:${monitoringConfig.prometheus.port}${monitoringConfig.prometheus.path}")
|
|
||||||
}
|
|
||||||
Thread.sleep(1000)
|
|
||||||
}
|
}
|
||||||
}
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user