public static void incrementStat(final PwmApplication pwmApplication, final Statistic statistic) { if (pwmApplication == null) { LOGGER.error( "skipping requested statistic increment of " + statistic + " due to null pwmApplication"); return; } final StatisticsManager statisticsManager = pwmApplication.getStatisticsManager(); if (statisticsManager == null) { LOGGER.error( "skipping requested statistic increment of " + statistic + " due to null statisticsManager"); return; } if (statisticsManager.status() != STATUS.OPEN) { LOGGER.trace( "skipping requested statistic increment of " + statistic + " due to StatisticsManager being closed"); return; } statisticsManager.incrementValue(statistic); }
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; }
private void initialize(final boolean initLogging) throws PwmUnrecoverableException { final Date startTime = new Date(); // initialize log4j if (initLogging) { final String log4jFileName = configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_LOG4JCONFIG_FILE); final File log4jFile = Helper.figureFilepath(log4jFileName, applicationPath); final String consoleLevel, fileLevel; switch (getApplicationMode()) { case ERROR: case NEW: consoleLevel = PwmLogLevel.TRACE.toString(); fileLevel = PwmLogLevel.TRACE.toString(); break; default: consoleLevel = configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_STDOUT_LEVEL); fileLevel = configuration.readSettingAsString(PwmSetting.EVENTS_FILE_LEVEL); break; } PwmLogManager.initializeLogger( this, configuration, log4jFile, consoleLevel, applicationPath, fileLevel); switch (getApplicationMode()) { case RUNNING: break; case ERROR: LOGGER.fatal( "starting up in ERROR mode! Check log or health check information for cause"); break; default: LOGGER.trace( "setting log level to TRACE because application mode is " + getApplicationMode()); break; } } LOGGER.info( "initializing, application mode=" + getApplicationMode() + ", applicationPath=" + (applicationPath == null ? "null" : applicationPath.getAbsolutePath()) + ", configurationFile=" + (configurationFile == null ? "null" : configurationFile.getAbsolutePath())); this.localDB = Initializer.initializeLocalDB(this); this.localDBLogger = PwmLogManager.initializeLocalDBLogger(this); // log the loaded configuration LOGGER.info("configuration load completed"); // read the pwm servlet instance id instanceID = fetchInstanceID(localDB, this); LOGGER.info("using '" + getInstanceID() + "' for instance's ID (instanceID)"); // read the pwm installation date installTime = fetchInstallDate(startupTime); LOGGER.debug( "this application instance first installed on " + PwmConstants.DEFAULT_DATETIME_FORMAT.format(installTime)); initServices(); final TimeDuration totalTime = TimeDuration.fromCurrent(startTime); LOGGER.info( PwmConstants.PWM_APP_NAME + " " + PwmConstants.SERVLET_VERSION + " open for bidness! (" + totalTime.asCompactString() + ")"); StatisticsManager.incrementStat(this, Statistic.PWM_STARTUPS); LOGGER.debug( "buildTime=" + PwmConstants.BUILD_TIME + ", javaLocale=" + Locale.getDefault() + ", DefaultLocale=" + PwmConstants.DEFAULT_LOCALE); final Thread postInitThread = new Thread() { @Override public void run() { postInitTasks(); } }; postInitThread.setDaemon(true); postInitThread.setName(Helper.makeThreadName(this, PwmApplication.class)); postInitThread.start(); }