|
@ -24,63 +24,6 @@ public class ServerMonitorService {
|
|
@Autowired
|
|
@Autowired
|
|
private Mongo mongo;
|
|
private Mongo mongo;
|
|
|
|
|
|
// public Result mapReduce(String beginTime, String endTime) {
|
|
|
|
// DBCollection businessLogDB = mongoOperations.getCollection(mongoOperations
|
|
|
|
// .getCollectionName(BusinessLog.class));
|
|
|
|
//
|
|
|
|
// String map = "function(){emit(this.breadcrumbId, this.fireTime);}";
|
|
|
|
// String reduce = "function(key, values){ return values[0];}";
|
|
|
|
// String out = reduceTableName;
|
|
|
|
// BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
|
|
|
|
// new BasicDBObject[]{
|
|
|
|
// new BasicDBObject().append("fireTime",
|
|
|
|
// new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
|
|
|
|
// new BasicDBObject().append("fireTime",
|
|
|
|
// new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
|
|
|
|
//
|
|
|
|
// MapReduceOutput mapReduceOutput = businessLogDB.mapReduce(map,
|
|
|
|
// reduce.toString(), out, queryObject);
|
|
|
|
// DBCollection resultColl = mapReduceOutput.getOutputCollection();
|
|
|
|
// DBCursor cursor = resultColl.find();
|
|
|
|
// String result = "";
|
|
|
|
//
|
|
|
|
// while (cursor.hasNext()) {
|
|
|
|
// result += cursor.next();
|
|
|
|
// }
|
|
|
|
// return Result.success(result);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public JSONObject aggregate(String beginTime, String endTime) {
|
|
|
|
// DBCollection reduceDB = mongoOperations.getCollection(mongoOperations
|
|
|
|
// .getCollectionName(ReduceResult.class));
|
|
|
|
// BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
|
|
|
|
// new BasicDBObject[]{
|
|
|
|
// new BasicDBObject().append("value",
|
|
|
|
// new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
|
|
|
|
// new BasicDBObject().append("value",
|
|
|
|
// new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
|
|
|
|
//
|
|
|
|
// DBObject match = new BasicDBObject("$match", queryObject);
|
|
|
|
//
|
|
|
|
// // Now the $group operation
|
|
|
|
// DBObject groupFields = new BasicDBObject( "_id", new BasicDBObject("$minute", "$value"));
|
|
|
|
// groupFields.put("pv", new BasicDBObject( "$sum", 1));
|
|
|
|
// DBObject group = new BasicDBObject("$group", groupFields);
|
|
|
|
//
|
|
|
|
// // build the $sort operation
|
|
|
|
// DBObject sortFields = new BasicDBObject( "_id", 1);
|
|
|
|
// DBObject sort = new BasicDBObject("$sort", sortFields );
|
|
|
|
// // run aggregation
|
|
|
|
// AggregationOutput output = reduceDB.aggregate(match, group, sort);
|
|
|
|
// String result = "";
|
|
|
|
// for (DBObject dbObject : output.results()) {
|
|
|
|
// result += dbObject.toString();
|
|
|
|
// }
|
|
|
|
// JSONObject jsonObject = new JSONObject(result);
|
|
|
|
// return jsonObject;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public Result getMonitorInfo(String table,String beginTime, String endTime) {
|
|
public Result getMonitorInfo(String table,String beginTime, String endTime) {
|
|
mongoOperations = new MongoTemplate(mongo, envHealth);
|
|
mongoOperations = new MongoTemplate(mongo, envHealth);
|
|
DBCollection envCollection = mongoOperations.getCollection(table);
|
|
DBCollection envCollection = mongoOperations.getCollection(table);
|
|
@ -105,26 +48,4 @@ public class ServerMonitorService {
|
|
return actionResult;
|
|
return actionResult;
|
|
}
|
|
}
|
|
|
|
|
|
public JSONArray getMonitorInfoTest(String table,String beginTime, String endTime) {
|
|
|
|
mongoOperations = new MongoTemplate(mongo, envHealth);
|
|
|
|
DBCollection envCollection = mongoOperations.getCollection(table);
|
|
|
|
BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
|
|
|
|
new BasicDBObject[]{
|
|
|
|
new BasicDBObject().append("create_time",
|
|
|
|
new BasicDBObject().append(QueryOperators.GTE, DateUtil.toTimestamp(beginTime))),
|
|
|
|
new BasicDBObject().append("create_time",
|
|
|
|
new BasicDBObject().append(QueryOperators.LT, DateUtil.toTimestamp(endTime)))});
|
|
|
|
|
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
DBCursor cursor = envCollection.find(queryObject);
|
|
|
|
while(cursor.hasNext()) {
|
|
|
|
DBObject dbObject = cursor.next();
|
|
|
|
dbObject.removeField("_id");
|
|
|
|
result.put(dbObject);
|
|
|
|
System.out.println(dbObject.toString());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|