Add total Users metric

This commit is contained in:
George Kalampokis 2021-04-13 12:19:55 +03:00
parent e801bbf2e2
commit 961a4df270
2 changed files with 7 additions and 1 deletions

View File

@ -35,7 +35,8 @@ public class MetricsManager {
{"totalTemplates", Gauge.build("total_templates", "Number of total Templates").register()}, {"totalTemplates", Gauge.build("total_templates", "Number of total Templates").register()},
{"activeTemplates", Gauge.build("active_templates", "Number of active Templates").register()}, {"activeTemplates", Gauge.build("active_templates", "Number of active Templates").register()},
{"usedTemplates", Gauge.build("used_templates", "Number of used Templates").register()}, {"usedTemplates", Gauge.build("used_templates", "Number of used Templates").register()},
{"languages", Gauge.build("languages", "Number of Languages").register()} {"languages", Gauge.build("languages", "Number of Languages").register()},
{"totalUsers", Gauge.build("total_users", "Total Number of Users").register()}
}).collect(Collectors.toMap(data -> (String)data[0], data -> (Gauge) data[1])); }).collect(Collectors.toMap(data -> (String)data[0], data -> (Gauge) data[1]));
public static void increaseValue(String name, int amount) { public static void increaseValue(String name, int amount) {
@ -96,6 +97,7 @@ public class MetricsManager {
calculateValue("activeTemplates", (int) datasetProfileManager.countAllFinalized()); calculateValue("activeTemplates", (int) datasetProfileManager.countAllFinalized());
calculateValue("usedTemplates", (int) datasetProfileManager.countAllUsed()); calculateValue("usedTemplates", (int) datasetProfileManager.countAllUsed());
calculateValue("usersLoggedIn", userManager.countActiveUsers().intValue()); calculateValue("usersLoggedIn", userManager.countActiveUsers().intValue());
calculateValue("totalUsers", userManager.countAllUsers().intValue());
long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count(); long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count();
calculateValue("languages", (int) files); calculateValue("languages", (int) files);
logger.info("Metrics calculation Completed"); logger.info("Metrics calculation Completed");

View File

@ -249,4 +249,8 @@ public class UserManager {
return apiContext.getOperationsContext().getDatabaseRepository().getUserTokenDao().asQueryable().where(((builder, root) -> builder.greaterThan(root.get("expiresAt"), new Date()))).count(); return apiContext.getOperationsContext().getDatabaseRepository().getUserTokenDao().asQueryable().where(((builder, root) -> builder.greaterThan(root.get("expiresAt"), new Date()))).count();
} }
public Long countAllUsers(){
return apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().count();
}
} }