diff --git a/src/fr/devinsy/statoolinfos/core/Configuration.java b/src/fr/devinsy/statoolinfos/core/Configuration.java index ffe9cc7..f889edd 100644 --- a/src/fr/devinsy/statoolinfos/core/Configuration.java +++ b/src/fr/devinsy/statoolinfos/core/Configuration.java @@ -381,9 +381,9 @@ public class Configuration extends PathPropertyList * * @return the probe mode */ - public ProbeMode getProbeMode() + public ProbePeriod getProbeMode() { - ProbeMode result; + ProbePeriod result; String value = get("conf.probe.mode"); @@ -393,7 +393,7 @@ public class Configuration extends PathPropertyList } else { - result = ProbeMode.valueOf(StringUtils.upperCase(value)); + result = ProbePeriod.valueOf(StringUtils.upperCase(value)); } // diff --git a/src/fr/devinsy/statoolinfos/core/ProbeMode.java b/src/fr/devinsy/statoolinfos/core/ProbePeriod.java similarity index 97% rename from src/fr/devinsy/statoolinfos/core/ProbeMode.java rename to src/fr/devinsy/statoolinfos/core/ProbePeriod.java index 6d9bd80..198c58c 100644 --- a/src/fr/devinsy/statoolinfos/core/ProbeMode.java +++ b/src/fr/devinsy/statoolinfos/core/ProbePeriod.java @@ -21,7 +21,7 @@ package fr.devinsy.statoolinfos.core; /** * The Enum LogFilter. */ -public enum ProbeMode +public enum ProbePeriod { FULL, TODAY, diff --git a/src/fr/devinsy/statoolinfos/metrics/Prober.java b/src/fr/devinsy/statoolinfos/metrics/Prober.java index ab43ded..125d121 100644 --- a/src/fr/devinsy/statoolinfos/metrics/Prober.java +++ b/src/fr/devinsy/statoolinfos/metrics/Prober.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Factory; -import fr.devinsy.statoolinfos.core.ProbeMode; +import fr.devinsy.statoolinfos.core.ProbePeriod; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer; @@ -97,115 +97,125 @@ public class Prober System.out.println("Targets=" + types.toStringWithBrackets()); - PathCounters counters = new PathCounters(); - - // - if (types.containsAnyIgnoreCase("HttpAccessLog")) + if (configuration.getProbeMode() != null) { - logger.info("== Processing HttpAccessLog."); - String source = configuration.getProbeHttpAccessLogSource(); - String patternRegex = configuration.getProbeHttpAccessLogPattern(); - logger.info("source=[{}]", source); - logger.info("pattern=[{}]", patternRegex); + PathCounters counters = new PathCounters(); - PathCounters data = HttpAccessLogAnalyzer.probe(source, patternRegex); - counters.putAll(data); - } - - // - if (types.containsAnyIgnoreCase("HttpErrorLog")) - { - logger.info("== Processing HttpErrorLog."); - String source = configuration.getProbeHttpErrorLogSource(); - logger.info("source=[{}]", source); - - PathCounters data = HttpErrorLogAnalyzer.probe(source); - counters.putAll(data); - } - - // - if (types.containsAnyIgnoreCase("Framadate")) - { - logger.info("== Processing Framadate."); - String source = configuration.getProbeHttpErrorLogSource(); - logger.info("source=[{}]", source); - - // PathCounters data = HttpErrorLogAnalyzer.probe(source); - // counters.putAll(data); - } - - // - if (types.containsAnyIgnoreCase("Mumble")) - { - logger.info("== Processing Mumble."); - String source = configuration.getProbeHttpErrorLogSource(); - logger.info("source=[{}]", source); - - // PathCounters data = HttpErrorLogAnalyzer.probe(source); - // counters.putAll(data); - } - - // Filter. - logger.info("== Filtering"); - if (configuration.getProbeMode() == ProbeMode.TODAY) - { - logger.info("=== TODAY"); - counters = counters.searchByPeriod(LocalDate.now(), LocalDate.now()); - } - else if (configuration.getProbeMode() == ProbeMode.PREVIOUS_DAY) - { - logger.info("=== PREVIOUS_DAY"); - counters = counters.searchByPeriod(LocalDate.now().minusDays(1), LocalDate.now()); - } - else if (configuration.getProbeMode() == ProbeMode.PREVIOUS_DAYS_7) - { - logger.info("=== PREVIOUS_WEEK"); - counters = counters.searchByPeriod(LocalDate.now().minusDays(7), LocalDate.now()); - } - - // - File target = configuration.getProbeTarget(); - logger.info("target=[{}]", target); - - if (target == null) - { - throw new IllegalArgumentException("Undefined target."); - } - else - { - if (target.exists()) + // + if (types.containsAnyIgnoreCase("HttpAccessLog")) { - logger.info("ModeProbe=" + configuration.getProbeMode()); - if (configuration.getProbeMode() != ProbeMode.FULL) - { - // Load. - logger.info("== Reading previous target file."); - PathCounters previousCounters = readMetrics(target); - logger.info("previous size={}", previousCounters.size()); + logger.info("== Processing HttpAccessLog."); + String source = configuration.getProbeHttpAccessLogSource(); + String patternRegex = configuration.getProbeHttpAccessLogPattern(); + logger.info("source=[{}]", source); + logger.info("pattern=[{}]", patternRegex); - // Merge. - logger.info("== Merging"); - for (PathCounter counter : counters.values()) + PathCounters data = HttpAccessLogAnalyzer.probe(source, patternRegex); + counters.putAll(data); + } + + // + if (types.containsAnyIgnoreCase("HttpErrorLog")) + { + logger.info("== Processing HttpErrorLog."); + String source = configuration.getProbeHttpErrorLogSource(); + logger.info("source=[{}]", source); + + PathCounters data = HttpErrorLogAnalyzer.probe(source); + counters.putAll(data); + } + + // + if (types.containsAnyIgnoreCase("Framadate")) + { + logger.info("== Processing Framadate."); + String source = configuration.getProbeHttpErrorLogSource(); + logger.info("source=[{}]", source); + + // PathCounters data = HttpErrorLogAnalyzer.probe(source); + // counters.putAll(data); + } + + // + if (types.containsAnyIgnoreCase("Mumble")) + { + logger.info("== Processing Mumble."); + String source = configuration.getProbeHttpErrorLogSource(); + logger.info("source=[{}]", source); + + // PathCounters data = HttpErrorLogAnalyzer.probe(source); + // counters.putAll(data); + } + + // Filter. + logger.info("== Filtering"); + if (configuration.getProbeMode() == ProbePeriod.TODAY) + { + logger.info("=== TODAY"); + counters = counters.searchByPeriod(LocalDate.now(), LocalDate.now()); + } + else if (configuration.getProbeMode() == ProbePeriod.PREVIOUS_DAY) + { + logger.info("=== PREVIOUS_DAY"); + counters = counters.searchByPeriod(LocalDate.now().minusDays(1), LocalDate.now()); + } + else if (configuration.getProbeMode() == ProbePeriod.PREVIOUS_DAYS_7) + { + logger.info("=== PREVIOUS_WEEK"); + counters = counters.searchByPeriod(LocalDate.now().minusDays(7), LocalDate.now()); + } + + // + File target = configuration.getProbeTarget(); + logger.info("target=[{}]", target); + + if (target == null) + { + throw new IllegalArgumentException("Undefined target."); + } + else + { + if (target.exists()) + { + logger.info("ModeProbe=" + configuration.getProbeMode()); + if (configuration.getProbeMode() != ProbePeriod.FULL) { - PathCounter previousCounter = previousCounters.get(counter.getPath(), counter.getTimeMark()); - previousCounter.setCounter(counter.getCounter()); + // Load. + logger.info("== Reading previous target file."); + PathCounters previousCounters = readMetrics(target); + logger.info("previous size={}", previousCounters.size()); + + // Merge. + logger.info("== Merging"); + for (PathCounter counter : counters.values()) + { + PathCounter previousCounter = previousCounters.get(counter.getPath(), counter.getTimeMark()); + if (previousCounter == null) + { + previousCounters.put(counter); + } + else + { + previousCounter.setCounter(counter.getCounter()); + } + } + + // + counters = previousCounters; } // - counters = previousCounters; + logger.info("== Backing previous target file."); + target.renameTo(new File(target.getParentFile(), target.getName() + ".bak")); } - // - logger.info("== Backing previous target file."); - target.renameTo(new File(target.getParentFile(), target.getName() + ".bak")); + writeMetrics(target, counters); } - writeMetrics(target, counters); + // + logger.info("== Writing."); + logger.info("size={}", counters.size()); } - - // - logger.info("== Writing."); - logger.info("size={}", counters.size()); } /**