diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index c607bcf3b..d05661c43 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -70,7 +70,7 @@ public class Admin extends BaseController { userDatasetProfile.setRole(0); getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile); datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile); - MetricsManager.increaseValue("totalTemplates", 1); + MetricsManager.increaseValue("argos_dataset_templates", 1, "total"); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); } @@ -89,7 +89,7 @@ public class Admin extends BaseController { eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile); if (datasetProfile.getStatus() == 1 && oldStatus == 0) { - MetricsManager.increaseValue("activeTemplates", 1); + MetricsManager.increaseValue("argos_dataset_templates", 1, "active"); } return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java index d9ec07835..ac75578d9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java @@ -95,7 +95,7 @@ public class Login { public @ResponseBody ResponseEntity<ResponseItem<PrincipalModel>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException { logger.info("Trying To Login With " + credentials.getProvider()); - MetricsManager.increaseValue("usersLoggedIn", 1); + MetricsManager.increaseValue("argos_users", 1, "loggedin"); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); } @@ -104,7 +104,7 @@ public class Login { public @ResponseBody ResponseEntity<ResponseItem<PrincipalModel>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException { logger.info(credentials.getUsername() + " Trying To Login"); - MetricsManager.increaseValue("usersLoggedIn", 1); + MetricsManager.increaseValue("argos_users", 1, "loggedin"); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PrincipalModel>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); } @@ -165,7 +165,7 @@ public class Login { ResponseEntity<ResponseItem<Principal>> logout(Principal principal) { this.nonVerifiedUserAuthenticationService.Logout(principal.getToken()); logger.info(principal + " Logged Out"); - MetricsManager.decreaseValue("usersLoggedIn", 1); + MetricsManager.decreaseValue("argos_users", 1, "loggedin"); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserGuideController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserGuideController.java index b65dcf671..6cb588eef 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserGuideController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserGuideController.java @@ -39,7 +39,7 @@ public class UserGuideController { @RequestMapping(path = "{lang}", method = RequestMethod.GET ) public ResponseEntity getUserGuide(@PathVariable(name = "lang") String lang) throws IOException { long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count(); - MetricsManager.calculateValue("languages", (int) files); + MetricsManager.calculateValue("argos_languages", (int) files, null); Stream<Path> walk = Files.walk(Paths.get(this.environment.getProperty("userguide.path"))); List<String> result = walk.filter(Files::isRegularFile) .map(Path::toString).collect(Collectors.toList()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index eea3b6cb3..80ba37918 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -376,7 +376,7 @@ public class DataManagementPlanManager { setNotification = true; } else { - MetricsManager.increaseValue("draftDMPs", 1); + MetricsManager.increaseValue("argos_managed_dmps", 1, "draft"); } DMP newDmp = dataManagementPlan.toDataModel(); @@ -500,7 +500,7 @@ public class DataManagementPlanManager { if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) throw new Exception("DMP is finalized, therefore cannot be edited."); } else { - MetricsManager.increaseValue("draftDMPs", 1); + MetricsManager.increaseValue("argos_managed_dmps", 1, "draft"); } List<Dataset> datasets = new ArrayList<>(); DMP tempDMP = dataManagementPlan.toDataModel(); @@ -616,7 +616,7 @@ public class DataManagementPlanManager { newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); this.updateIndex(newDmp); - MetricsManager.increaseValue("draftDMPs", 1); + MetricsManager.increaseValue("argos_managed_dmps", 1, "draft"); return newDmp.getId(); } @@ -630,16 +630,16 @@ public class DataManagementPlanManager { DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); switch (oldDmp.getStatus()) { case 0: - MetricsManager.decreaseValue("draftDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft"); break; case 1: if (oldDmp.getDoi() != null) { - MetricsManager.decreaseValue("doiedDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "doied"); } if (oldDmp.isPublic()) { - MetricsManager.decreaseValue("publishedDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "published"); } - MetricsManager.decreaseValue("finalizedDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "finalized"); break; } oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue()); @@ -679,7 +679,7 @@ public class DataManagementPlanManager { else { researcher.setCreationUser(user); researcherRepository.createOrUpdate(researcher); - MetricsManager.increaseValue("researchers", 1); + MetricsManager.increaseValue("argos_researchers", 1, null); } } } @@ -759,14 +759,14 @@ public class DataManagementPlanManager { project.setType(Project.ProjectType.EXTERNAL.getValue()); if (project.getId() == null) project.setId(UUID.randomUUID()); projectDao.createOrUpdate(project); - MetricsManager.increaseValue("projects", 1); + MetricsManager.increaseValue("argos_projects", 1, null); } } else { project.setType(Project.ProjectType.EXTERNAL.getValue()); if (project.getId() == null) project.setId(UUID.randomUUID()); projectDao.createOrUpdate(project); - MetricsManager.increaseValue("projects", 1); + MetricsManager.increaseValue("argos_projects", 1, null); } } } @@ -843,7 +843,7 @@ public class DataManagementPlanManager { return newDataset; }).thenApplyAsync(item -> { futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> { - MetricsManager.increaseValue("draftDatasets", 1); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft"); eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset(); datasetElastic.setId(dataset1.getId().toString()); datasetElastic.setLabel(dataset1.getLabel()); @@ -901,7 +901,7 @@ public class DataManagementPlanManager { dmp.setPublic(true); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); this.updateIndex(dmp); - MetricsManager.increaseValue("publishedDMPs", 1); + MetricsManager.increaseValue("argos_managed_dmps", 1, "published"); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); criteria.setGroupIds(Collections.singletonList(dmp.getGroupId())); criteria.setAllVersions(true); @@ -914,7 +914,7 @@ public class DataManagementPlanManager { tags = elastic.getTags(); } this.datasetManager.updateTags(dataset, tags); - MetricsManager.increaseValue("publishedDatasets", 1); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "published"); } catch (Exception e) { logger.error(e.getMessage(), e); } @@ -936,8 +936,8 @@ public class DataManagementPlanManager { dmp.setStatus(DMP.DMPStatus.FINALISED.getValue()); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); this.updateIndex(dmp); - MetricsManager.decreaseValue("draftDMPs", 1); - MetricsManager.increaseValue("finalizedDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft"); + MetricsManager.increaseValue("argos_managed_dmps", 1, "finalized"); List<Dataset> indexDatasets = new ArrayList<>(); if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() @@ -987,8 +987,8 @@ public class DataManagementPlanManager { sendNotification(dmp, user, NotificationType.DMP_FINALISED); } this.updateDatasetsIndex(indexDatasets); - MetricsManager.decreaseValue("draftDatasets", indexDatasets.size()); - MetricsManager.increaseValue("finalizedDatasets", indexDatasets.size()); + MetricsManager.decreaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "draft"); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "finalized"); } public void undoFinalize(UUID id, Principal principal) throws Exception { @@ -1000,8 +1000,8 @@ public class DataManagementPlanManager { dmp.setStatus(DMP.DMPStatus.ACTIVE.getValue()); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); this.updateIndex(dmp); - MetricsManager.decreaseValue("finalizedDMPs", 1); - MetricsManager.increaseValue("draftDMPs", 1); + MetricsManager.decreaseValue("argos_managed_dmps", 1, "finalized"); + MetricsManager.increaseValue("argos_managed_dmps", 1, "draft"); } public void updateUsers(UUID id, List<UserInfoListingModel> users, Principal principal) throws Exception { @@ -2094,6 +2094,16 @@ public class DataManagementPlanManager { return apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(criteria).count(); } + public long countAllFunders() { + FunderCriteria criteria = new FunderCriteria(); + return apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(criteria).count(); + } + + public long countAllGrants() { + GrantCriteria criteria = new GrantCriteria(); + return apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).count(); + } + /*public DataTableData<DataManagementPlanListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup, Principal principal) throws Exception { dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))); QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index ebce6f37b..867f688f1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -591,7 +591,7 @@ public class DatasetManager { sendNotification = true; } } else { - MetricsManager.increaseValue("draftDatasets", 1); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft"); } if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null) throw new Exception("DMP is finalized, therefore Dataset cannot be edited."); @@ -826,7 +826,7 @@ public class DatasetManager { if (dataset.getStatus() != eu.eudat.data.entities.Dataset.Status.FINALISED.getValue()) throw new Exception("You cannot make public a Dataset That Has not Been Finalised"); datasetDao.createOrUpdate(dataset); - MetricsManager.increaseValue("publishedDatasets", 1); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "published"); } public ResponseEntity<byte[]> getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType, Principal principal) throws IllegalAccessException, IOException, InstantiationException { @@ -915,7 +915,7 @@ public class DatasetManager { createServicesIfTheyDontExist(entity); createExternalDatasetsIfTheyDontExist(entity); - MetricsManager.increaseValue("draftDatasets", 1); + MetricsManager.increaseValue("argos_managed_dataset_descriptions", 1, "draft"); return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java index cf1a17e1a..e0ca4a8a9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java @@ -91,7 +91,7 @@ public class DatasetProfileManager { DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); profile.setId(null); - MetricsManager.increaseValue("totalTemplates", 1); + MetricsManager.increaseValue("argos_dataset_templates", 1, "total"); return profile; } @@ -231,7 +231,7 @@ public class DatasetProfileManager { File localFile = convert(multiPartFile); eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile); Files.deleteIfExists(localFile.toPath()); - MetricsManager.increaseValue("totalTemplates", 1); + MetricsManager.increaseValue("argos_dataset_templates", 1, "total"); return profile; } catch (IOException e) { logger.error(e.getMessage(), e); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java index 8fd39df2d..c8c28cfbd 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java @@ -21,44 +21,56 @@ import java.util.stream.Stream; public class MetricsManager { private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class); private static Map<String, Gauge> gauges = Stream.of( new Object[][]{ - {"usersLoggedIn", Gauge.build("users_logged_in", "Number of current logged in users").register()}, - {"projects", Gauge.build("projects", "Number of registered Projects").register()}, - {"draftDMPs", Gauge.build("draft_dmps", "Number of draft DMPs").register()}, - {"finalizedDMPs", Gauge.build("finalized_dmps", "Number of finalized DMPs").register()}, - {"publishedDMPs", Gauge.build("published_dmps", "Number of published DMPs").register()}, - {"doiedDMPs", Gauge.build("doied_dmps", "Number of DMPs with DOI").register()}, - {"draftDatasets", Gauge.build("draft_datasets", "Number of draft Datasets").register()}, - {"finalizedDatasets", Gauge.build("finalized_datasets", "Number of finalized Datasets").register()}, - {"publishedDatasets", Gauge.build("published_datasets", "Number of published Datasets").register()}, - {"doiedDatasets", Gauge.build("doied_datasets", "Number of Datasets with DOI").register()}, - {"researchers", Gauge.build("researchers", "Number of Colaborators/Researchers").register()}, - {"totalTemplates", Gauge.build("total_templates", "Number of total Templates").register()}, - {"activeTemplates", Gauge.build("active_templates", "Number of active Templates").register()}, - {"usedTemplates", Gauge.build("used_templates", "Number of used Templates").register()}, - {"languages", Gauge.build("languages", "Number of Languages").register()}, - {"totalUsers", Gauge.build("total_users", "Total Number of Users").register()} + {"argos_managed_dmps", Gauge.build().name("argos_managed_dmps").help("Number of managed DMPs").labelNames("status").register()}, + + {"argos_funders", Gauge.build().name("argos_funders").help("Number of registered Funders").register()}, + {"argos_grants", Gauge.build().name("argos_grants").help("Number of registered Grants").register()}, + {"argos_projects", Gauge.build().name("argos_projects").help("Number of registered Projects").register()}, + {"argos_researchers", Gauge.build().name("argos_researchers").help("Number of Colaborators/Researchers").register()}, + + {"argos_managed_dataset_descriptions", Gauge.build().name("argos_managed_dataset_descriptions").help("Number of managed Dataset Descriptions").labelNames("status").register()}, + + {"argos_dataset_templates", Gauge.build().name("argos_dataset_templates").help("Number of dataset Templates").labelNames("status").register()}, + + {"argos_users", Gauge.build().name("argos_users").help("Number of users").labelNames("type").register()}, + + {"argos_languages", Gauge.build().name("argos_languages").help("Number of Languages").register()}, + }).collect(Collectors.toMap(data -> (String)data[0], data -> (Gauge) data[1])); - public static void increaseValue(String name, int amount) { - gauges.get(name).inc(amount); + public static void increaseValue(String name, int amount, String label) { + + if(label != null) { + gauges.get(name).labels(label).inc(amount); + } else { + gauges.get(name).inc(amount); + } } - public static void decreaseValue(String name, int amount) { - gauges.get(name).dec(amount); + public static void decreaseValue(String name, int amount, String label) { + if(label != null) { + gauges.get(name).labels(label).dec(amount); + } else { + gauges.get(name).dec(amount); + } } - public static Integer getValue(String name) { - return Double.valueOf(gauges.get(name).get()).intValue(); + public static Integer getValue(String name, String label) { + if(label != null) { + return Double.valueOf(gauges.get(name).labels(label).get()).intValue(); + } else { + return Double.valueOf(gauges.get(name).get()).intValue(); + } } - public static void calculateValue(String name, int amount) { - Integer orig = getValue(name); + public static void calculateValue(String name, int amount, String label) { + Integer orig = getValue(name, label); int diff = orig - amount; if (diff != 0) { if (diff > 0) { - decreaseValue(name, diff); + decreaseValue(name, diff, label); } else { - increaseValue(name, Math.abs(diff)); + increaseValue(name, Math.abs(diff), label); } } } @@ -83,23 +95,31 @@ public class MetricsManager { @Scheduled(initialDelay = 1000 * 60 * 60, fixedDelay = 1000 * 60 * 60) public void init() throws IOException { logger.info("Start calculating Metrics"); - calculateValue("draftDMPs", (int) dataManagementPlanManager.countAllDrafts()); - calculateValue("finalizedDMPs", (int) dataManagementPlanManager.countAllFinalized()); - calculateValue("publishedDMPs", (int) dataManagementPlanManager.countAllPublished()); - calculateValue("doiedDMPs", (int) dataManagementPlanManager.countAllDoied()); - calculateValue("projects", (int) dataManagementPlanManager.countAllProjects()); - calculateValue("researchers", (int) dataManagementPlanManager.countAllResearchers()); - calculateValue("draftDatasets", (int) datasetManager.countAllDraft()); - calculateValue("finalizedDatasets", (int) datasetManager.countAllFinalized()); - calculateValue("publishedDatasets", (int) datasetManager.countAllPublic()); - calculateValue("doiedDatasets", (int) datasetManager.countAllWithDoi()); - calculateValue("totalTemplates", (int) datasetProfileManager.countAlldraft()); - calculateValue("activeTemplates", (int) datasetProfileManager.countAllFinalized()); - calculateValue("usedTemplates", (int) datasetProfileManager.countAllUsed()); - calculateValue("usersLoggedIn", userManager.countActiveUsers().intValue()); - calculateValue("totalUsers", userManager.countAllUsers().intValue()); + calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDrafts(), "draft"); + calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllFinalized(), "finalized"); + calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllPublished(), "published"); + calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDoied(), "doied"); + + calculateValue("argos_funders", (int) dataManagementPlanManager.countAllFunders(), null); + calculateValue("argos_grants", (int) dataManagementPlanManager.countAllGrants(), null); + calculateValue("argos_projects", (int) dataManagementPlanManager.countAllProjects(), null); + calculateValue("argos_researchers", (int) dataManagementPlanManager.countAllResearchers(), null); + + calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllDraft(), "draft"); + calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllFinalized(), "finalized"); + calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllPublic(), "published"); + calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllWithDoi(), "doied"); + + calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAlldraft(), "total"); + calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllFinalized(), "active"); + calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllUsed(), "used"); + + calculateValue("argos_users", (int) userManager.countActiveUsers().intValue(), "loggedin"); + calculateValue("argos_users", (int) userManager.countAllUsers().intValue(), "total"); + long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count(); - calculateValue("languages", (int) files); + calculateValue("argos_languages", (int) files, null); + logger.info("Metrics calculation Completed"); }