Search in sources :

Example 6 with StatisticsManager

use of password.pwm.svc.stats.StatisticsManager in project pwm by pwm-project.

the class ExportStatsCommand method doCommand.

@Override
void doCommand() throws Exception {
    final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
    final StatisticsManager statsManger = pwmApplication.getStatisticsManager();
    JavaHelper.pause(1000);
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    final long startTime = System.currentTimeMillis();
    out("beginning output to " + outputFile.getAbsolutePath());
    final int counter;
    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile, true)) {
        counter = statsManger.outputStatsToCsv(fileOutputStream, Locale.getDefault(), true);
        fileOutputStream.close();
    }
    out("completed writing " + counter + " rows of stats output in " + TimeDuration.fromCurrent(startTime).asLongString());
}
Also used : PwmApplication(password.pwm.PwmApplication) StatisticsManager(password.pwm.svc.stats.StatisticsManager) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 7 with StatisticsManager

use of password.pwm.svc.stats.StatisticsManager in project pwm by pwm-project.

the class RestStatisticsServer method doPwmStatisticJsonGet.

@RestMethodHandler(method = HttpMethod.GET, consumes = HttpContentType.form, produces = HttpContentType.json)
public RestResultBean doPwmStatisticJsonGet(final RestRequest restRequest) throws PwmUnrecoverableException {
    final String statKey = restRequest.readParameterAsString("statKey", PwmHttpRequestWrapper.Flag.BypassValidation);
    final String statName = restRequest.readParameterAsString("statName", PwmHttpRequestWrapper.Flag.BypassValidation);
    final String days = restRequest.readParameterAsString("days", PwmHttpRequestWrapper.Flag.BypassValidation);
    try {
        final StatisticsManager statisticsManager = restRequest.getPwmApplication().getStatisticsManager();
        final JsonOutput jsonOutput = new JsonOutput();
        jsonOutput.EPS = addEpsStats(statisticsManager);
        if (statName != null && statName.length() > 0) {
            jsonOutput.nameData = doNameStat(statisticsManager, statName, days);
        } else {
            jsonOutput.keyData = doKeyStat(statisticsManager, statKey);
        }
        StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_STATISTICS);
        final RestResultBean resultBean = RestResultBean.withData(jsonOutput);
        return resultBean;
    } catch (Exception e) {
        final String errorMsg = "unexpected error building json response: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        return RestResultBean.fromError(restRequest, errorInformation);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) StatisticsManager(password.pwm.svc.stats.StatisticsManager) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) RestResultBean(password.pwm.ws.server.RestResultBean) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 8 with StatisticsManager

use of password.pwm.svc.stats.StatisticsManager in project pwm by pwm-project.

the class AdminServlet method restStatisticsHandler.

@ActionHandler(action = "statistics")
private ProcessStatus restStatisticsHandler(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException {
    final String statKey = pwmRequest.readParameterAsString("statKey");
    final String statName = pwmRequest.readParameterAsString("statName");
    final String days = pwmRequest.readParameterAsString("days");
    final StatisticsManager statisticsManager = pwmRequest.getPwmApplication().getStatisticsManager();
    final RestStatisticsServer.JsonOutput jsonOutput = new RestStatisticsServer.JsonOutput();
    jsonOutput.EPS = RestStatisticsServer.addEpsStats(statisticsManager);
    if (statName != null && statName.length() > 0) {
        jsonOutput.nameData = RestStatisticsServer.doNameStat(statisticsManager, statName, days);
    } else {
        jsonOutput.keyData = RestStatisticsServer.doKeyStat(statisticsManager, statKey);
    }
    final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : StatisticsManager(password.pwm.svc.stats.StatisticsManager) RestStatisticsServer(password.pwm.ws.server.rest.RestStatisticsServer) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

StatisticsManager (password.pwm.svc.stats.StatisticsManager)8 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 ErrorInformation (password.pwm.error.ErrorInformation)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 PwmApplication (password.pwm.PwmApplication)2 LocalSessionStateBean (password.pwm.bean.LocalSessionStateBean)2 PwmException (password.pwm.error.PwmException)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)2 IntruderManager (password.pwm.svc.intruder.IntruderManager)2 RestResultBean (password.pwm.ws.server.RestResultBean)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)1 DirectoryVendor (com.novell.ldapchai.provider.DirectoryVendor)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1