use of org.xdi.model.metric.counter.CounterMetricEntry in project oxCore by GluuFederation.
the class LdapEntryReporter method builCounterEntries.
private List<MetricEntry> builCounterEntries(SortedMap<String, Counter> counters, Set<MetricType> registeredMetricTypes) {
List<MetricEntry> result = new ArrayList<MetricEntry>();
Set<MetricType> currentRegisteredMetricTypes = new HashSet<MetricType>(registeredMetricTypes);
for (MetricType metricType : currentRegisteredMetricTypes) {
Counter counter = counters.get(metricType.getValue());
if (counter != null) {
long count = counter.getCount();
// Remove to avoid writing not changed statistic
// registeredMetricTypes.remove(metricType);
CounterMetricData counterMetricData = new CounterMetricData(count);
CounterMetricEntry counterMetricEntry = new CounterMetricEntry();
counterMetricEntry.setMetricData(counterMetricData);
counterMetricEntry.setMetricType(metricType);
result.add(counterMetricEntry);
}
}
return result;
}
use of org.xdi.model.metric.counter.CounterMetricEntry in project oxTrust by GluuFederation.
the class MetricService method dump.
private void dump(List<CounterMetricEntry> metrics) {
for (CounterMetricEntry metric : metrics) {
Date date = metric.getCreationDate();
long count = metric.getMetricData().getCount();
System.out.println(date + " : " + count);
}
}
use of org.xdi.model.metric.counter.CounterMetricEntry in project oxTrust by GluuFederation.
the class MetricService method genereateAuthenticationChartDto.
public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
String key = OxTrustConstants.CACHE_METRICS_KEY + "#home";
AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxTrustConstants.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(OxTrustConstants.CACHE_METRICS_NAME, key, authenticationChartDto);
return authenticationChartDto;
}
use of org.xdi.model.metric.counter.CounterMetricEntry in project oxTrust by GluuFederation.
the class MetricService method calculateCounterStatistics.
private Map<String, Long> calculateCounterStatistics(int countDays, List<CounterMetricEntry> metrics) {
// Prepare map with all dates
Map<String, Long> stats = new TreeMap<String, Long>();
Calendar calendar = Calendar.getInstance();
for (int i = 0; i <= countDays; i++) {
String dateString = df.format(calendar.getTime());
stats.put(dateString, 0L);
calendar.add(Calendar.DATE, -1);
}
if ((metrics == null) || (metrics.size() == 0)) {
return stats;
}
// Detect servers restart and readjust counts
// Server restart condition: previous entry CounterMetricEntry.CounterMetricEntry.count > current entry CounterMetricEntry.CounterMetricEntry.count
CounterMetricEntry prevMetric = null;
long prevDayCount = 0L;
long adjust = 0;
for (CounterMetricEntry metric : metrics) {
Date date = metric.getCreationDate();
calendar.setTime(date);
// Detect server restarts
if ((prevMetric != null) && (prevMetric.getMetricData().getCount() > metric.getMetricData().getCount() + adjust)) {
// Last count before server restart
long count = prevMetric.getMetricData().getCount();
// Change adjust value
adjust = count;
}
long count = metric.getMetricData().getCount();
metric.getMetricData().setCount(count + adjust);
prevMetric = metric;
}
// Iterate through ordered by MetricEntry.startDate list and just make value snapshot at the end of the day
int prevDay = -1;
prevMetric = null;
prevDayCount = 0L;
for (CounterMetricEntry metric : metrics) {
Date date = metric.getCreationDate();
calendar.setTime(date);
int currDay = calendar.get(Calendar.DAY_OF_MONTH);
if ((prevMetric != null) && (prevDay != currDay)) {
long count = prevMetric.getMetricData().getCount();
String dateString = df.format(prevMetric.getCreationDate());
stats.put(dateString, count - prevDayCount);
// Show only difference, not total
prevDayCount = count;
}
prevMetric = metric;
prevDay = currDay;
}
// Add last day statistic
long count = prevMetric.getMetricData().getCount();
String dateString = df.format(prevMetric.getCreationDate());
stats.put(dateString, count - prevDayCount);
return stats;
}
Aggregations