Skip to content

Commit

Permalink
Fix hikaricp metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
tdroxler committed Aug 27, 2024
1 parent f1f2e5b commit 6c6d753
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/src/main/resources/grafana/explorer-backend-overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"type": "prometheus",
"uid": "FWwc47WVk"
},
"expr": "hikaricp_idle_connections",
"expr": "hikaricp_connections_idle",
"instant": true,
"interval": "",
"legendFormat": "",
Expand Down Expand Up @@ -355,7 +355,7 @@
"type": "prometheus",
"uid": "FWwc47WVk"
},
"expr": "hikaricp_pending_threads",
"expr": "hikaricp_connections_pending",
"instant": true,
"interval": "",
"legendFormat": "",
Expand Down Expand Up @@ -492,7 +492,7 @@
"type": "prometheus",
"uid": "FWwc47WVk"
},
"expr": "hikaricp_active_connections",
"expr": "hikaricp_connections_active",
"instant": true,
"interval": "",
"legendFormat": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.explorer
import java.sql.Driver

import com.typesafe.config.Config
import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory
import io.micrometer.core.instrument.Clock
import io.micrometer.core.instrument.binder.db.PostgreSQLDatabaseMetrics
import io.micrometer.prometheusmetrics.{PrometheusConfig, PrometheusMeterRegistry}
Expand All @@ -28,18 +27,20 @@ import slick.jdbc.hikaricp.HikariCPJdbcDataSource

object InstrumentedHikariCP extends JdbcDataSourceFactory {
override def forConfig(
c: Config,
config: Config,
driver: Driver,
name: String,
classLoader: ClassLoader
): JdbcDataSource = {
val hikariCPDataSource = HikariCPJdbcDataSource.forConfig(c, driver, name, classLoader)
hikariCPDataSource.ds.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory())
val databaseName = c.getString("name")
val pgMetrics = new PostgreSQLDatabaseMetrics(hikariCPDataSource.ds, databaseName)
val registry =
new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, Metrics.defaultRegistry, Clock.SYSTEM)
val hikariCPDataSource = HikariCPJdbcDataSource.forConfig(config, driver, name, classLoader)
val databaseName = config.getString("name")
val pgMetrics = new PostgreSQLDatabaseMetrics(hikariCPDataSource.ds, databaseName)

hikariCPDataSource.ds.setMetricRegistry(registry)
pgMetrics.bindTo(registry)

hikariCPDataSource
}
}

0 comments on commit 6c6d753

Please sign in to comment.