We have Json data streams that we need to analyze 

Source Data

{ "_id" : { "$oid" : "521843d498c06bf2328634cc" }, "android_version" : "2.3.5", "app_version_code" : "30012", "total_mem_size" : "1663090688", "user_app_start_date" : "2013-08-21T18:44:59.000-04:00", "exception" : "java.lang.Exception: IDLE-2 inside run():", "is_silent" : "true", "package_name" : "com.verizon.messaging.vzmsgs", "shared_preferences" : { "pref_country_code" : "1", "pref_country" : "US" }, "display" : { "metrics-widthPixels" : "800", "refreshRate" : "68.0fps" }, "device_id" : "A0000024FEA7C4", "build" : { "tags" : "release-keys", "model" : "SCH-I500", "user" : "se.infra", "serial" : "unknown" }, "reqid" : "193237", "stack_trace" : " java.lang.Exception: IDLE-2 inside run(): java.lang.NullPointerException", "user_crash_date" : "2013-08-21T22:32:14.000-04:00", "brand" : "verizon", "report_id" : "c12d34e3-0312-487f-ba64-f439506c0cea", "app_version_name" : "4.0.1", "available_mem_size" : "1131577344", "phone_model" : "SCH-I500" }

Declare Rest controller and inject your service.

@Controller
 public class LogViewerMvcController
 @Inject
 public MonitoringService monitoringService
 @RequestMapping(value = "/", method = RequestMethod.GET) { .. }

In the Service layer aggregate exception data from mongo and send the data back to Controller.

public List exceptionDetails(SearchCriteria criteria) throws Exception {
 List viewDataList = new ArrayList(1);

 Map<String, String> projectedFields = new HashMap<String, String>();
 projectedFields.put("exception_string", "$exception");
 projectedFields.put("phone_model", "$phone_model");
 projectedFields.put("android_version", "$android_version");

 BasicDBObject projectOp = new BasicDBObject("$project", new  
 BasicDBObject(projectedFields));
BasicDBObject groupByFields = new BasicDBObject("_id", new BasicDBObject("exception_string", "$exception_string").append("phone_model", "$phone_model").append("android_version","$android_version")) .append("total_exception_count", new BasicDBObject("$sum", 1));

BasicDBObject groupOp = new BasicDBObject("$group", groupByFields );

DBCollection dbColl = mongoOperations.getCollection("logs");
 AggregationOutput aggrOutput = dbColl.aggregate(projectOp, groupOp);

for (DBObject dbObject : aggrOutput.results()) {
 logDataInfo = new ArrayList(1);
 String exceptionName = (String) ((DBObject) dbObject.get("_id")) .get("exception_string");
 String phoneModel = (String) ((DBObject)dbObject.get("_id")).get("phone_model");

 logDataInfo.add(exceptionName);
 logDataInfo.add(phoneModel);
 BusinessEntity businessEntity = new BusinessEntity(logDataInfo);
 viewDataList.add(businessEntity);
}
Advertisements