gluu
公開メンバ関数 | 静的公開変数類 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.service.MetricService クラス
org.gluu.oxtrust.service.MetricService の継承関係図
Inheritance graph
org.gluu.oxtrust.service.MetricService 連携図
Collaboration graph

公開メンバ関数

void initTimer ()
 
String baseDn ()
 
String applianceInum ()
 
org.xdi.service.metric.MetricService getMetricServiceInstance ()
 
AuthenticationChartDto genereateAuthenticationChartDto (int countDays)
 
boolean isMetricReporterEnabled ()
 
ApplicationType getApplicationType ()
 

静的公開変数類

static final String METRIC_SERVICE_COMPONENT_NAME = "metricService"
 

非公開メンバ関数

Map< MetricType, List<? extends MetricEntry > > findAuthenticationMetrics (ApplicationType applicationType, int countDays)
 
Map< String, Long > calculateCounterStatistics (int countDays, List< CounterMetricEntry > metrics)
 
void dump (List< CounterMetricEntry > metrics)
 

非公開変数類

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd")
 
Logger log
 
Instance< MetricServiceinstance
 
CacheService cacheService
 
ApplianceService applianceService
 
OrganizationService organizationService
 
ConfigurationFactory configurationFactory
 
AppConfiguration appConfiguration
 

静的非公開変数類

static final long serialVersionUID = 7875838160379126796L
 

詳解

Store and retrieve metric

著者
Yuriy Movchan Date: 06/28/2015
Rahat Ali Date: 07/30/2015

関数詳解

◆ applianceInum()

String org.gluu.oxtrust.service.MetricService.applianceInum ( )
inline
84  {
86  }
String getApplianceInum()
Definition: ApplianceService.java:178
ApplianceService applianceService
Definition: MetricService.java:61

◆ baseDn()

String org.gluu.oxtrust.service.MetricService.baseDn ( )
inline
77  {
79  String baseDn = String.format("ou=metric,%s", orgDn);
80  return baseDn;
81  }
OrganizationService organizationService
Definition: MetricService.java:64
String getDnForOrganization(String inum)
Definition: OrganizationService.java:106
String baseDn()
Definition: MetricService.java:77

◆ calculateCounterStatistics()

Map<String, Long> org.gluu.oxtrust.service.MetricService.calculateCounterStatistics ( int  countDays,
List< CounterMetricEntry >  metrics 
)
inlineprivate
141  {
142  // Prepare map with all dates
143  Map<String, Long> stats = new TreeMap<String, Long>();
144  Calendar calendar = Calendar.getInstance();
145  for (int i = 0; i <= countDays; i++) {
146  String dateString = df.format(calendar.getTime());
147  stats.put(dateString, 0L);
148  calendar.add(Calendar.DATE, -1);
149  }
150 
151  if ((metrics == null) || (metrics.size() == 0)) {
152  return stats;
153  }
154 
155  // Detect servers restart and readjust counts
156  // Server restart condition: previous entry CounterMetricEntry.CounterMetricEntry.count > current entry CounterMetricEntry.CounterMetricEntry.count
157  CounterMetricEntry prevMetric = null;
158  long prevDayCount = 0L;
159  long adjust = 0;
160  for (CounterMetricEntry metric : metrics) {
161  Date date = metric.getCreationDate();
162  calendar.setTime(date);
163 
164  // Detect server restarts
165  if ((prevMetric != null) && (prevMetric.getMetricData().getCount() > metric.getMetricData().getCount() + adjust)) {
166  // Last count before server restart
167  long count = prevMetric.getMetricData().getCount();
168 
169  // Change adjust value
170  adjust = count;
171  }
172 
173  long count = metric.getMetricData().getCount();
174  metric.getMetricData().setCount(count + adjust);
175 
176  prevMetric = metric;
177  }
178 
179  // Iterate through ordered by MetricEntry.startDate list and just make value snapshot at the end of the day
180  int prevDay = -1;
181  prevMetric = null;
182  prevDayCount = 0L;
183  for (CounterMetricEntry metric : metrics) {
184  Date date = metric.getCreationDate();
185  calendar.setTime(date);
186 
187  int currDay = calendar.get(Calendar.DAY_OF_MONTH);
188  if ((prevMetric != null) && (prevDay != currDay)) {
189  long count = prevMetric.getMetricData().getCount();
190  String dateString = df.format(prevMetric.getCreationDate());
191  stats.put(dateString, count - prevDayCount);
192 
193  // Show only difference, not total
194  prevDayCount = count;
195  }
196 
197  prevMetric = metric;
198  prevDay = currDay;
199  }
200 
201  // Add last day statistic
202  long count = prevMetric.getMetricData().getCount();
203  String dateString = df.format(prevMetric.getCreationDate());
204  stats.put(dateString, count - prevDayCount);
205 
206  return stats;
207  }
SimpleDateFormat df
Definition: MetricService.java:49

◆ dump()

void org.gluu.oxtrust.service.MetricService.dump ( List< CounterMetricEntry >  metrics)
inlineprivate
223  {
224  for (CounterMetricEntry metric : metrics) {
225  Date date = metric.getCreationDate();
226  long count = metric.getMetricData().getCount();
227  System.out.println(date + " : " + count);
228  }
229  }

