Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bom 331, fikse metrikker #1364

Merged
merged 1 commit into from
Jun 4, 2024
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package no.nav.vedtak.log.metrics;

import static io.micrometer.core.instrument.Metrics.globalRegistry;
import static io.micrometer.prometheus.PrometheusConfig.DEFAULT;
import static io.micrometer.prometheusmetrics.PrometheusConfig.DEFAULT;

import io.micrometer.core.instrument.Meter.Id;
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 @@ -13,9 +13,7 @@
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.core.instrument.config.MeterFilter;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;

public class MetricsUtil {
public static final PrometheusMeterRegistry REGISTRY = new PrometheusMeterRegistry(DEFAULT);
Expand All @@ -40,36 +38,34 @@ 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 utvidMedMedian(String navn) {
utvidMedPercentiler(navn, 0.5);
public static void timerMedPercentiler(String navn, double... percentiles) {
Timer.builder(navn)
.publishPercentiles(percentiles)
.publishPercentileHistogram(false)
.register(globalRegistry);
}

public static void utvidMedPercentiler(String navn, double... percentiles) {
globalRegistry.config().meterFilter(new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Id id, DistributionStatisticConfig config) {
if (id.getName().equals(navn)) {
return DistributionStatisticConfig.builder().percentilesHistogram(false).percentiles(percentiles).build().merge(config);
}
return config;
}
});
public static void timerMedHistogram(String navn) {
timerMedHistogram(navn, 0.5, 0.95, 0.99);
}

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

public static void utvidMedHistogram(String navn, double... percentiles) {
globalRegistry.config().meterFilter(new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Id id, DistributionStatisticConfig config) {
if (id.getName().equals(navn)) {
return DistributionStatisticConfig.builder().percentilesHistogram(true).percentiles(percentiles).build().merge(config);
}
return config;
}
});
public static void timerMedHistogram(String navn, double... percentiles) {
Timer.builder(navn)
.publishPercentiles(percentiles)
.publishPercentileHistogram(true)
.register(globalRegistry);
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>no.nav.foreldrepenger.felles</groupId>
<artifactId>fp-bom</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
</parent>

<artifactId>felles-root</artifactId>
Expand All @@ -33,7 +33,7 @@
<dependency>
<groupId>no.nav.foreldrepenger.felles</groupId>
<artifactId>fp-bom</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down