Search in sources :

Example 1 with Statistic

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

the class AdminPropertyKeysTest method testStatisticsLabelKeys.

@Test
public void testStatisticsLabelKeys() {
    final ResourceBundle resourceBundle = ResourceBundle.getBundle(password.pwm.i18n.Admin.class.getName(), PwmConstants.DEFAULT_LOCALE);
    final Set<String> expectedKeys = new HashSet<>();
    for (final Statistic statistic : Statistic.values()) {
        final String[] keys = new String[] { password.pwm.i18n.Admin.STATISTICS_DESCRIPTION_PREFIX + statistic.getKey(), password.pwm.i18n.Admin.STATISTICS_LABEL_PREFIX + statistic.getKey() };
        for (final String key : keys) {
            expectedKeys.add(key);
            Assert.assertTrue("Admin.properties missing record for " + key, resourceBundle.containsKey(key));
        }
    }
    final Set<String> extraKeys = new HashSet<>(resourceBundle.keySet());
    extraKeys.removeAll(expectedKeys);
    for (final String key : extraKeys) {
        if (key.startsWith(password.pwm.i18n.Admin.STATISTICS_DESCRIPTION_PREFIX) || key.startsWith(password.pwm.i18n.Admin.STATISTICS_LABEL_PREFIX)) {
            Assert.fail("unexpected key in Admin.properties file: " + key);
        }
    }
}
Also used : Statistic(password.pwm.svc.stats.Statistic) EpsStatistic(password.pwm.svc.stats.EpsStatistic) ResourceBundle(java.util.ResourceBundle) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Statistic

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

the class RestStatisticsServer method doNameStat.

public static Map<String, Object> doNameStat(final StatisticsManager statisticsManager, final String statName, final String days) {
    final Statistic statistic = Statistic.valueOf(statName);
    final int historyDays = StringUtil.convertStrToInt(days, 30);
    final Map<String, Object> results = new HashMap<>();
    results.putAll(statisticsManager.getStatHistory(statistic, historyDays));
    return results;
}
Also used : Statistic(password.pwm.svc.stats.Statistic) EpsStatistic(password.pwm.svc.stats.EpsStatistic) HashMap(java.util.HashMap)

Example 3 with Statistic

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

the class TelemetryService method generatePublishableBean.

