コード例 #1
0
  private void resetDailyStats() {
    try {
      final Map<String, String> emailValues = new LinkedHashMap<>();
      for (final Statistic statistic : Statistic.values()) {
        final String key = statistic.getLabel(PwmConstants.DEFAULT_LOCALE);
        final String value = statsDaily.getStatistic(statistic);
        emailValues.put(key, value);
      }

      AlertHandler.alertDailyStats(pwmApplication, emailValues);
    } catch (Exception e) {
      LOGGER.error("error while generating daily alert statistics: " + e.getMessage());
    }

    currentDailyKey = new DailyKey(new Date());
    statsDaily = new StatisticsBundle();
    LOGGER.debug("reset daily statistics");
  }
コード例 #2
0
  public int outputStatsToCsv(
      final OutputStream outputStream, final Locale locale, final boolean includeHeader)
      throws IOException {
    LOGGER.trace("beginning output stats to csv process");
    final Date startTime = new Date();

    final StatisticsManager statsManger = pwmApplication.getStatisticsManager();
    final CSVPrinter csvPrinter = Helper.makeCsvPrinter(outputStream);

    if (includeHeader) {
      final List<String> headers = new ArrayList<>();
      headers.add("KEY");
      headers.add("YEAR");
      headers.add("DAY");
      for (Statistic stat : Statistic.values()) {
        headers.add(stat.getLabel(locale));
      }
      csvPrinter.printRecord(headers);
    }

    int counter = 0;
    final Map<StatisticsManager.DailyKey, String> keys =
        statsManger.getAvailableKeys(PwmConstants.DEFAULT_LOCALE);
    for (final StatisticsManager.DailyKey loopKey : keys.keySet()) {
      counter++;
      final StatisticsBundle bundle = statsManger.getStatBundleForKey(loopKey.toString());
      final List<String> lineOutput = new ArrayList<>();
      lineOutput.add(loopKey.toString());
      lineOutput.add(String.valueOf(loopKey.year));
      lineOutput.add(String.valueOf(loopKey.day));
      for (final Statistic stat : Statistic.values()) {
        lineOutput.add(bundle.getStatistic(stat));
      }
      csvPrinter.printRecord(lineOutput);
    }

    csvPrinter.flush();
    LOGGER.trace(
        "completed output stats to csv process; output "
            + counter
            + " records in "
            + TimeDuration.fromCurrent(startTime).asCompactString());
    return counter;
  }