Skip to content
Merged
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
5 changes: 5 additions & 0 deletions accountant/accountant-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.preferences</groupId>
<artifactId>preferences</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package co.nilin.opex.accountant.app.utils

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.health.HealthComponent
import org.springframework.boot.actuate.health.HealthEndpoint
import org.springframework.boot.actuate.health.SystemHealth
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class PrometheusHealthExtension(
private val registry: MeterRegistry,
private val endpoint: HealthEndpoint
) {

private var consulHealth = -1
private var r2dbcHealth = -1
private var vaultHealth = -1
private var vaultReactiveHealth = -1
private val service = "ACCOUNTANT"

init {
Gauge.builder("consul_health", consulHealth) { consulHealth.toDouble() }
.description("Health of consul connection")
.tag("Service", service)
.register(registry)

Gauge.builder("r2dbc_health", r2dbcHealth) { r2dbcHealth.toDouble() }
.description("Health of r2dbc connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vault_health", vaultHealth) { vaultHealth.toDouble() }
.description("Health of vault connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vaultReactive_health", vaultReactiveHealth) { vaultReactiveHealth.toDouble() }
.description("Health of vaultReactive connection")
.tag("Service", service)
.register(registry)
}

@Scheduled(initialDelay = 1000, fixedDelay = 5000)
fun updateHealth() {
try {
val health = endpoint.health() as SystemHealth
consulHealth = getHealthValue(health.components["consul"])
r2dbcHealth = getHealthValue(health.components["r2dbc"])
vaultHealth = getHealthValue(health.components["vault"])
vaultReactiveHealth = getHealthValue(health.components["vaultReactive"])
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun getHealthValue(health: HealthComponent?): Int {
health ?: return -1
return if (health.status.code == "UP") 1 else 0
}

}
16 changes: 16 additions & 0 deletions accountant/accountant-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ spring:
prefer-ip-address: true
config:
import: vault://secret/${spring.application.name}
management:
health:
db:
enabled: true
endpoints:
web:
base-path: /actuator
exposure:
include: [ "health", "prometheus", "metrics" ]
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true
app:
address: 1
wallet:
Expand Down
5 changes: 5 additions & 0 deletions api/api-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<groupId>co.nilin.opex.utility.preferences</groupId>
<artifactId>preferences</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions api/api-app/src/main/kotlin/co/nilin/opex/api/app/ApiApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.ComponentScan
import org.springframework.scheduling.annotation.EnableScheduling
import springfox.documentation.swagger2.annotations.EnableSwagger2

@SpringBootApplication
@ComponentScan("co.nilin.opex")
@EnableScheduling
class ApiApp

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package co.nilin.opex.api.app.utils

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.health.HealthComponent
import org.springframework.boot.actuate.health.HealthEndpoint
import org.springframework.boot.actuate.health.SystemHealth
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class PrometheusHealthExtension(
private val registry: MeterRegistry,
private val endpoint: HealthEndpoint
) {

private var consulHealth = -1
private var r2dbcHealth = -1
private var vaultHealth = -1
private var vaultReactiveHealth = -1
private val service = "API"

init {
Gauge.builder("consul_health", consulHealth) { consulHealth.toDouble() }
.description("Health of consul connection")
.tag("Service", service)
.register(registry)

Gauge.builder("r2dbc_health", r2dbcHealth) { r2dbcHealth.toDouble() }
.description("Health of r2dbc connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vault_health", vaultHealth) { vaultHealth.toDouble() }
.description("Health of vault connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vaultReactive_health", vaultReactiveHealth) { vaultReactiveHealth.toDouble() }
.description("Health of vaultReactive connection")
.tag("Service", service)
.register(registry)
}

@Scheduled(initialDelay = 1000, fixedDelay = 5000)
fun updateHealth() {
try {
val health = endpoint.health() as SystemHealth
consulHealth = getHealthValue(health.components["consul"])
r2dbcHealth = getHealthValue(health.components["r2dbc"])
vaultHealth = getHealthValue(health.components["vault"])
vaultReactiveHealth = getHealthValue(health.components["vaultReactive"])
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun getHealthValue(health: HealthComponent?): Int {
health ?: return -1
return if (health.status.code == "UP") 1 else 0
}

}
13 changes: 13 additions & 0 deletions api/api-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ spring:
prefer-ip-address: true
config:
import: vault://secret/${spring.application.name}
management:
endpoints:
web:
base-path: /actuator
exposure:
include: ["health", "prometheus", "metrics"]
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true
app:
accountant:
url: lb://opex-accountant
Expand Down
5 changes: 5 additions & 0 deletions bc-gateway/bc-gateway-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package co.nilin.opex.bcgateway.app.utils

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.health.HealthComponent
import org.springframework.boot.actuate.health.HealthEndpoint
import org.springframework.boot.actuate.health.SystemHealth
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class PrometheusHealthExtension(
private val registry: MeterRegistry,
private val endpoint: HealthEndpoint
) {

private var consulHealth = -1
private var r2dbcHealth = -1
private var vaultHealth = -1
private var vaultReactiveHealth = -1
private val service = "BC_GATEWAY"

init {
Gauge.builder("consul_health", consulHealth) { consulHealth.toDouble() }
.description("Health of consul connection")
.tag("Service", service)
.register(registry)

Gauge.builder("r2dbc_health", r2dbcHealth) { r2dbcHealth.toDouble() }
.description("Health of r2dbc connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vault_health", vaultHealth) { vaultHealth.toDouble() }
.description("Health of vault connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vaultReactive_health", vaultReactiveHealth) { vaultReactiveHealth.toDouble() }
.description("Health of vaultReactive connection")
.tag("Service", service)
.register(registry)
}

@Scheduled(initialDelay = 1000, fixedDelay = 5000)
fun updateHealth() {
try {
val health = endpoint.health() as SystemHealth
consulHealth = getHealthValue(health.components["consul"])
r2dbcHealth = getHealthValue(health.components["r2dbc"])
vaultHealth = getHealthValue(health.components["vault"])
vaultReactiveHealth = getHealthValue(health.components["vaultReactive"])
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun getHealthValue(health: HealthComponent?): Int {
health ?: return -1
return if (health.status.code == "UP") 1 else 0
}

}
13 changes: 13 additions & 0 deletions bc-gateway/bc-gateway-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ spring:
import: vault://secret/${spring.application.name}
codec:
max-in-memory-size: 20MB
management:
endpoints:
web:
base-path: /actuator
exposure:
include: ["health", "prometheus", "metrics"]
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true
logging:
level:
org.apache.kafka: ERROR
Expand Down
5 changes: 5 additions & 0 deletions captcha/captcha-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import co.nilin.opex.utility.error.EnableOpexErrorHandler
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan
import org.springframework.scheduling.annotation.EnableScheduling

@SpringBootApplication
@ComponentScan("co.nilin.opex")
@EnableOpexErrorHandler
@EnableScheduling
class App

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package co.nilin.opex.captcha.app.utils

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.health.HealthComponent
import org.springframework.boot.actuate.health.HealthEndpoint
import org.springframework.boot.actuate.health.SystemHealth
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class PrometheusHealthExtension(
private val registry: MeterRegistry,
private val endpoint: HealthEndpoint
) {

private var consulHealth = -1
private var r2dbcHealth = -1
private var vaultHealth = -1
private var vaultReactiveHealth = -1
private val service = "CAPTCHA"

init {
Gauge.builder("consul_health", consulHealth) { consulHealth.toDouble() }
.description("Health of consul connection")
.tag("Service", service)
.register(registry)

Gauge.builder("r2dbc_health", r2dbcHealth) { r2dbcHealth.toDouble() }
.description("Health of r2dbc connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vault_health", vaultHealth) { vaultHealth.toDouble() }
.description("Health of vault connection")
.tag("Service", service)
.register(registry)

Gauge.builder("vaultReactive_health", vaultReactiveHealth) { vaultReactiveHealth.toDouble() }
.description("Health of vaultReactive connection")
.tag("Service", service)
.register(registry)
}

@Scheduled(initialDelay = 1000, fixedDelay = 5000)
fun updateHealth() {
try {
val health = endpoint.health() as SystemHealth
consulHealth = getHealthValue(health.components["consul"])
r2dbcHealth = getHealthValue(health.components["r2dbc"])
vaultHealth = getHealthValue(health.components["vault"])
vaultReactiveHealth = getHealthValue(health.components["vaultReactive"])
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun getHealthValue(health: HealthComponent?): Int {
health ?: return -1
return if (health.status.code == "UP") 1 else 0
}

}
Loading