Skip to content

Commit

Permalink
实现部分接口.
Browse files Browse the repository at this point in the history
  • Loading branch information
hidehai committed Mar 16, 2016
1 parent 8777da1 commit 1f3e52f
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public Collection<ApplicationInfo> queryApplications() {

@Override
public ApplicationInfo queryApplicationInfo(String application, long start, long end) {
//TODO fix
return null;
}

Expand Down Expand Up @@ -150,9 +151,16 @@ public StatisticsOverview queryServiceOverview(String application, String servic
@Override
public Collection<ServiceInfo> queryServiceByApp(String application, long start, long end) {
List<ServiceInfo> infos = findServiceByApp(application);

Statistics statistics = null;
for(ServiceInfo info : infos){

statistics = queryMaxItemByService(application,info.getName(),"concurrent",start,end);
info.setMaxConcurrent(statistics == null ? 0 : statistics.getConcurrent());
statistics = queryMaxItemByService(application,info.getName(),"elapsed",start,end);
info.setMaxElapsed(statistics == null ? 0 : statistics.getElapsed());
statistics = queryMaxItemByService(application,info.getName(),"failureCount",start,end);
info.setMaxFault(statistics == null ? 0 : statistics.getFailureCount());
statistics = queryMaxItemByService(application,info.getName(),"successCount",start,end);
info.setMaxSuccess(statistics == null ? 0 : statistics.getSuccessCount());
}
return infos;
}
Expand Down Expand Up @@ -195,9 +203,9 @@ private Statistics findMethodMaxItemByService(String column,String application,
query.addCriteria(Criteria.where("timestamp").gte(startTime).lte(endTime));
query.with(new Sort(Sort.Direction.DESC,column)).limit(1);

Statistics statisticses = mongoTemplate.findOne(query,Statistics.class,
Statistics statistics = mongoTemplate.findOne(query,Statistics.class,
String.format("%s_%s",STATISTICS_COLLECTIONS,application.toLowerCase()));
return statisticses;
return statistics;
}

/**
Expand Down Expand Up @@ -240,8 +248,9 @@ private List<Statistics> findServiceOverview(String application,String service,S

private List<ServiceInfo> findServiceByApp(String application){
TypedAggregation aggregation =new TypedAggregation(Statistics.class,
Aggregation.project("remoteType","serviceInterface"), //限制结果集包含域
Aggregation.group("serviceInterface","remoteType") //分组聚合
Aggregation.project("remoteType","serviceInterface"),
Aggregation.group("serviceInterface","remoteType"),
Aggregation.project("remoteType").and("serviceInterface").as("name")
);

List<ServiceInfo> serviceInfos = mongoTemplate.aggregate(aggregation,
Expand All @@ -250,6 +259,25 @@ private List<ServiceInfo> findServiceByApp(String application){
return serviceInfos;
}

/**
*
* @param application
* @param service
* @param startTime
* @param endTime
* @return
*/
private Statistics queryMaxItemByService(String application,String service,String item,long startTime,long endTime){
Query query = new Query();
query.addCriteria(Criteria.where("serviceInterface").is(service));
query.addCriteria(Criteria.where("timestamp").gte(startTime).lte(endTime));
query.with(new Sort(Sort.Direction.DESC,item));

Statistics statistics = mongoTemplate.findOne(query,Statistics.class,
String.format("%s_%s",STATISTICS_COLLECTIONS,application.toLowerCase()));
return statistics;
}



private void fillConcurrentItem(List<Statistics> statisticses,StatisticsOverview statisticsOverview){
Expand Down

0 comments on commit 1f3e52f

Please sign in to comment.