|
1 | 1 | package no.nav.foreldrepenger.abakus.app.metrics;
|
2 | 2 |
|
3 | 3 |
|
4 |
| -import io.prometheus.client.CollectorRegistry; |
5 |
| -import io.prometheus.client.Gauge; |
6 |
| -import io.prometheus.client.exporter.common.TextFormat; |
7 |
| -import io.swagger.v3.oas.annotations.Operation; |
8 |
| -import no.nav.vedtak.felles.prosesstask.api.TaskMonitor; |
| 4 | +import static no.nav.vedtak.log.metrics.MetricsUtil.REGISTRY; |
9 | 5 |
|
| 6 | +import io.swagger.v3.oas.annotations.Operation; |
10 | 7 | import jakarta.enterprise.context.ApplicationScoped;
|
11 | 8 | import jakarta.ws.rs.GET;
|
12 | 9 | import jakarta.ws.rs.Path;
|
13 |
| -import jakarta.ws.rs.core.Response; |
14 |
| - |
15 |
| -import java.io.IOException; |
16 |
| -import java.io.StringWriter; |
17 |
| -import java.io.Writer; |
18 | 10 |
|
19 | 11 | @Path("/metrics")
|
20 | 12 | @ApplicationScoped
|
21 | 13 | public class PrometheusRestService {
|
22 | 14 |
|
23 |
| - private static final Gauge TASK_GAUGE = Gauge.build().name("prosesstask_antall").labelNames("status").help("No tasks w/status.").register(); |
24 |
| - |
25 | 15 | @GET
|
26 | 16 | @Operation(tags = "metrics", hidden = true)
|
27 | 17 | @Path("/prometheus")
|
28 |
| - public Response prometheus() { |
29 |
| - TaskMonitor.monitoredStatuses().forEach(s -> TASK_GAUGE.labels(TaskMonitor.statusLabel(s)).set(TaskMonitor.TASK_GAUGES.get(s).get())); |
30 |
| - try (final Writer writer = new StringWriter()) { |
31 |
| - TextFormat.writeFormat(TextFormat.CONTENT_TYPE_004, writer, CollectorRegistry.defaultRegistry.metricFamilySamples()); |
32 |
| - return Response.ok().encoding("UTF-8").entity(writer.toString()).header("content-type", TextFormat.CONTENT_TYPE_004).build(); |
33 |
| - } catch (IOException e) { |
34 |
| - //TODO logg? |
35 |
| - } |
36 |
| - |
37 |
| - return null; |
| 18 | + public String prometheus() { |
| 19 | + return REGISTRY.scrape(); |
38 | 20 | }
|
39 | 21 | }
|
0 commit comments