Skip to content

Commit

Permalink
metrics on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rahatjaan committed Aug 19, 2015
1 parent 4482286 commit d4e179f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
35 changes: 20 additions & 15 deletions server/src/main/java/org/gluu/oxtrust/service/MetricService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.xdi.model.metric.MetricType;
import org.xdi.model.metric.ldap.MetricEntry;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Store and retrieve metric
*
Expand Down Expand Up @@ -57,9 +59,9 @@ public class MetricService extends org.xdi.service.metric.MetricService {
private OxTrustConfiguration oxTrustConfiguration;

Map<MetricType, List<MetricEntry>> entries;
Map<String,Integer> successStats;
Map<String,Integer> failureStats;

String successJson;
String failureJson;
ObjectMapper mapper = new ObjectMapper();
@Create
public void create() {
// init(3000);
Expand All @@ -78,9 +80,11 @@ public void create() {
oxTrustConfiguration.getApplicationConfiguration()
.getApplianceInum(), metricTypes, startDate,
endDate, null);
System.out.println(entries);
successStats = calculateMonthlyStatistics(entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
failureStats = calculateMonthlyStatistics(entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
System.out.println(entries);
Map<String,Integer> successStats = calculateMonthlyStatistics(entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
Map<String,Integer> failureStats = calculateMonthlyStatistics(entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
successJson = mapper.writeValueAsString(successStats);
failureJson = mapper.writeValueAsString(failureStats);
} catch (Exception ex) {
ex.printStackTrace();
}
Expand All @@ -96,7 +100,7 @@ private Map<String, Integer> calculateMonthlyStatistics(
String dateString =df.format(date);
Integer count = stats.get(dateString);
if(count!=null)
stats.put(dateString,count++);
stats.put(dateString,(count+1));
else
stats.put(dateString,1);
}
Expand Down Expand Up @@ -132,20 +136,21 @@ public static MetricService instance() {
return (MetricService) Component.getInstance(MetricService.class);
}

public Map<String, Integer> getSuccessStats() {
return successStats;
public String getSuccessJson() {
return successJson;
}

public void setSuccessStats(Map<String, Integer> successStats) {
this.successStats = successStats;
public void setSuccessJson(String successJson) {
this.successJson = successJson;
}

public Map<String, Integer> getFailureStats() {
return failureStats;
public String getFailureJson() {
return failureJson;
}

public void setFailureStats(Map<String, Integer> failureStats) {
this.failureStats = failureStats;
public void setFailureJson(String failureJson) {
this.failureJson = failureJson;
}


}
27 changes: 24 additions & 3 deletions server/src/main/webapp/home.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
</div>

</div>
<div>
<h2>Metric Service here <h:outputText styleClass="info-box-number" value="#{metricService.entries}" /></h2>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="info-box">
<span class="info-box-icon bg-red"><i class="fa fa-tasks" style="line-height:2em !important;"></i></span>
Expand Down Expand Up @@ -85,6 +82,20 @@
</div>

</div>
<div>
<h2>Successful login</h2>
<h:inputTextarea value="#{metricService.successJson}" ></h:inputTextarea>


</div>

<div>
<h2>failed login</h2>
<h:inputTextarea value="#{metricService.failureJson}" ></h:inputTextarea>


</div>

<div class="row">
<div class="col-md-12">
<div class="box">
Expand Down Expand Up @@ -384,6 +395,16 @@
<script src="#{oxTrustConfigurationService.cssLocation}/../theme/plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="#{oxTrustConfigurationService.cssLocation}/../theme/plugins/chartjs/Chart.min.js" type="text/javascript"></script>
<script src="#{oxTrustConfigurationService.cssLocation}/../theme/dist/js/pages/dashboard.js" type="text/javascript"></script>
<script>
/*
var metrics = $("#metrics").val();
console.log("#metrics length:"+metrics.length);
var obj = JSON.stringify(eval(metrics));
console.log(obj);
var obj = JSON.parse(metrics);
console.log(obj);
*/
</script>

</ui:define>
</ui:composition>

0 comments on commit d4e179f

Please sign in to comment.