From e00e49b429d23081267daad644dc274c46d5ba0d Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 26 Apr 2017 12:19:22 +0900 Subject: [PATCH] fix config --- .../overflow/crawler/mongo/MongoCrawler.java | 15 ++++---- src/test/resources/config/example.json | 37 +++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/mongo/MongoCrawler.java b/src/main/java/com/loafle/overflow/crawler/mongo/MongoCrawler.java index dd9fa63..cb4fff4 100644 --- a/src/main/java/com/loafle/overflow/crawler/mongo/MongoCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/mongo/MongoCrawler.java @@ -3,7 +3,7 @@ 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; @@ -49,17 +49,18 @@ public class MongoCrawler extends Crawler { row = new ArrayList<>(); - ofResultSet = new OFResultSetCol(item); + ofResultSet = OFResultSet.newInstance(item); + Map metaMap = ofResultSet.getMeta(); - dataBaseName = (String)item.getQueryInfo().get("dataBaseName"); - statusCommand = (String)item.getQueryInfo().get("statusCommand"); + dataBaseName = item.getQueryInfo().getExtend().get("dataBaseName"); + statusCommand = item.getQueryInfo().getExtend().get("statusCommand"); MongoDatabase database = mongoClient.getDatabase(dataBaseName); Document serverStatus = database.runCommand(new Document(statusCommand, 1)); - Map re = (Map)serverStatus.get(item.getQueryInfo().get("query")); + Map re = (Map)serverStatus.get(item.getQueryInfo().getQuery()); // Map resultMap = new HashMap(); // for (Map.Entry set : serverStatus.entrySet()){ @@ -70,8 +71,8 @@ public class MongoCrawler extends Crawler { // Map re = (Map) resultMap.get(query.getQueryInfo().get("query")); - for (int index =0 ; index < item.getKeys().size() ; ++index) { - row.add(String.valueOf(re.get(item.getKeys().get(index)))); + for( String key : metaMap.keySet()) { + row.add(String.valueOf(re.get(key))); } ofResultSet.addRow(row); diff --git a/src/test/resources/config/example.json b/src/test/resources/config/example.json index bd22264..6967a5e 100644 --- a/src/test/resources/config/example.json +++ b/src/test/resources/config/example.json @@ -20,27 +20,24 @@ }, "items" : [ { - "metrics" : [ - "memory.usage.bits", - "memory.usage.rss", - "memory.usage.vmem", - "memory.usage.supported", - "memory.usage.mapped", - "memory.usage.mappedWithJournal" - ], - "queryInfo": { - "query":"mem", - "dataBaseName":"admin", - "statusCommand":"serverStatus" - }, "keys" : [ - "bits", - "resident", - "virtual", - "supported", - "mapped", - "mappedWithJournal" - ] + {"metric":"memory.usage.bits", "key":"bits"}, + {"metric":"memory.usage.rss", "key":"resident"}, + {"metric":"memory.usage.vmem", "key":"virtual"}, + {"metric":"memory.usage.supported", "key":"supported"}, + {"metric":"memory.usage.mapped", "key":"mapped"}, + {"metric":"memory.usage.mappedWithJournal", "key":"mappedWithJournal"} + ], + "queryInfo" : { + "query": "mem", + "extend" : { + "dataBaseName":"admin", + "statusCommand": "serverStatus" + } + }, + "mappingInfo" : { + "parseDirection" : "col" + } } ] } \ No newline at end of file