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