diff --git a/src/main/java/com/loafle/overflow/crawler/config/Item.java b/src/main/java/com/loafle/overflow/crawler/config/Item.java index 7fdef3d..3afc081 100644 --- a/src/main/java/com/loafle/overflow/crawler/config/Item.java +++ b/src/main/java/com/loafle/overflow/crawler/config/Item.java @@ -8,30 +8,31 @@ import java.util.Map; */ public class Item { - List metrics; - List keys; - Map queryInfo; + private List keys; + private QueryInfo queryInfo; + private MappingInfo mappingInfo; - public List getMetrics() { - return metrics; - } - public void setMetrics(List metrics) { - this.metrics = metrics; - } - - public List getKeys() { + public List getKeys() { return keys; } - public void setKeys(List keys) { + public void setKeys(List keys) { this.keys = keys; } - public Map getQueryInfo() { + public QueryInfo getQueryInfo() { return queryInfo; } - public void setQueryInfo(Map queryInfo) { + public void setQueryInfo(QueryInfo queryInfo) { this.queryInfo = queryInfo; } + + public MappingInfo getMappingInfo() { + return mappingInfo; + } + + public void setMappingInfo(MappingInfo mappingInfo) { + this.mappingInfo = mappingInfo; + } } diff --git a/src/main/java/com/loafle/overflow/crawler/config/Keys.java b/src/main/java/com/loafle/overflow/crawler/config/Keys.java new file mode 100644 index 0000000..3816531 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/config/Keys.java @@ -0,0 +1,26 @@ +package com.loafle.overflow.crawler.config; + +/** + * Created by root on 17. 4. 26. + */ +public class Keys { + + private String metric; + private String key; + + public String getMetric() { + return metric; + } + + public void setMetric(String metric) { + this.metric = metric; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/config/MappingInfo.java b/src/main/java/com/loafle/overflow/crawler/config/MappingInfo.java new file mode 100644 index 0000000..34e6dde --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/config/MappingInfo.java @@ -0,0 +1,46 @@ +package com.loafle.overflow.crawler.config; + +import java.util.List; + +/** + * Created by root on 17. 4. 26. + */ +public class MappingInfo { + + private String parseDirection; + private List arrayColumns; + private List keyColumns; + private String valueColumn; + + public String getParseDirection() { + return parseDirection; + } + + public void setParseDirection(String parseDirection) { + this.parseDirection = parseDirection; + } + + public List getArrayColumns() { + return arrayColumns; + } + + public void setArrayColumns(List arrayColumns) { + this.arrayColumns = arrayColumns; + } + + public List getKeyColumns() { + return keyColumns; + } + + public void setKeyColumns(List keyColumns) { + this.keyColumns = keyColumns; + } + + public String getValueColumn() { + return valueColumn; + } + + public void setValueColumn(String valueColumn) { + this.valueColumn = valueColumn; + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/config/QueryInfo.java b/src/main/java/com/loafle/overflow/crawler/config/QueryInfo.java new file mode 100644 index 0000000..cef1e60 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/config/QueryInfo.java @@ -0,0 +1,27 @@ +package com.loafle.overflow.crawler.config; + +import java.util.Map; + +/** + * Created by root on 17. 4. 26. + */ +public class QueryInfo { + private String query; + private Map extend; + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public Map getExtend() { + return extend; + } + + public void setExtend(Map extend) { + this.extend = extend; + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java index e7acc0b..ad66770 100644 --- a/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java @@ -42,7 +42,7 @@ public abstract class OFResultSet { // methods static public OFResultSet newInstance(Item item) { - String type = (String) item.getQueryInfo().get("parseDirection"); + String type = (String) item.getMappingInfo().getParseDirection(); if (type != null && type.equals("row")) { return new OFResultSetRow(item); } else { diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java index d30f856..f888ae9 100644 --- a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java @@ -1,6 +1,7 @@ package com.loafle.overflow.crawler.result; import com.loafle.overflow.crawler.config.Item; +import com.loafle.overflow.crawler.config.Keys; import java.util.*; @@ -16,15 +17,15 @@ public class OFResultSetCol extends OFResultSet{ public void setMeta() { - List meta = this.item.getKeys(); - List arrayColumns = (List)this.item.getQueryInfo().get("arrayColumns"); + List meta = this.item.getKeys(); + List arrayColumns = (List)this.item.getMappingInfo().getArrayColumns(); if(this.meta == null) { this.meta = new HashMap<>(); } for(int indexI = 0; indexI < meta.size(); ++indexI) { - this.meta.put(meta.get(indexI), indexI); + this.meta.put(meta.get(indexI).getKey(), indexI); } if( arrayColumns != null) { @@ -39,8 +40,8 @@ public class OFResultSetCol extends OFResultSet{ public Map parse() { - List metrics = this.item.getMetrics(); - List arrayColumns = (List)this.item.getQueryInfo().get("arrayColumns"); + List metrics = this.item.getKeys(); + List arrayColumns = (List)this.item.getMappingInfo().getArrayColumns(); // this.meta Map resultMap = new HashMap<>(); @@ -72,7 +73,7 @@ public class OFResultSetCol extends OFResultSet{ for(int indexK = 0 ; indexK < metrics.size(); ++indexK) { - metric = metrics.get(indexK); + metric = metrics.get(indexK).getMetric(); metric = convertMetric(metric, arrayValue); diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java index 994a09c..5757aaa 100644 --- a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java @@ -1,6 +1,7 @@ package com.loafle.overflow.crawler.result; import com.loafle.overflow.crawler.config.Item; +import com.loafle.overflow.crawler.config.Keys; import java.util.ArrayList; import java.util.HashMap; @@ -21,9 +22,9 @@ public class OFResultSetRow extends OFResultSet{ List meta = new ArrayList<>(); - List arrayColumns = (List) this.item.getQueryInfo().get("arrayColumns"); - List keyColumns = (List) this.item.getQueryInfo().get("keyColumns"); - String valueColumn = (String) this.item.getQueryInfo().get("valueColumn"); + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) this.item.getMappingInfo().getKeyColumns(); + String valueColumn = (String) this.item.getMappingInfo().getValueColumn(); if (arrayColumns != null) { for (String c : arrayColumns) { meta.add(c); @@ -53,7 +54,7 @@ public class OFResultSetRow extends OFResultSet{ Map returnMap = new HashMap<>(); - String valueColumn = (String) this.item.getQueryInfo().get("valueColumn"); + String valueColumn = (String) this.item.getMappingInfo().getValueColumn(); for (List row : this.rows) { String key = makeKey(row); @@ -65,11 +66,11 @@ public class OFResultSetRow extends OFResultSet{ private String makeKey(List data) { - List metrics = this.item.getMetrics(); + List metrics = this.item.getKeys(); - List arrayColumns = (List) this.item.getQueryInfo().get("arrayColumns"); - List keyColumns = (List) this.item.getQueryInfo().get("keyColumns"); - List keys = this.item.getKeys(); + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) this.item.getMappingInfo().getKeyColumns(); + List keys = this.item.getKeys(); boolean find = false; int findIndex = -1; @@ -85,7 +86,7 @@ public class OFResultSetRow extends OFResultSet{ if (find == true) {break;} } - String metric = metrics.get(findIndex); + String metric = metrics.get(findIndex).getMetric(); if (arrayColumns != null) { for (int i =0 ; i< arrayColumns.size() ; ++i) { diff --git a/src/test/resources/config/example.json b/src/test/resources/config/example.json index d7388fa..6e591bc 100644 --- a/src/test/resources/config/example.json +++ b/src/test/resources/config/example.json @@ -20,15 +20,28 @@ }, "items" : [ { - "query": + "keys" : [ { - "queryInfo" : { - "query" : "show session status", - "direction" : "col" - }, - "keys" : [] + "metric" : "object[$0].db[$1].datafile_size", + "key" : "Data File(s) Size (KB)" + }, + { + "metric" : "object[$0].db[$1].logfile_size", + "key" : "Log File(s) Size (KB)" } - + ], + "queryInfo" : { + "query": "select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'", + "extend" : { + "command":"" + } + }, + "mappingInfo" : { + "parseDirection" : "row", + "arrayColumns" : [ "object_name","instance_name"], + "keyColumns" : ["counter_name"], + "valueColumn" : "cntr_value" + } } ] } \ No newline at end of file