Search in sources :

Example 1 with PwmNumberFormat

use of password.pwm.util.java.PwmNumberFormat in project pwm by pwm-project.

the class LocalDBLogger method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> healthRecords = new ArrayList<>();
    if (status != STATUS.OPEN) {
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_NOTOPEN, status.toString()));
        return healthRecords;
    }
    final int eventCount = getStoredEventCount();
    if (eventCount > settings.getMaxEvents() + 5000) {
        final PwmNumberFormat numberFormat = PwmNumberFormat.forDefaultLocale();
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_HighRecordCount, numberFormat.format(eventCount), numberFormat.format(settings.getMaxEvents())));
    }
    final Instant tailDate = getTailDate();
    if (tailDate != null) {
        final TimeDuration timeDuration = TimeDuration.fromCurrent(tailDate);
        final TimeDuration maxTimeDuration = settings.getMaxAge().add(TimeDuration.HOUR);
        if (timeDuration.isLongerThan(maxTimeDuration)) {
            // older than max age + 1h
            healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_OldRecordPresent, timeDuration.asCompactString(), maxTimeDuration.asCompactString()));
        }
    }
    return healthRecords;
}
Also used : HealthRecord(password.pwm.health.HealthRecord) PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration)

Example 2 with PwmNumberFormat

use of password.pwm.util.java.PwmNumberFormat in project pwm by pwm-project.

the class ReportStatusBean method makeReportStatusData.

public static ReportStatusBean makeReportStatusData(final ReportService reportService, final Locale locale) throws LocalDBException {
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    final ReportStatusBean returnMap = new ReportStatusBean();
    final ReportStatusInfo reportInfo = reportService.getReportStatusInfo();
    final LinkedHashMap<String, Object> presentableMap = new LinkedHashMap<>();
    final Set<ReportService.ReportCommand> availableCommands = new HashSet<>();
    presentableMap.put("Job Engine", reportInfo.getCurrentProcess().getLabel());
    switch(reportInfo.getCurrentProcess()) {
        case RollOver:
            {
                presentableMap.put("Users Processed", numberFormat.format(reportService.getSummaryData().getTotalUsers()) + " of " + numberFormat.format(reportService.getTotalRecords()));
                availableCommands.add(ReportService.ReportCommand.Stop);
            }
            break;
        case ReadData:
            {
                presentableMap.put("Users Processed", numberFormat.format(reportInfo.getCount()));
                presentableMap.put("Users Remaining", numberFormat.format(reportService.getWorkQueueSize()));
                if (reportInfo.getJobDuration() != null) {
                    presentableMap.put("Job Time", reportInfo.getJobDuration().asLongString(locale));
                }
                if (reportInfo.getCount() > 0) {
                    final BigDecimal eventRate = reportService.getEventRate().setScale(2, RoundingMode.UP);
                    presentableMap.put("Users/Second", eventRate);
                    if (!eventRate.equals(BigDecimal.ZERO)) {
                        final int usersRemaining = reportService.getWorkQueueSize();
                        final float secondsRemaining = usersRemaining / eventRate.floatValue();
                        final TimeDuration remainingDuration = new TimeDuration(((int) secondsRemaining) * 1000);
                        presentableMap.put("Estimated Time Remaining", remainingDuration.asLongString(locale));
                    }
                }
                availableCommands.add(ReportService.ReportCommand.Stop);
            }
            break;
        case None:
            {
                if (reportInfo.getFinishDate() != null) {
                    presentableMap.put("Last Job Completed", reportInfo.getFinishDate());
                }
                availableCommands.add(ReportService.ReportCommand.Start);
                if (reportService.getTotalRecords() > 0) {
                    availableCommands.add(ReportService.ReportCommand.Clear);
                }
            }
            break;
        default:
            break;
    }
    {
        if (reportInfo.getErrors() > 0) {
            presentableMap.put("Error Count", numberFormat.format(reportInfo.getErrors()));
        }
        if (reportInfo.getLastError() != null) {
            presentableMap.put("Last Error", reportInfo.getLastError().toDebugStr());
        }
        final int totalRecords = reportService.getTotalRecords();
        presentableMap.put("Records in Cache", numberFormat.format(totalRecords));
        if (totalRecords > 0) {
            presentableMap.put("Mean Record Cache Time", reportService.getSummaryData().getMeanCacheTime());
        }
    }
    returnMap.setControllable(true);
    returnMap.setRaw(reportInfo);
    returnMap.setPresentable(presentableMap);
    returnMap.setAvailableCommands(availableCommands);
    return returnMap;
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) ReportStatusInfo(password.pwm.svc.report.ReportStatusInfo) TimeDuration(password.pwm.util.java.TimeDuration) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 3 with PwmNumberFormat

use of password.pwm.util.java.PwmNumberFormat in project pwm by pwm-project.

the class AppDashboardData method makeAboutJavaData.

