config metric test
This commit is contained in:
parent
142d897ab0
commit
a5d1969d49
@ -3,7 +3,6 @@ package com.loafle.overflow.crawler.mongo;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.crawler.config.Config;
|
||||
import com.loafle.overflow.crawler.config.Item;
|
||||
import com.loafle.overflow.crawler.config.Query;
|
||||
import com.loafle.overflow.crawler.result.OFResultSet;
|
||||
import com.loafle.overflow.crawler.result.OFResultSetCol;
|
||||
import com.mongodb.MongoClient;
|
||||
@ -13,18 +12,14 @@ import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
public class MongoCrawler extends Crawler {
|
||||
|
||||
public Object collectMetric(Config c) throws Exception {
|
||||
|
||||
MongoClient mongoClient = null;
|
||||
// Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
|
||||
String dataBaseName = null;
|
||||
String statusCommand = null;
|
||||
@ -48,36 +43,21 @@ public class MongoCrawler extends Crawler {
|
||||
for (Item item : items) {
|
||||
|
||||
row = new ArrayList<>();
|
||||
|
||||
ofResultSet = new OFResultSetCol(item);
|
||||
Query query = item.getQuery();
|
||||
|
||||
dataBaseName = (String)item.getQuery().getQueryInfo().get("dataBaseName");
|
||||
statusCommand = (String)item.getQuery().getQueryInfo().get("statusCommand");
|
||||
dataBaseName = (String)item.getQueryInfo().get("dataBaseName");
|
||||
statusCommand = (String)item.getQueryInfo().get("statusCommand");
|
||||
|
||||
MongoDatabase database = mongoClient.getDatabase(dataBaseName);
|
||||
Document serverStatus = database.runCommand(new Document(statusCommand, 1));
|
||||
|
||||
|
||||
Map<String, String> re = (Map<String, String>)serverStatus.get(query.getQueryInfo().get("query"));
|
||||
|
||||
// Map<String,Object> resultMap = new HashMap<String, Object>();
|
||||
// for (Map.Entry<String, Object> set : serverStatus.entrySet()){
|
||||
// resultMap.put(set.getKey(), set.getValue());
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// Map<String, String> re = (Map<String, String>) resultMap.get(query.getQueryInfo().get("query"));
|
||||
|
||||
for (int index =0 ; index < query.getKeys().size() ; ++index) {
|
||||
row.add(String.valueOf(re.get(query.getKeys().get(index))));
|
||||
Map<String, String> re = (Map<String, String>)serverStatus.get(item.getQueryInfo().get("query"));
|
||||
for (int index =0 ; index < item.getKeys().size() ; ++index) {
|
||||
row.add(String.valueOf(re.get(item.getKeys().get(index))));
|
||||
}
|
||||
|
||||
ofResultSet.addRow(row);
|
||||
|
||||
ofResultSets.add(ofResultSet);
|
||||
|
||||
}
|
||||
}catch (Exception e) {
|
||||
throw e;
|
||||
|
@ -28,24 +28,19 @@
|
||||
"memory.usage.mapped",
|
||||
"memory.usage.mappedWithJournal"
|
||||
],
|
||||
"query":
|
||||
{
|
||||
"queryInfo": {
|
||||
"query":"mem",
|
||||
"dataBaseName":"admin",
|
||||
"statusCommand":"serverStatus",
|
||||
"parseDirection" : "col"
|
||||
},
|
||||
"keys" : [
|
||||
"bits",
|
||||
"resident",
|
||||
"virtual",
|
||||
"supported",
|
||||
"mapped",
|
||||
"mappedWithJournal"
|
||||
]
|
||||
}
|
||||
|
||||
"queryInfo": {
|
||||
"query":"mem",
|
||||
"dataBaseName":"admin",
|
||||
"statusCommand":"serverStatus"
|
||||
},
|
||||
"keys" : [
|
||||
"bits",
|
||||
"resident",
|
||||
"virtual",
|
||||
"supported",
|
||||
"mapped",
|
||||
"mappedWithJournal"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user