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