◆ findAuthenticationMetrics()

Map<MetricType, List<? extends MetricEntry> > org.gluu.oxtrust.service.MetricService.findAuthenticationMetrics ( ApplicationType  applicationType,
int  countDays 
)
inlineprivate
124  {
125  List<MetricType> metricTypes = new ArrayList<MetricType>();
126  metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES);
127  metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS);
128 
129  Date endDate = new Date();
130  Calendar calendar = Calendar.getInstance();
131  calendar.add(Calendar.DATE, countDays);
132 
133  Date startDate = calendar.getTime();
134 
135  Map<MetricType, List<? extends MetricEntry>> entries = findMetricEntry(applicationType, appConfiguration
136  .getApplianceInum(), metricTypes, startDate, endDate);
137 
138  return entries;
139  }
AppConfiguration appConfiguration
Definition: MetricService.java:70

◆ genereateAuthenticationChartDto()

AuthenticationChartDto org.gluu.oxtrust.service.MetricService.genereateAuthenticationChartDto ( int  countDays)
inline
93  {
94  String key = OxTrustConstants.CACHE_METRICS_KEY + "#home";
95  AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxTrustConstants.CACHE_METRICS_NAME, key);
96  if (authenticationChartDto != null) {
97  return authenticationChartDto;
98  }
99 
100  Map<MetricType, List<? extends MetricEntry>> entries = findAuthenticationMetrics(ApplicationType.OX_AUTH, -countDays);
101 
102  String[] labels = new String[countDays];
103  Map<String, Long> successStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
104  labels = successStats.keySet().toArray(labels);
105 
106  Long[] values = new Long[countDays];
107  values = successStats.values().toArray(values);
108 
109  authenticationChartDto = new AuthenticationChartDto();
110 
111  authenticationChartDto.setLabels(labels);
112  authenticationChartDto.setSuccess(values);
113 
114  Map<String, Long> failureStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
115  values = new Long[countDays];
116  values = failureStats.values().toArray(values);
117  authenticationChartDto.setFailure(values);
118 
119  cacheService.put(OxTrustConstants.CACHE_METRICS_NAME, key, authenticationChartDto);
120 
121  return authenticationChartDto;
122  }
Map< String, Long > calculateCounterStatistics(int countDays, List< CounterMetricEntry > metrics)
Definition: MetricService.java:141
CacheService cacheService
Definition: MetricService.java:58
Map< MetricType, List<? extends MetricEntry > > findAuthenticationMetrics(ApplicationType applicationType, int countDays)
Definition: MetricService.java:124

◆ getApplicationType()

ApplicationType org.gluu.oxtrust.service.MetricService.getApplicationType ( )
inline
219  {
220  return ApplicationType.OX_TRUST;
221  }

◆ getMetricServiceInstance()

org.xdi.service.metric.MetricService org.gluu.oxtrust.service.MetricService.getMetricServiceInstance ( )
inline
89  {
90  return instance.get();
91  }
Instance< MetricService > instance
Definition: MetricService.java:55

◆ initTimer()

void org.gluu.oxtrust.service.MetricService.initTimer ( )
inline
72  {
73  initTimer(this.appConfiguration.getMetricReporterInterval());
74  }
void initTimer()
Definition: MetricService.java:72
AppConfiguration appConfiguration
Definition: MetricService.java:70

◆ isMetricReporterEnabled()

boolean org.gluu.oxtrust.service.MetricService.isMetricReporterEnabled ( )
inline
210  {
211  if (this.appConfiguration.getMetricReporterEnabled() == null) {
212  return false;
213  }
214 
215  return this.appConfiguration.getMetricReporterEnabled();
216  }
AppConfiguration appConfiguration
Definition: MetricService.java:70

メンバ詳解

◆ appConfiguration

AppConfiguration org.gluu.oxtrust.service.MetricService.appConfiguration
private

◆ applianceService

ApplianceService org.gluu.oxtrust.service.MetricService.applianceService
private

◆ cacheService

CacheService org.gluu.oxtrust.service.MetricService.cacheService
private

◆ configurationFactory

ConfigurationFactory org.gluu.oxtrust.service.MetricService.configurationFactory
private

◆ df

SimpleDateFormat org.gluu.oxtrust.service.MetricService.df = new SimpleDateFormat("yyyy-MM-dd")
private

◆ instance

Instance<MetricService> org.gluu.oxtrust.service.MetricService.instance
private

◆ log

Logger org.gluu.oxtrust.service.MetricService.log
private

◆ METRIC_SERVICE_COMPONENT_NAME

final String org.gluu.oxtrust.service.MetricService.METRIC_SERVICE_COMPONENT_NAME = "metricService"
static

◆ organizationService

OrganizationService org.gluu.oxtrust.service.MetricService.organizationService
private

◆ serialVersionUID

final long org.gluu.oxtrust.service.MetricService.serialVersionUID = 7875838160379126796L
staticprivate

このクラス詳解は次のファイルから抽出されました: