From 892c4e2653bb73f8a8a54cb345955a6812a994cb Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 26 Apr 2017 12:07:09 +0900 Subject: [PATCH] fix config --- .../crawler/wmi/WMICrawlerWindows.java | 124 +++++++++--------- src/test/resources/config/example.json | 53 ++++---- 2 files changed, 92 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java index 379aa3c..28f09fc 100644 --- a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java +++ b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java @@ -37,7 +37,7 @@ public class WMICrawlerWindows extends WMICrawlerOS { cItem = config.getItems().get(cIndexI); - query = (String)cItem.getQueryInfo().get("query"); + query = cItem.getQueryInfo().getQuery(); wmiconnect = connectServer(config); @@ -111,40 +111,40 @@ public class WMICrawlerWindows extends WMICrawlerOS { return ofResultSet; } - - protected void getMultiValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { - - Variant vItem = null; - Dispatch item = null; - - - int keyIdx = 0; - while (enumVariant.hasMoreElements()) { - - vItem = enumVariant.nextElement(); - item = vItem.toDispatch(); - - - String name = null; - String value = null; - Variant vValue = null; - - for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { - name = cQuery.getKeys().get(indexI); - vValue = Dispatch.call(item, name); - value = vValue.toString(); - String keyStr = convertArrayKey(cItem.getMetrics().get(indexI),keyIdx ); - resultMap.put(keyStr, value); - vValue.safeRelease(); - } - - vItem.safeRelease(); - item.safeRelease(); - ++idxMetric; - ++keyIdx; - } - - } +// +// protected void getMultiValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { +// +// Variant vItem = null; +// Dispatch item = null; +// +// +// int keyIdx = 0; +// while (enumVariant.hasMoreElements()) { +// +// vItem = enumVariant.nextElement(); +// item = vItem.toDispatch(); +// +// +// String name = null; +// String value = null; +// Variant vValue = null; +// +// for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { +// name = cQuery.getKeys().get(indexI); +// vValue = Dispatch.call(item, name); +// value = vValue.toString(); +// String keyStr = convertArrayKey(cItem.getMetrics().get(indexI),keyIdx ); +// resultMap.put(keyStr, value); +// vValue.safeRelease(); +// } +// +// vItem.safeRelease(); +// item.safeRelease(); +// ++idxMetric; +// ++keyIdx; +// } +// +// } protected String convertArrayKey(String key, int index) { int idx = key.indexOf("["); @@ -168,33 +168,33 @@ public class WMICrawlerWindows extends WMICrawlerOS { return ret; } - protected void getSingleValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { - - Variant vItem = null; - Dispatch item = null; - - while (enumVariant.hasMoreElements()) { - - vItem = enumVariant.nextElement(); - item = vItem.toDispatch(); - - String name = null; - String value = null; - Variant vValue = null; - - for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { - name = cQuery.getKeys().get(indexI); - vValue = Dispatch.call(item, name); - value = vValue.toString(); - resultMap.put(cItem.getMetrics().get(idxMetric++), value); - vValue.safeRelease(); - } - - vItem.safeRelease(); - item.safeRelease(); - } - - } +// protected void getSingleValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { +// +// Variant vItem = null; +// Dispatch item = null; +// +// while (enumVariant.hasMoreElements()) { +// +// vItem = enumVariant.nextElement(); +// item = vItem.toDispatch(); +// +// String name = null; +// String value = null; +// Variant vValue = null; +// +// for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { +// name = cQuery.getKeys().get(indexI); +// vValue = Dispatch.call(item, name); +// value = vValue.toString(); +// resultMap.put(cItem.getMetrics().get(idxMetric++), value); +// vValue.safeRelease(); +// } +// +// vItem.safeRelease(); +// item.safeRelease(); +// } +// +// } protected List getColumns(Dispatch item) { diff --git a/src/test/resources/config/example.json b/src/test/resources/config/example.json index 20ba905..74ff15b 100644 --- a/src/test/resources/config/example.json +++ b/src/test/resources/config/example.json @@ -20,36 +20,43 @@ }, "items" : [ { - "metrics": [ - "cpu[$0].usage.system", - "cpu[$0].usage.idle", - "cpu[$0].usage.user" + "keys" : [ + {"metric" : "cpu[$0].usage.system", "key":"PercentProcessorTime"}, + {"metric" : "cpu[$0].usage.idle", "key":"PercentIdleTime"}, + {"metric" : "cpu[$0].usage.user", "key":"PercentUserTime"} ], - "queryInfo": { - "query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor", + "queryInfo" : { + "query": "select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor", + "extend" : { + "nameSpace":"root/cimv2", + "wmicPath": "" + } + }, + "mappingInfo" : { "parseDirection" : "col", - "arrayColumns":["Name"] - }, - "keys":["PercentProcessorTime","PercentIdleTime", "PercentUserTime"] + "arrayColumns" : [ "Name"] + } } - ,{ - "metrics": [ - "cpu.usage.system", - "cpu.usage.idle", - "cpu.usage.user" + , + { + "keys" : [ + {"metric" : "cpu.usage.system", "key":"PercentProcessorTime"}, + {"metric" : "cpu.usage.idle", "key":"PercentIdleTime"}, + {"metric" : "cpu.usage.user", "key":"PercentUserTime"} ], - - "queryInfo": { - "query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'", - "parseDirection" : "col" - + "queryInfo" : { + "query": "select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'", + "extend" : { + "nameSpace":"root/cimv2", + "wmicPath": "" + } }, - "keys":["PercentProcessorTime","PercentIdleTime", "PercentUserTime"] - - + "mappingInfo" : { + "parseDirection" : "col", + "arrayColumns" : [ "Name"] + } } - ] } \ No newline at end of file