private static List<DisplayElement> makeAboutJavaData(final PwmApplication pwmApplication, final Locale locale) {
    final Map<PwmAboutProperty, String> aboutMap = PwmAboutProperty.makeInfoBean(pwmApplication);
    final List<DisplayElement> javaInfo = new ArrayList<>();
    final String notApplicable = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    {
        final List<PwmAboutProperty> interestedProperties = Arrays.asList(PwmAboutProperty.java_vmName, PwmAboutProperty.java_vmVendor, PwmAboutProperty.java_vmVersion, PwmAboutProperty.java_runtimeVersion, PwmAboutProperty.java_vmLocation, PwmAboutProperty.java_appServerInfo, PwmAboutProperty.java_osName, PwmAboutProperty.java_osVersion, PwmAboutProperty.java_osArch, PwmAboutProperty.java_memoryFree, PwmAboutProperty.java_memoryAllocated, PwmAboutProperty.java_memoryMax, PwmAboutProperty.java_threadCount);
        for (final PwmAboutProperty property : interestedProperties) {
            javaInfo.add(new DisplayElement(property.name(), DisplayElement.Type.string, property.getLabel(), aboutMap.getOrDefault(property, notApplicable)));
        }
    }
    {
        final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
        final String display = numberFormat.format(pwmApplication.getResourceServletService().itemsInCache()) + "items (" + numberFormat.format(pwmApplication.getResourceServletService().bytesInCache()) + " bytes)";
        javaInfo.add(new DisplayElement("resourceFileServletCacheSize", DisplayElement.Type.string, "ResourceFileServlet Cache", display));
    }
    javaInfo.add(new DisplayElement("resourceFileServletCacheHitRatio", DisplayElement.Type.string, "ResourceFileServlet Cache Hit Ratio", pwmApplication.getResourceServletService().cacheHitRatio().pretty(2)));
    {
        final Map<SessionTrackService.DebugKey, String> debugInfoMap = pwmApplication.getSessionTrackService().getDebugData();
        javaInfo.add(new DisplayElement("sessionTotalSize", DisplayElement.Type.string, "Estimated Session Total Size", debugInfoMap.get(SessionTrackService.DebugKey.HttpSessionTotalSize)));
        javaInfo.add(new DisplayElement("sessionAverageSize", DisplayElement.Type.string, "Estimated Session Average Size", debugInfoMap.get(SessionTrackService.DebugKey.HttpSessionAvgSize)));
    }
    return Collections.unmodifiableList(javaInfo);
}
Also used : PwmAboutProperty(password.pwm.PwmAboutProperty) PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DisplayElement(password.pwm.http.bean.DisplayElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SessionTrackService(password.pwm.svc.sessiontrack.SessionTrackService)

Example 4 with PwmNumberFormat

use of password.pwm.util.java.PwmNumberFormat in project pwm by pwm-project.

the class AppDashboardData method makeAboutData.

private static List<DisplayElement> makeAboutData(final PwmApplication pwmApplication, final ContextManager contextManager, final Locale locale) {
    final LocaleHelper.DisplayMaker l = new LocaleHelper.DisplayMaker(locale, Admin.class, pwmApplication);
    final String notApplicableValue = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    final List<DisplayElement> aboutData = new ArrayList<>();
    aboutData.add(new DisplayElement("appVersion", DisplayElement.Type.string, l.forKey("Field_AppVersion", PwmConstants.PWM_APP_NAME), PwmConstants.SERVLET_VERSION));
    aboutData.add(new DisplayElement("currentTime", DisplayElement.Type.timestamp, l.forKey("Field_CurrentTime"), JavaHelper.toIsoDate(Instant.now())));
    aboutData.add(new DisplayElement("startupTime", DisplayElement.Type.timestamp, l.forKey("Field_StartTime"), JavaHelper.toIsoDate(pwmApplication.getStartupTime())));
    aboutData.add(new DisplayElement("runningDuration", DisplayElement.Type.string, l.forKey("Field_UpTime"), TimeDuration.fromCurrent(pwmApplication.getStartupTime()).asLongString(locale)));
    aboutData.add(new DisplayElement("installTime", DisplayElement.Type.timestamp, l.forKey("Field_InstallTime"), JavaHelper.toIsoDate(pwmApplication.getInstallTime())));
    aboutData.add(new DisplayElement("siteURL", DisplayElement.Type.string, l.forKey("Field_SiteURL"), pwmApplication.getConfig().readSettingAsString(PwmSetting.PWM_SITE_URL)));
    aboutData.add(new DisplayElement("instanceID", DisplayElement.Type.string, l.forKey("Field_InstanceID"), pwmApplication.getInstanceID()));
    aboutData.add(new DisplayElement("configRestartCounter", DisplayElement.Type.number, "Configuration Restart Counter", contextManager == null ? notApplicableValue : numberFormat.format(contextManager.getRestartCount())));
    aboutData.add(new DisplayElement("chaiApiVersion", DisplayElement.Type.string, l.forKey("Field_ChaiAPIVersion"), com.novell.ldapchai.ChaiConstant.CHAI_API_VERSION));
    return Collections.unmodifiableList(aboutData);
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) LocaleHelper(password.pwm.util.LocaleHelper) ArrayList(java.util.ArrayList) DisplayElement(password.pwm.http.bean.DisplayElement)

Example 5 with PwmNumberFormat

use of password.pwm.util.java.PwmNumberFormat in project pwm by pwm-project.

the class AppDashboardData method makeLocalDbInfo.

private static List<DisplayElement> makeLocalDbInfo(final PwmApplication pwmApplication, final Locale locale) {
    final List<DisplayElement> localDbInfo = new ArrayList<>();
    final String notApplicable = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    localDbInfo.add(new DisplayElement("worlistSize", DisplayElement.Type.number, "Word List Dictionary Size", numberFormat.format(pwmApplication.getWordlistManager().size())));
    localDbInfo.add(new DisplayElement("seedlistSize", DisplayElement.Type.number, "Seed List Dictionary Size", numberFormat.format(pwmApplication.getSeedlistManager().size())));
    localDbInfo.add(new DisplayElement("sharedHistorySize", DisplayElement.Type.number, "Shared Password History Size", numberFormat.format(pwmApplication.getSharedHistoryManager().size())));
    {
        final Instant oldestEntryAge = pwmApplication.getSharedHistoryManager().getOldestEntryTime();
        final String display = oldestEntryAge == null ? notApplicable : TimeDuration.fromCurrent(oldestEntryAge).asCompactString();
        localDbInfo.add(new DisplayElement("oldestSharedHistory", DisplayElement.Type.string, "OldestShared Password Entry", display));
    }
    localDbInfo.add(new DisplayElement("emailQueueSize", DisplayElement.Type.number, "Email Queue Size", numberFormat.format(pwmApplication.getEmailQueue().queueSize())));
    localDbInfo.add(new DisplayElement("smsQueueSize", DisplayElement.Type.number, "SMS Queue Size", numberFormat.format(pwmApplication.getSmsQueue().queueSize())));
    localDbInfo.add(new DisplayElement("sharedHistorySize", DisplayElement.Type.number, "Syslog Queue Size", String.valueOf(pwmApplication.getAuditManager().syslogQueueSize())));
    localDbInfo.add(new DisplayElement("localAuditRecords", DisplayElement.Type.number, "Audit Records", pwmApplication.getAuditManager().sizeToDebugString()));
    {
        final Instant eldestAuditRecord = pwmApplication.getAuditManager().eldestVaultRecord();
        final String display = eldestAuditRecord != null ? TimeDuration.fromCurrent(eldestAuditRecord).asLongString() : notApplicable;
        localDbInfo.add(new DisplayElement("oldestLocalAuditRecords", DisplayElement.Type.string, "Oldest Audit Record", display));
    }
    localDbInfo.add(new DisplayElement("logEvents", DisplayElement.Type.number, "Log Events", pwmApplication.getLocalDBLogger().sizeToDebugString()));
    {
        final String display = pwmApplication.getLocalDBLogger() != null && pwmApplication.getLocalDBLogger().getTailDate() != null ? TimeDuration.fromCurrent(pwmApplication.getLocalDBLogger().getTailDate()).asLongString() : notApplicable;
        localDbInfo.add(new DisplayElement("oldestLogEvents", DisplayElement.Type.string, "Oldest Log Event", display));
    }
    {
        final String display = pwmApplication.getLocalDB() == null ? notApplicable : pwmApplication.getLocalDB().getFileLocation() == null ? notApplicable : StringUtil.formatDiskSize(FileSystemUtility.getFileDirectorySize(pwmApplication.getLocalDB().getFileLocation()));
        localDbInfo.add(new DisplayElement("localDbSizeOnDisk", DisplayElement.Type.string, "LocalDB Size On Disk", display));
    }
    {
        final String display = pwmApplication.getLocalDB() == null ? notApplicable : pwmApplication.getLocalDB().getFileLocation() == null ? notApplicable : StringUtil.formatDiskSize(FileSystemUtility.diskSpaceRemaining(pwmApplication.getLocalDB().getFileLocation()));
        localDbInfo.add(new DisplayElement("localDbFreeSpace", DisplayElement.Type.string, "LocalDB Free Space", display));
    }
    return Collections.unmodifiableList(localDbInfo);
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) Instant(java.time.Instant) ArrayList(java.util.ArrayList) DisplayElement(password.pwm.http.bean.DisplayElement)

Aggregations

PwmNumberFormat (password.pwm.util.java.PwmNumberFormat)6 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)3 DisplayElement (password.pwm.http.bean.DisplayElement)3 Instant (java.time.Instant)2 TimeDuration (password.pwm.util.java.TimeDuration)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PwmAboutProperty (password.pwm.PwmAboutProperty)1 HealthRecord (password.pwm.health.HealthRecord)1 ReportStatusInfo (password.pwm.svc.report.ReportStatusInfo)1 SessionTrackService (password.pwm.svc.sessiontrack.SessionTrackService)1 LocaleHelper (password.pwm.util.LocaleHelper)1 LocalDB (password.pwm.util.localdb.LocalDB)1 LocalDBException (password.pwm.util.localdb.LocalDBException)1