Skip to content

Commit

Permalink
Forenkle MetricsUtils (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Dec 3, 2024
1 parent 017c131 commit e121891
Showing 1 changed file with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static io.micrometer.prometheusmetrics.PrometheusConfig.DEFAULT;

import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmInfoMetrics;
Expand All @@ -24,48 +23,24 @@ private MetricsUtil() {

static {
Metrics.addRegistry(REGISTRY);
// JVM
new ClassLoaderMetrics().bindTo(globalRegistry);
new JvmMemoryMetrics().bindTo(globalRegistry);
new JvmGcMetrics().bindTo(globalRegistry);
new ProcessorMetrics().bindTo(globalRegistry);
new JvmThreadMetrics().bindTo(globalRegistry);
new JvmInfoMetrics().bindTo(globalRegistry);
// System
new ProcessorMetrics().bindTo(globalRegistry);
new UptimeMetrics().bindTo(globalRegistry);
// Logging
new LogbackMetrics().bindTo(globalRegistry);
}

public static String scrape() {
return REGISTRY.scrape();
}

public static void timerUtenHistogram(String navn) {
timerMedPercentiler(navn, 0.5, 0.95, 0.99);
}

public static void timerMedianUtenHistogram(String navn) {
timerMedPercentiler(navn, 0.5);
}

public static void timerMedPercentiler(String navn, double... percentiles) {
Timer.builder(navn)
.publishPercentiles(percentiles)
.publishPercentileHistogram(false)
.register(globalRegistry);
}

public static void timerMedHistogram(String navn) {
timerMedHistogram(navn, 0.5, 0.95, 0.99);
}

public static void timerMedianMedHistogram(String navn) {
timerMedHistogram(navn, 0.5);
}

public static void timerMedHistogram(String navn, double... percentiles) {
Timer.builder(navn)
.publishPercentiles(percentiles)
.publishPercentileHistogram(true)
.register(globalRegistry);
}
// Til info Eksempel på timer med percentiler
// Timer.builder(navn).publishPercentiles(double... percentiles).publishPercentileHistogram(boolean).register(globalRegistry);

}

0 comments on commit e121891

Please sign in to comment.