use of org.xdi.model.metric.ldap.MetricEntry in project oxTrust by GluuFederation.
the class MetricService method findAuthenticationMetrics.
private Map<MetricType, List<? extends MetricEntry>> findAuthenticationMetrics(int countDays) {
List<MetricType> metricTypes = new ArrayList<MetricType>();
metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES);
metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS);
Date endDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, countDays);
Date startDate = calendar.getTime();
Map<MetricType, List<? extends MetricEntry>> entries = findMetricEntry(ApplicationType.OX_AUTH, appConfiguration.getApplianceInum(), metricTypes, startDate, endDate);
return entries;
}
use of org.xdi.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.
the class LdapEntryReporter method builTimerEntries.
private List<MetricEntry> builTimerEntries(SortedMap<String, Timer> timers, Set<MetricType> registeredMetricTypes) {
List<MetricEntry> result = new ArrayList<MetricEntry>();
for (MetricType metricType : registeredMetricTypes) {
Timer timer = timers.get(metricType.getValue());
if (timer != null) {
Snapshot snapshot = timer.getSnapshot();
TimerMetricData timerMetricData = new TimerMetricData(timer.getCount(), convertRate(timer.getMeanRate()), convertRate(timer.getOneMinuteRate()), convertRate(timer.getFiveMinuteRate()), convertRate(timer.getFifteenMinuteRate()), getRateUnit(), convertDuration(snapshot.getMin()), convertDuration(snapshot.getMax()), convertDuration(snapshot.getMean()), convertDuration(snapshot.getStdDev()), convertDuration(snapshot.getMedian()), convertDuration(snapshot.get75thPercentile()), convertDuration(snapshot.get95thPercentile()), convertDuration(snapshot.get98thPercentile()), convertDuration(snapshot.get99thPercentile()), convertDuration(snapshot.get999thPercentile()), getDurationUnit());
TimerMetricEntry timerMetricEntry = new TimerMetricEntry();
timerMetricEntry.setMetricData(timerMetricData);
timerMetricEntry.setMetricType(metricType);
result.add(timerMetricEntry);
}
}
return result;
}
use of org.xdi.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.
the class MetricService method removeExpiredMetricEntries.
public void removeExpiredMetricEntries(int batchSize, final Date expirationDate, final ApplicationType applicationType, final String applianceInum) {
final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, applianceInum, expirationDate, new Date());
// Remove expired entries
for (final String baseDnForPeriod : keepBaseDnForPeriod) {
BatchOperation<MetricEntry> metricEntryBatchOperation = new BatchOperation<MetricEntry>(ldapEntryManager) {
@Override
protected List<MetricEntry> getChunkOrNull(int batchSize) {
return getExpiredMetricEntries(this, batchSize, baseDnForPeriod, expirationDate);
}
@Override
protected void performAction(List<MetricEntry> objects) {
for (MetricEntry metricEntry : objects) {
remove(metricEntry);
}
}
};
metricEntryBatchOperation.iterateAllByChunks(batchSize);
}
BatchOperation<SimpleBranch> batchOperation = new BatchOperation<SimpleBranch>(ldapEntryManager) {
@Override
protected List<SimpleBranch> getChunkOrNull(int batchSize) {
return findAllPeriodBranches(this, batchSize, applicationType, applianceInum);
}
@Override
protected void performAction(List<SimpleBranch> objects) {
String baseDn = buildDn(null, null, applicationType, applianceInum);
Set<String> periodBranchesStrings = new HashSet<String>();
for (SimpleBranch periodBranch : objects) {
if (!StringHelper.equalsIgnoreCase(baseDn, periodBranch.getDn())) {
periodBranchesStrings.add(periodBranch.getDn());
}
}
periodBranchesStrings.removeAll(keepBaseDnForPeriod);
// Remove expired months
for (String baseDnForPeriod : periodBranchesStrings) {
removeBranch(baseDnForPeriod);
}
}
};
batchOperation.iterateAllByChunks(batchSize);
}
use of org.xdi.model.metric.ldap.MetricEntry in project oxTrust by GluuFederation.
the class MetricService method genereateAuthenticationChartDto.
public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
String key = OxConstants.CACHE_METRICS_KEY + "#home";
AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxConstants.CACHE_METRICS_NAME, key);
if (authenticationChartDto != null) {
return authenticationChartDto;
}
Map<MetricType, List<? extends MetricEntry>> entries = findAuthenticationMetrics(-countDays);
String[] labels = new String[countDays];
Map<String, Long> successStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
labels = successStats.keySet().toArray(labels);
Long[] values = new Long[countDays];
values = successStats.values().toArray(values);
authenticationChartDto = new AuthenticationChartDto();
authenticationChartDto.setLabels(labels);
authenticationChartDto.setSuccess(values);
Map<String, Long> failureStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
values = new Long[countDays];
values = failureStats.values().toArray(values);
authenticationChartDto.setFailure(values);
cacheService.put(OxConstants.CACHE_METRICS_NAME, key, authenticationChartDto);
return authenticationChartDto;
}
use of org.xdi.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.
the class MetricService method removeExpiredMetricEntries.
public void removeExpiredMetricEntries(final Date expirationDate, final ApplicationType applicationType, final String applianceInum, int sizeLimit, int chunkSize) {
final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, applianceInum, expirationDate, new Date());
// Remove expired entries
for (final String baseDnForPeriod : keepBaseDnForPeriod) {
DefaultBatchOperation<MetricEntry> metricEntryBatchOperation = new DefaultBatchOperation<MetricEntry>() {
@Override
public boolean collectSearchResult(int size) {
return false;
}
@Override
public void performAction(List<MetricEntry> entries) {
for (MetricEntry metricEntry : entries) {
remove(metricEntry);
}
}
};
getExpiredMetricEntries(metricEntryBatchOperation, baseDnForPeriod, expirationDate, sizeLimit, chunkSize);
}
DefaultBatchOperation<SimpleBranch> batchOperation = new DefaultBatchOperation<SimpleBranch>() {
@Override
public boolean collectSearchResult(int size) {
return false;
}
@Override
public void performAction(List<SimpleBranch> objects) {
String baseDn = buildDn(null, null, applicationType, applianceInum);
Set<String> periodBranchesStrings = new HashSet<String>();
for (SimpleBranch periodBranch : objects) {
if (!StringHelper.equalsIgnoreCase(baseDn, periodBranch.getDn())) {
periodBranchesStrings.add(periodBranch.getDn());
}
}
periodBranchesStrings.removeAll(keepBaseDnForPeriod);
// Remove expired months
for (String baseDnForPeriod : periodBranchesStrings) {
removeBranch(baseDnForPeriod);
}
}
};
findAllPeriodBranches(batchOperation, applicationType, applianceInum, sizeLimit, chunkSize);
}
Aggregations