From 03d7661ba9ac86596df2b6750c2f416fab7ced42 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 18 Apr 2022 20:34:54 +0200 Subject: [PATCH] Added GSL metric generator. --- README.md | 10 ++ .../devinsy/statoolinfos/metrics/Prober.java | 13 +++ .../statoolinfos/metrics/gsl/GSLProber.java | 106 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/fr/devinsy/statoolinfos/metrics/gsl/GSLProber.java diff --git a/README.md b/README.md index 85ecd86..d500e63 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,16 @@ conf.probe.gitea.database.password= conf.probe.target=/srv/statoolinfos/well-known/statoolinfos/foo.bar.org-metrics.properties ``` +### GSL metrics + +Configuration template: + +``` +conf.probe.types=GSL +conf.probe.gsl.stats=/foo/bar/stats.properties +conf.probe.target=/srv/statoolinfos/well-known/statoolinfos/foo.bar.org-metrics.properties +``` + ### LibreQR metrics Configuration template: diff --git a/src/fr/devinsy/statoolinfos/metrics/Prober.java b/src/fr/devinsy/statoolinfos/metrics/Prober.java index b6b4a5e..4bdca7d 100644 --- a/src/fr/devinsy/statoolinfos/metrics/Prober.java +++ b/src/fr/devinsy/statoolinfos/metrics/Prober.java @@ -40,6 +40,7 @@ import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.metrics.etherpad.EtherpadProber; import fr.devinsy.statoolinfos.metrics.gitea.GiteaProber; +import fr.devinsy.statoolinfos.metrics.gsl.GSLProber; import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer; import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer; import fr.devinsy.statoolinfos.metrics.libreqr.LibreQRProber; @@ -184,6 +185,18 @@ public class Prober counters.putAll(metrics); } + // + if (types.containsAnyIgnoreCase("GSL")) + { + logger.info("== Probing GSL."); + + File statsFile = configuration.getAsFile("conf.probe.gsl.stats"); + logger.info("statsfile=[{}]", statsFile); + + PathCounters data = GSLProber.probe(statsFile); + counters.putAll(data); + } + // if (types.containsAnyIgnoreCase("LibreQR")) { diff --git a/src/fr/devinsy/statoolinfos/metrics/gsl/GSLProber.java b/src/fr/devinsy/statoolinfos/metrics/gsl/GSLProber.java new file mode 100644 index 0000000..6ef0cd6 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/metrics/gsl/GSLProber.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2022 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.metrics.gsl; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +import org.apache.commons.lang3.math.NumberUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.PathCounters; +import fr.devinsy.strings.StringList; + +/** + * The Class GSLProber. + */ +public class GSLProber +{ + private static Logger logger = LoggerFactory.getLogger(GSLProber.class); + + /** + * Instantiates a new GSL prober. + */ + private GSLProber() + { + } + + /** + * Probe. + * + * @param httpLogs + * the http logs + * @param httpLogRegex + * the http log regex + * @param dataPath + * the data path + * @return the path counters + * @throws IOException + * Signals that an I/O exception has occurred. + * @throws StatoolInfosException + * the statool infos exception + */ + public static PathCounters probe(final File statsFile) throws IOException, StatoolInfosException + { + PathCounters result; + + result = new PathCounters(); + + // + Properties properties = new Properties(); + properties.load(new FileReader(statsFile)); + + StringList timemarks = result.getNowTimeMarks(); + + // metrics.gsl.articles = + String value = properties.getProperty("gsl.articles"); + if (NumberUtils.isDigits(value)) + { + result.set(Long.valueOf(value), "metrics.gsl.articles", timemarks); + } + + // metrics.gsl.articles.pages= + value = properties.getProperty("gsl.articles.pages"); + if (NumberUtils.isDigits(value)) + { + result.set(Long.valueOf(value), "metrics.gsl.articles.pages", timemarks); + } + + // metrics.gsl.articles.posts= + value = properties.getProperty("gsl.articles.posts"); + if (NumberUtils.isDigits(value)) + { + result.set(Long.valueOf(value), "metrics.gsl.articles.posts", timemarks); + } + + // metrics.gsl.authors = + value = properties.getProperty("gsl.authors"); + if (NumberUtils.isDigits(value)) + { + result.set(Long.valueOf(value), "metrics.gsl.authors", timemarks); + } + + // + return result; + } +}