public TelemetryPublishBean generatePublishableBean() throws URISyntaxException, IOException, PwmUnrecoverableException {
    final StatisticsBundle bundle = pwmApplication.getStatisticsManager().getStatBundleForKey(StatisticsManager.KEY_CUMULATIVE);
    final Configuration config = pwmApplication.getConfig();
    final Map<PwmAboutProperty, String> aboutPropertyStringMap = PwmAboutProperty.makeInfoBean(pwmApplication);
    final Map<String, String> statData = new TreeMap<>();
    for (final Statistic loopStat : Statistic.values()) {
        statData.put(loopStat.getKey(), bundle.getStatistic(loopStat));
    }
    final List<String> configuredSettings = new ArrayList<>();
    for (final PwmSetting pwmSetting : config.nonDefaultSettings()) {
        if (!pwmSetting.getCategory().hasProfiles() && !config.isDefaultValue(pwmSetting)) {
            configuredSettings.add(pwmSetting.getKey());
        }
    }
    String ldapVendorName = null;
    for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
        if (ldapVendorName == null) {
            try {
                final DirectoryVendor directoryVendor = ldapProfile.getProxyChaiProvider(pwmApplication).getDirectoryVendor();
                final PwmLdapVendor pwmLdapVendor = PwmLdapVendor.fromChaiVendor(directoryVendor);
                if (pwmLdapVendor != null) {
                    ldapVendorName = pwmLdapVendor.name();
                }
            } catch (Exception e) {
                LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "unable to read ldap vendor type for stats publication: " + e.getMessage());
            }
        }
    }
    final Map<String, String> aboutStrings = new TreeMap<>();
    {
        for (final Map.Entry<PwmAboutProperty, String> entry : aboutPropertyStringMap.entrySet()) {
            final PwmAboutProperty pwmAboutProperty = entry.getKey();
            aboutStrings.put(pwmAboutProperty.name(), entry.getValue());
        }
        aboutStrings.remove(PwmAboutProperty.app_instanceID.name());
        aboutStrings.remove(PwmAboutProperty.app_siteUrl.name());
    }
    final TelemetryPublishBean.TelemetryPublishBeanBuilder builder = TelemetryPublishBean.builder();
    builder.timestamp(Instant.now());
    builder.id(makeId(pwmApplication));
    builder.instanceHash(pwmApplication.getSecureService().hash(pwmApplication.getInstanceID()));
    builder.installTime(pwmApplication.getInstallTime());
    builder.siteDescription(config.readSettingAsString(PwmSetting.PUBLISH_STATS_SITE_DESCRIPTION));
    builder.versionBuild(PwmConstants.BUILD_NUMBER);
    builder.versionVersion(PwmConstants.BUILD_VERSION);
    builder.ldapVendorName(ldapVendorName);
    builder.statistics(Collections.unmodifiableMap(statData));
    builder.configuredSettings(Collections.unmodifiableList(configuredSettings));
    builder.about(aboutStrings);
    return builder.build();
}
Also used : Configuration(password.pwm.config.Configuration) ArrayList(java.util.ArrayList) PwmLdapVendor(password.pwm.ldap.PwmLdapVendor) TreeMap(java.util.TreeMap) LdapProfile(password.pwm.config.profile.LdapProfile) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) PwmSetting(password.pwm.config.PwmSetting) PwmAboutProperty(password.pwm.PwmAboutProperty) StatisticsBundle(password.pwm.svc.stats.StatisticsBundle) Statistic(password.pwm.svc.stats.Statistic) DirectoryVendor(com.novell.ldapchai.provider.DirectoryVendor) TelemetryPublishBean(password.pwm.bean.TelemetryPublishBean)

Example 4 with Statistic

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

the class RestStatisticsServer method doKeyStat.

public static Map<String, Object> doKeyStat(final StatisticsManager statisticsManager, final String statKey) {
    final String key = (statKey == null) ? StatisticsManager.KEY_CUMULATIVE : statKey;
    final StatisticsBundle statisticsBundle = statisticsManager.getStatBundleForKey(key);
    final Map<String, Object> outputValueMap = new TreeMap<>();
    for (final Statistic stat : Statistic.values()) {
        outputValueMap.put(stat.getKey(), statisticsBundle.getStatistic(stat));
    }
    return outputValueMap;
}
Also used : StatisticsBundle(password.pwm.svc.stats.StatisticsBundle) Statistic(password.pwm.svc.stats.Statistic) EpsStatistic(password.pwm.svc.stats.EpsStatistic) TreeMap(java.util.TreeMap)

Aggregations

Statistic (password.pwm.svc.stats.Statistic)4 EpsStatistic (password.pwm.svc.stats.EpsStatistic)3 TreeMap (java.util.TreeMap)2 StatisticsBundle (password.pwm.svc.stats.StatisticsBundle)2 DirectoryVendor (com.novell.ldapchai.provider.DirectoryVendor)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ResourceBundle (java.util.ResourceBundle)1 Test (org.junit.Test)1 PwmAboutProperty (password.pwm.PwmAboutProperty)1 TelemetryPublishBean (password.pwm.bean.TelemetryPublishBean)1 Configuration (password.pwm.config.Configuration)1 PwmSetting (password.pwm.config.PwmSetting)1 LdapProfile (password.pwm.config.profile.LdapProfile)1 PwmException (password.pwm.error.PwmException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 PwmLdapVendor (password.pwm.ldap.PwmLdapVendor)1