config process
This commit is contained in:
parent
8f024d8c8b
commit
161cbe0f27
|
@ -28,5 +28,10 @@ public abstract class WMICrawlerOS {
|
|||
return WMICrawlerOS.wmiCrawlerOS;
|
||||
}
|
||||
|
||||
public abstract Object processWMI(Config config) throws Exception;
|
||||
public Object processWMI(Config config) throws Exception {
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import com.jacob.com.Variant;
|
|||
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 java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -25,18 +27,18 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
Item cItem = null;
|
||||
Query cQuery = null;
|
||||
|
||||
int idxMetric = 0;
|
||||
// int idxMetric = 0;
|
||||
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
List<OFResultSet> retlist = new ArrayList<>();
|
||||
ActiveXComponent wmiconnect = null;
|
||||
|
||||
OFResultSet ofResultSet = null;
|
||||
for(int cIndexI = 0 ; cIndexI < config.getItems().size() ; ++cIndexI) {
|
||||
|
||||
cItem = config.getItems().get(cIndexI);
|
||||
|
||||
for( int indexJ = 0; indexJ < cItem.getQueries().size(); ++indexJ) {
|
||||
|
||||
cQuery = cItem.getQueries().get(indexJ);
|
||||
query =cQuery.getQuery();
|
||||
cQuery = cItem.getQuery();
|
||||
query = (String)cQuery.getQueryInfo().get("query");
|
||||
|
||||
wmiconnect = connectServer(config);
|
||||
|
||||
|
@ -51,28 +53,114 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
vCollection.safeRelease();
|
||||
|
||||
|
||||
int count = getCount(dConnection);
|
||||
// int count = getCount(dConnection);
|
||||
|
||||
EnumVariant enumVariant = new EnumVariant(dConnection);
|
||||
dConnection.safeRelease();
|
||||
|
||||
if( count <= 1 ) {
|
||||
getSingleValue(enumVariant, cQuery, cItem, idxMetric, resultMap);
|
||||
}
|
||||
else {
|
||||
getMultiValue(enumVariant, cQuery, cItem, idxMetric, resultMap);
|
||||
}
|
||||
// if( count <= 1 ) {
|
||||
// getSingleValue(enumVariant, cQuery, cItem, idxMetric, resultMap);
|
||||
// }
|
||||
// else {
|
||||
// getMultiValue(enumVariant, cQuery, cItem, idxMetric, resultMap);
|
||||
// }
|
||||
|
||||
ofResultSet = getResultSet(enumVariant, cItem);
|
||||
|
||||
enumVariant.safeRelease();
|
||||
idxMetric += cQuery.getKeys().size();
|
||||
// idxMetric += cQuery.getKeys().size();
|
||||
|
||||
retlist.add(ofResultSet);
|
||||
}
|
||||
|
||||
return retlist;
|
||||
}
|
||||
|
||||
protected OFResultSet getResultSet(EnumVariant enumVariant, Item citem) {
|
||||
|
||||
OFResultSet ofResultSet = new OFResultSetCol(citem);
|
||||
|
||||
Variant vItem = null;
|
||||
Dispatch item = null;
|
||||
|
||||
Variant vValue = null;
|
||||
|
||||
String value = null;
|
||||
|
||||
List<String> row = null;
|
||||
|
||||
List<String> columns = (List<String>)citem.getQuery().getQueryInfo().get("arrayColumns");
|
||||
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
|
||||
row = new ArrayList<>();
|
||||
|
||||
vItem = enumVariant.nextElement();
|
||||
item = vItem.toDispatch();
|
||||
|
||||
for( int indexI = 0; indexI < citem.getQuery().getKeys().size(); ++indexI) {
|
||||
vValue = Dispatch.call(item, citem.getQuery().getKeys().get(indexI));
|
||||
value = vValue.toString();
|
||||
vValue.safeRelease();
|
||||
row.add(value);
|
||||
}
|
||||
|
||||
if (columns != null) {
|
||||
for( int indexI = 0 ; indexI < columns.size(); ++indexI) {
|
||||
vValue = Dispatch.call(item, columns.get(indexI));
|
||||
value = vValue.toString();
|
||||
vValue.safeRelease();
|
||||
row.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
vItem.safeRelease();
|
||||
item.safeRelease();
|
||||
|
||||
ofResultSet.addRow(row);
|
||||
}
|
||||
return resultMap;
|
||||
|
||||
|
||||
return ofResultSet;
|
||||
}
|
||||
|
||||
protected void getMultiValue(EnumVariant enumVariant,Query cQuery, Map<String, String> resultMap) {
|
||||
|
||||
Variant vItem = null;
|
||||
Dispatch item = null;
|
||||
|
||||
String indexColumn = (String)cQuery.getQueryInfo().get("indexColumn");
|
||||
|
||||
Variant vValue = null;
|
||||
Variant vColumn = null;
|
||||
String value = null;
|
||||
String columnStr = null;
|
||||
|
||||
|
||||
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
|
||||
vItem = enumVariant.nextElement();
|
||||
item = vItem.toDispatch();
|
||||
|
||||
vColumn = Dispatch.call(item, indexColumn);
|
||||
columnStr = vColumn.toString();
|
||||
vColumn.safeRelease();
|
||||
|
||||
for( int indexI = 0; indexI < cQuery.getKeys().size(); ++indexI) {
|
||||
|
||||
vValue = Dispatch.call(item, cQuery.getKeys().get(indexI));
|
||||
value = vValue.toString();
|
||||
|
||||
vValue.safeRelease();
|
||||
}
|
||||
|
||||
vItem.safeRelease();
|
||||
item.safeRelease();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void getMultiValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map<String, String> resultMap) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.loafle.overflow.crawler.wmi;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.loafle.overflow.crawler.config.Config;
|
||||
import com.loafle.overflow.crawler.result.OFResultSet;
|
||||
import com.sun.xml.internal.ws.api.ResourceLoader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -135,12 +136,19 @@ public class WMICrawlerTest {
|
|||
WMICrawler wmiCrawler = new WMICrawler();
|
||||
|
||||
|
||||
Map<String, String> resultMap = (Map<String, String>)wmiCrawler.getInternal(c);
|
||||
|
||||
List<OFResultSet> resultList = (List<OFResultSet>)wmiCrawler.getInternal(c);
|
||||
|
||||
for(int indexI = 0 ; indexI < resultList.size(); ++indexI) {
|
||||
Map<String,String> resultMap = resultList.get(indexI).getData();
|
||||
System.out.println("============================================");
|
||||
for( String key : resultMap.keySet() ){
|
||||
System.out.println( String.format("key : %s ||| value : %s", key, resultMap.get(key)) );
|
||||
}
|
||||
System.out.println("============================================");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -178,4 +186,22 @@ public class WMICrawlerTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplace() {
|
||||
|
||||
|
||||
String aaa = "cpu[$0].usage.system";
|
||||
|
||||
String bbb = "$";
|
||||
String ccc = bbb + String.valueOf(0);
|
||||
|
||||
String ddd = aaa.replace(ccc, "asdfasdf");
|
||||
|
||||
|
||||
System.out.println(ddd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -19,33 +19,43 @@
|
|||
"container":"network_crawler"
|
||||
},
|
||||
"items" : [
|
||||
|
||||
{
|
||||
"metrics": [
|
||||
"cpu[$0].usage.system",
|
||||
"cpu[$0].usage.idle",
|
||||
"cpu[$0].usage.user"
|
||||
],
|
||||
"query":
|
||||
{
|
||||
"queryInfo": {
|
||||
"query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor",
|
||||
"parseDirection" : "col",
|
||||
"arrayColumns":["Name"]
|
||||
},
|
||||
"keys":["PercentProcessorTime","PercentIdleTime", "PercentUserTime"]
|
||||
}
|
||||
|
||||
}
|
||||
,{
|
||||
"metrics": [
|
||||
"cpu.usage.system",
|
||||
"cpu.usage.idle",
|
||||
"cpu.usage.user"
|
||||
],
|
||||
"queries": [
|
||||
"query":
|
||||
{
|
||||
"query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'",
|
||||
"keys":["PercentProcessorTime","PercentIdleTime", "PercentUserTime"]
|
||||
}
|
||||
]
|
||||
"queryInfo": {
|
||||
"query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'",
|
||||
"parseDirection" : "col"
|
||||
|
||||
},
|
||||
{
|
||||
"metrics": [
|
||||
"cpu[].usage.system",
|
||||
"cpu[].usage.idle",
|
||||
"cpu[].usage.user"
|
||||
],
|
||||
"queries": [
|
||||
{
|
||||
"query":"select PercentProcessorTime, PercentIdleTime, PercentUserTime from Win32_PerfFormattedData_PerfOS_Processor where Name!='_Total'",
|
||||
"keys":["PercentProcessorTime","PercentIdleTime", "PercentUserTime"]
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user