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());
}
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);
}
}
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;
}
Aggregations