1 |
61450
|
spyroukon
|
package eu.dnetlib.repo.manager.controllers;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.repo.manager.service.PiWikService;
|
4 |
|
|
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
|
5 |
|
|
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
6 |
|
|
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
7 |
|
|
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
8 |
|
|
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
|
9 |
|
|
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
|
10 |
|
|
import io.micrometer.prometheus.PrometheusConfig;
|
11 |
|
|
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
12 |
|
|
import io.prometheus.client.exporter.common.TextFormat;
|
13 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
|
|
import org.springframework.http.MediaType;
|
15 |
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
16 |
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
17 |
|
|
import org.springframework.web.bind.annotation.RestController;
|
18 |
|
|
|
19 |
|
|
import java.io.File;
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
@RestController
|
23 |
|
|
@RequestMapping("/actuator/prometheus")
|
24 |
|
|
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
|
25 |
|
|
|
26 |
|
|
private final PiWikService piWikService;
|
27 |
|
|
|
28 |
|
|
@Autowired
|
29 |
|
|
public PrometheusController(PiWikService piWikService) {
|
30 |
|
|
this.piWikService = piWikService;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
@RequestMapping(method = RequestMethod.GET, path = "", produces = MediaType.TEXT_PLAIN_VALUE)
|
34 |
|
|
public String getPiwikMetrics() {
|
35 |
|
|
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
|
36 |
|
|
registry.counter("total").increment(piWikService.getTotal());
|
37 |
|
|
registry.counter("validated").increment(piWikService.getValidated(true));
|
38 |
|
|
|
39 |
|
|
return registry.scrape(TextFormat.CONTENT_TYPE_004);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
@RequestMapping(method = RequestMethod.GET, path = "metrics", produces = MediaType.TEXT_PLAIN_VALUE)
|
43 |
|
|
public String getMetrics() {
|
44 |
|
|
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
|
45 |
|
|
new JvmThreadMetrics().bindTo(registry);
|
46 |
|
|
new JvmGcMetrics().bindTo(registry);
|
47 |
|
|
new JvmMemoryMetrics().bindTo(registry);
|
48 |
|
|
new DiskSpaceMetrics(new File("/")).bindTo(registry);
|
49 |
|
|
new ProcessorMetrics().bindTo(registry); // metrics related to the CPU stats
|
50 |
|
|
new UptimeMetrics().bindTo(registry);
|
51 |
|
|
|
52 |
|
|
return registry.scrape(TextFormat.CONTENT_TYPE_004);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
}
|