adding api url property
This commit is contained in:
parent
2613c1dd8a
commit
bb14c55744
|
@ -7,6 +7,7 @@ import eu.dnetlib.dnetexploremetrics.model.Metrics;
|
|||
import eu.dnetlib.dnetexploremetrics.utils.PrometheusMetricsFormatter;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
@ -20,6 +21,9 @@ public class MetricsService {
|
|||
@Autowired
|
||||
private MetricsDAO metricsDAO;
|
||||
|
||||
@Value("${search.service.api.url:https://services.openaire.eu/search/v2/api/}")
|
||||
private String searchUrl;
|
||||
|
||||
private final String recordsRequest = "results?size=0&format=json";
|
||||
private final String publicationsRequest = "publications?size=0&format=json";
|
||||
private final String datasetsRequest = "datasets?size=0&format=json";
|
||||
|
@ -35,55 +39,56 @@ public class MetricsService {
|
|||
" or reldatasourcecompatibilityid exact hostedBy or relproject=*))&type=organizations&size=0&format=json";
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
@Scheduled(cron = "0 0/1 * * * *")
|
||||
//@Scheduled(cron = "0 0 0 * * ?")
|
||||
private void calculateMetrics() {
|
||||
System.out.println("Calculating metrics...");
|
||||
Metrics metrics = new Metrics();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
System.out.println(searchUrl);
|
||||
ResponseEntity<String> response
|
||||
= restTemplate.getForEntity("https://services.openaire.eu/search/v2/api/" + recordsRequest, String.class);
|
||||
= restTemplate.getForEntity(searchUrl + recordsRequest, String.class);
|
||||
|
||||
JSONObject jsonObject = new JSONObject(response.getBody());
|
||||
metrics.records= jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + publicationsRequest, String.class);
|
||||
getForEntity(searchUrl + publicationsRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.publications = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + datasetsRequest, String.class);
|
||||
getForEntity(searchUrl + datasetsRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.datasets = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + softwareRequest, String.class);
|
||||
getForEntity(searchUrl + softwareRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.software = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + orpRequest, String.class);
|
||||
getForEntity(searchUrl + orpRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.orp = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + fundersRequest, String.class);
|
||||
getForEntity(searchUrl + fundersRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.funders = jsonObject.getJSONObject("refineResults").getJSONArray("relfunder").length()+"";
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + projectsRequest, String.class);
|
||||
getForEntity(searchUrl + projectsRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.projects = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + contentProvidersRequest, String.class);
|
||||
getForEntity(searchUrl + contentProvidersRequest, String.class);
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.contentProviders = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
||||
System.out.println("https://services.openaire.eu/search/v2/api/" + organizationsRequest);
|
||||
response = restTemplate.
|
||||
getForEntity("https://services.openaire.eu/search/v2/api/" + organizationsRequest, String.class);
|
||||
getForEntity(searchUrl + organizationsRequest, String.class);
|
||||
|
||||
jsonObject = new JSONObject(response.getBody());
|
||||
metrics.organizations = jsonObject.getJSONObject("meta").get("total").toString();
|
||||
|
|
|
@ -7,10 +7,10 @@ public class PrometheusMetricsFormatter {
|
|||
|
||||
private enum PrometheusMetrics {
|
||||
RECORDS("# TYPE explore_total_records gauge\nexplore_total_records %s"),
|
||||
PUBLICATIONS("# TYPE explore_total_publications gauge\nexplore_total_publications %s"),
|
||||
DATASETS("# TYPE explore_total_datasets gauge\nexplore_total_datasets %s"),
|
||||
SOFTWARE("# TYPE explore_total_software gauge\nexplore_total_software %s"),
|
||||
ORP("# TYPE explore_total_otherresearchproducts gauge\nexplore_total_otherresearchproducts %s"),
|
||||
PUBLICATIONS("# TYPE explore_records gauge\nexplore_records{type=\"publications\"} %s"),
|
||||
DATASETS("# TYPE explore_total_datasets gauge\nexplore_records{type=\"datasets\"} %s"),
|
||||
SOFTWARE("# TYPE explore_total_software gauge\nexplore_records{type=\"explore_total_software\"} %s"),
|
||||
ORP("# TYPE explore_total_otherresearchproducts gauge\nexplore_records{type=\"otherresearchproducts\"} %s"),
|
||||
FUNDERS("# TYPE explore_total_funders gauge\nexplore_total_funders %s"),
|
||||
PROJECTS("#TYPE explore_total_projects gauge\nexplore_total_projects %s"),
|
||||
CONTENT_PROVIDERS("#TYPE explore_total_contentproviders gauge\nexplore_total_contentproviders %s"),
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
search.service.url = http://services.openaire.eu/search/
|
||||
search.service.api.url = https://services.openaire.eu/search/v2/api/
|
||||
server.port=8180
|
||||
|
|
Loading…
Reference in New Issue