fixed generate sensor config
This commit is contained in:
parent
bf85817e8b
commit
a9ea7af14e
|
@ -7,6 +7,7 @@ import com.loafle.overflow.crawler.config.*;
|
|||
import com.loafle.overflow.module.domain.model.Domain;
|
||||
import com.loafle.overflow.module.infra.model.*;
|
||||
import com.loafle.overflow.module.infra.service.InfraService;
|
||||
import com.loafle.overflow.module.meta.model.MetaCrawler;
|
||||
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
||||
import com.loafle.overflow.module.meta.service.MetaSensorItemKeyService;
|
||||
import com.loafle.overflow.module.probe.model.Probe;
|
||||
|
@ -48,7 +49,7 @@ public class SensorService {
|
|||
@Autowired
|
||||
private MetaSensorItemKeyService metaSensorItemKeyService;
|
||||
|
||||
private Map<Integer, String> mappingMap = null;
|
||||
private Map<Short, Map<Integer, String>> mappingMap = null;
|
||||
|
||||
public Sensor regist(Sensor sensor) {
|
||||
return this.sensorDAO.save(sensor);
|
||||
|
@ -112,6 +113,8 @@ public class SensorService {
|
|||
|
||||
public String generateSensorConfig(Sensor sensor) throws IOException {
|
||||
|
||||
|
||||
|
||||
// Sensor dbSensor = this.sensorDAO.findOne(sensor.getId());
|
||||
PageParams pageParams = new PageParams();
|
||||
pageParams.setPageNo(0);
|
||||
|
@ -129,6 +132,11 @@ public class SensorService {
|
|||
|
||||
Infra infra = this.infraService.readByTarget(dbSensor.getTarget());
|
||||
|
||||
// 7 = Infra OS Service
|
||||
if(infra.getInfraType().getId() != 7) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// InfraHost infraHost = this.getInfraHost(infra);
|
||||
|
||||
com.loafle.overflow.module.infra.model.InfraService infraService = (com.loafle.overflow.module.infra.model.InfraService)infra;
|
||||
|
@ -145,56 +153,39 @@ public class SensorService {
|
|||
|
||||
target.setConnection(connection);
|
||||
|
||||
Map<String, Object> auth = new HashMap<>();
|
||||
auth.put("url", "jdbc:mysql://"+StringConvertor.intToIp(infraService.getHost().getIp())+":"+String.valueOf(infraService.getPort()));
|
||||
auth.put("id", "docker"); // FIXME: Auth Info
|
||||
auth.put("pw", "qwer5795QWER"); // FIXME: Auth Info
|
||||
Map<String, Object> auth = this.getAuth(infraService);
|
||||
|
||||
target.setAuth(auth);
|
||||
|
||||
config.setTarget(target);
|
||||
|
||||
// FIXME: Interval
|
||||
Schedule schedule = new Schedule();
|
||||
schedule.setInterval("5"); // FIXME: Interval
|
||||
|
||||
schedule.setInterval("5");
|
||||
config.setSchedule(schedule);
|
||||
|
||||
Crawler crawler = new Crawler();
|
||||
crawler.setName(dbSensor.getCrawler().getName());
|
||||
crawler.setContainer("java_proxy"); // FIXME: if
|
||||
|
||||
Crawler crawler = this.getCrawler(dbSensor.getCrawler());
|
||||
config.setCrawler(crawler);
|
||||
|
||||
if(this.mappingMap == null) {
|
||||
this.mappingMap = this.metaSensorItemKeyService.readAllByCrawler(dbSensor.getCrawler());
|
||||
}
|
||||
Map<Integer, String> KeyMap = this.initMappingMap(dbSensor.getCrawler());
|
||||
|
||||
Item item = new Item();
|
||||
Keys keys = null;
|
||||
List<Keys> keysList = new ArrayList<>();
|
||||
for(SensorItem sItem : sensorItems) {
|
||||
keys = new Keys();
|
||||
// sItem.getItem().get
|
||||
keys.setMetric(sItem.getItem().getKey());
|
||||
keys.setKey(this.mappingMap.get(sItem.getItem().getId()));
|
||||
keys.setKey(KeyMap.get(sItem.getItem().getId()));
|
||||
keysList.add(keys);
|
||||
}
|
||||
item.setKeys(keysList);
|
||||
|
||||
QueryInfo queryInfo = new QueryInfo();
|
||||
queryInfo.setQuery("show status");
|
||||
MappingInfo mappingInfo = new MappingInfo();
|
||||
|
||||
this.setQueryAndMapping(dbSensor.getCrawler(), keysList, queryInfo, mappingInfo);
|
||||
|
||||
item.setQueryInfo(queryInfo);
|
||||
|
||||
MappingInfo mappingInfo = new MappingInfo();
|
||||
mappingInfo.setParseDirection("row");
|
||||
mappingInfo.setValueColumn("Value");
|
||||
|
||||
List<String> keyColumns = new ArrayList<>();
|
||||
keyColumns.add("Variable_name");
|
||||
|
||||
mappingInfo.setKeyColumns(keyColumns);
|
||||
|
||||
item.setMappingInfo(mappingInfo);
|
||||
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
|
@ -208,6 +199,96 @@ public class SensorService {
|
|||
return objectMapper.writeValueAsString(config);
|
||||
}
|
||||
|
||||
private void setQueryAndMapping(MetaCrawler metaCrawler, List<Keys> keysList, QueryInfo queryInfo, MappingInfo mappingInfo) {
|
||||
|
||||
switch (metaCrawler.getId()) {
|
||||
case 11:
|
||||
{
|
||||
String query = "show status where ";
|
||||
// queryInfo.setQuery("show status where ");
|
||||
|
||||
Keys keys = null;
|
||||
for(int indexI = 0 ; indexI < keysList.size(); ++indexI) {
|
||||
keys = keysList.get(indexI);
|
||||
query += "variable_name = '";
|
||||
query += keys.getKey();
|
||||
query += "'";
|
||||
if(indexI + 1 < keysList.size()) {
|
||||
query += " or ";
|
||||
}
|
||||
}
|
||||
|
||||
queryInfo.setQuery(query);
|
||||
|
||||
mappingInfo.setParseDirection("row");
|
||||
mappingInfo.setValueColumn("Value");
|
||||
|
||||
List<String> keyColumns = new ArrayList<>();
|
||||
keyColumns.add("Variable_name");
|
||||
|
||||
mappingInfo.setKeyColumns(keyColumns);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<Integer, String> initMappingMap(MetaCrawler metaCrawler) {
|
||||
|
||||
if(this.mappingMap == null) {
|
||||
this.mappingMap = new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Integer, String> resultMap = this.mappingMap.get(metaCrawler.getId());
|
||||
|
||||
if(resultMap != null) {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
resultMap = this.metaSensorItemKeyService.readAllByCrawler(metaCrawler);
|
||||
this.mappingMap.put(metaCrawler.getId(), resultMap);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private Map<String, Object> getAuth(com.loafle.overflow.module.infra.model.InfraService infraService) {
|
||||
|
||||
Map<String, Object> auth = new HashMap<>();
|
||||
auth.put("url", "jdbc:mysql://"+StringConvertor.intToIp(infraService.getHost().getIp())+":"+String.valueOf(infraService.getPort()));
|
||||
auth.put("id", "docker"); // FIXME: Auth Info
|
||||
auth.put("pw", "qwer5795QWER"); // FIXME: Auth Info
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
private Crawler getCrawler(MetaCrawler metaCrawler) {
|
||||
|
||||
Crawler crawler = new Crawler();
|
||||
crawler.setName(metaCrawler.getName());
|
||||
|
||||
String container = "";
|
||||
|
||||
switch (metaCrawler.getId()) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 13:
|
||||
case 15:
|
||||
container = "java_proxy";
|
||||
break;
|
||||
default:
|
||||
container = "java_proxy";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
crawler.setContainer(container);
|
||||
|
||||
return crawler;
|
||||
}
|
||||
|
||||
private InfraHost getInfraHost(Infra infra) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user