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