-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support prometheus export with micrometer
- Loading branch information
Showing
9 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ build | |
out/ | ||
.scannerwork/ | ||
cookie.txt | ||
prom.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
kotlin/src/main/kotlin/net/timafe/angkor/config/MetricsConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package net.timafe.angkor.config | ||
|
||
import io.micrometer.core.instrument.Meter | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.micrometer.core.instrument.config.MeterFilter | ||
import io.micrometer.core.instrument.config.MeterFilterReply | ||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
|
||
@Configuration | ||
class MetricsConfig { | ||
|
||
companion object { | ||
val FilterNames = setOf( | ||
"hikaricp.connections.max", | ||
"hikaricp.connections.active", | ||
"hikaricp.connections.acquire", | ||
"hikaricp.connections", | ||
"jvm.memory.max", | ||
"jvm.memory.committed", | ||
"jvm.memory.used", | ||
"process.start.time", | ||
"process.uptime", | ||
"system.cpu.usage", | ||
"tomcat.sessions.active.current", | ||
"tomcat.sessions.active.max", | ||
"tomcat.sessions.created" | ||
) | ||
} | ||
|
||
// add common tags | ||
@Bean | ||
fun metricsCommonTags(): MeterRegistryCustomizer<MeterRegistry> { | ||
return MeterRegistryCustomizer<MeterRegistry> { registry: MeterRegistry -> | ||
registry.config().commonTags("app", "angkor-api") | ||
} | ||
} | ||
|
||
/** | ||
* Reduce metrics https://stackoverflow.com/a/54097060/4292075 | ||
* https://github.com/micrometer-metrics/micrometer-docs/blob/main/src/docs/concepts/meter-filters.adoc#deny-or-accept-meters | ||
* Example Names (it uses dots, not the prometheus style underscore notation) | ||
* http.server.requests.active | ||
* spring.security.filter.active * | ||
*/ | ||
|
||
@Bean | ||
fun meterFilter(): MeterFilter { | ||
return object : MeterFilter { | ||
override fun accept(id: Meter.Id): MeterFilterReply { | ||
//listOf("jdbc.connections.active", "jvm.memory.max","process.cpu.usage","process.start").forEach { | ||
FilterNames.forEach { | ||
if (id.name.startsWith(it)) { | ||
return MeterFilterReply.NEUTRAL | ||
} | ||
} | ||
// println(id.name) | ||
// if (id.getName().startsWith("jvm.")) { | ||
// return MeterFilterReply.DENY | ||
// } | ||
return MeterFilterReply.DENY // deny all other | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters