Skip to content

Commit

Permalink
Merge pull request #14 from Ecwid/update-prometheus-1.0
Browse files Browse the repository at this point in the history
Update prometheus to 1.1
  • Loading branch information
vgv authored Apr 19, 2024
2 parents a0282b5 + eab334c commit 8432f14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Add prometheus metric dependency to your project

gradle
```
compile "io.prometheus:simpleclient:0.16.0"
compile "io.prometheus:prometheus-metrics-core:1.2.0"
```

Inject metrics collector on instantiate client
Expand Down
16 changes: 7 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
kotlin("jvm") version "1.6.10"
kotlin("jvm") version "1.9.23"
signing
`maven-publish`
id("com.netflix.nebula.release") version "17.2.2"
Expand All @@ -19,17 +19,15 @@ dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))

implementation("com.google.code.gson:gson:2.9.0")
implementation("com.google.code.gson:gson:2.10.1")

implementation("org.apache.httpcomponents:httpcore:4.4.15")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
implementation("org.apache.httpcomponents:httpcore:4.4.16")
implementation("org.apache.httpcomponents:httpclient:4.5.14")

compileOnly("io.prometheus:simpleclient:0.16.0")
compileOnly("io.prometheus:prometheus-metrics-core:1.2.0")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("org.mockito:mockito-core:2.15.0")
testImplementation("org.hamcrest:hamcrest-library:1.3")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.slf4j:slf4j-simple:1.7.36")
}

Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/com/ecwid/clickhouse/metrics/PrometheusMetrics.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
package com.ecwid.clickhouse.metrics

import io.prometheus.client.Counter
import io.prometheus.client.Summary
import io.prometheus.metrics.core.metrics.Counter
import io.prometheus.metrics.core.metrics.Summary


/**
* Metrics will be collected to prometheus lib
*/
class PrometheusMetrics : Metrics {
override fun startRequestTimer(host: String): AutoCloseable {
return requestsLatencySummary.labels(host).startTimer()
return requestsLatencySummary.labelValues(host).startTimer()
}

override fun measureRequest(host: String, statusCode: Int) {
requestsCounter.labels(host, statusCode.toString()).inc()
requestsCounter.labelValues(host, statusCode.toString()).inc()
}

companion object {
private val requestsLatencySummary = Summary.Builder()
.subsystem("clickhouse_client")
.name("requests_latency_seconds")
private val requestsLatencySummary = Summary.builder()
.name("clickhouse_client_requests_latency_seconds")
.help("Latency of requests in seconds")
.labelNames("host")
.quantile(0.5, 0.01)
.quantile(0.95, 0.01)
.quantile(0.99, 0.01)
.register()

private val requestsCounter = Counter.Builder()
.subsystem("clickhouse_client")
.name("requests_total")
private val requestsCounter = Counter.builder()
.name("clickhouse_client_requests_total")
.help("Total number of requests")
.labelNames("host", "http_code")
.register()
Expand Down

0 comments on commit 8432f14

Please sign in to comment.