created method to retrieve total registered datasources and added an entry in prometheus metrics
This commit is contained in:
parent
03e0b8f472
commit
746f3bbfbe
|
@ -1,6 +1,8 @@
|
|||
package eu.dnetlib.repo.manager.controllers;
|
||||
|
||||
import eu.dnetlib.repo.manager.service.PiWikService;
|
||||
import eu.dnetlib.repo.manager.service.RepositoryService;
|
||||
import eu.dnetlib.repo.manager.service.RepositoryServiceImpl;
|
||||
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
||||
|
@ -10,6 +12,8 @@ import io.micrometer.core.instrument.binder.system.UptimeMetrics;
|
|||
import io.micrometer.prometheus.PrometheusConfig;
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import io.prometheus.client.exporter.common.TextFormat;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -22,18 +26,22 @@ import java.io.File;
|
|||
@RestController
|
||||
@RequestMapping("/actuator/prometheus")
|
||||
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
|
||||
private static final Logger LOGGER = Logger.getLogger(PrometheusController.class);
|
||||
|
||||
private final PiWikService piWikService;
|
||||
private final RepositoryService repositoryService;
|
||||
|
||||
@Autowired
|
||||
public PrometheusController(PiWikService piWikService) {
|
||||
public PrometheusController(PiWikService piWikService, RepositoryService repositoryService) {
|
||||
this.piWikService = piWikService;
|
||||
this.repositoryService = repositoryService;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, path = "", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String getPiwikMetrics() {
|
||||
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
|
||||
registry.counter("provide_usagecounts_repositories").increment(piWikService.getTotal());
|
||||
registry.counter("provide_repositories_registered").increment(repositoryService.getTotalRegisteredRepositories());
|
||||
registry.counter("provide_usagecounts_repositories_registered").increment(piWikService.getTotal());
|
||||
registry.counter("provide_usagecounts_repositories_validated").increment(piWikService.getValidated(true));
|
||||
|
||||
return registry.scrape(TextFormat.CONTENT_TYPE_OPENMETRICS_100);
|
||||
|
|
|
@ -55,6 +55,8 @@ public interface RepositoryService {
|
|||
String officialName, String requestSortBy, String order,
|
||||
int page, int pageSize) throws Exception;
|
||||
|
||||
int getTotalRegisteredRepositories();
|
||||
|
||||
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
|
||||
|
||||
Repository addRepository(String datatype, Repository repository) throws Exception;
|
||||
|
|
|
@ -19,6 +19,7 @@ import eu.dnetlib.repo.manager.service.security.RoleMappingService;
|
|||
import eu.dnetlib.repo.manager.utils.Converter;
|
||||
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -33,6 +34,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
|
|||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -310,6 +312,16 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalRegisteredRepositories() {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
||||
.queryParam("fromDate", "1900-01-01")
|
||||
.build().encode();
|
||||
|
||||
return restTemplate.getForObject(uriComponents.toUri(), Integer.class);
|
||||
}
|
||||
|
||||
private Repository updateRepositoryInfo(Repository r) throws JSONException {
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue