Index: web-module/profiles/dev/support.properties =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r01b0a37c18e4c4f324b697ed56787e9a4c06ae7d --- web-module/profiles/dev/support.properties (.../support.properties) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/profiles/dev/support.properties (.../support.properties) (revision 01b0a37c18e4c4f324b697ed56787e9a4c06ae7d) @@ -35,4 +35,7 @@ allinone.monitoring.filebeatindex = filebeat-* allinone.monitoring.packetbeatindex = packetbeat-* allinone.monitoring.topbeatindex = topbeat-* -allinone.monitoring.apmindex = apm-* \ No newline at end of file +allinone.monitoring.apmindex = apm-* + +allinone.monitoring.influx.url = http://www.313.co.kr:3000/api/datasources/proxy/1/query? +allinone.monitoring.influx.query = db=scouterCounter&q=SHOW%20TAG%20VALUES%20FROM%20%22counter%22%20WITH%20KEY%20%3D%20%22obj%22&epoch=ms \ No newline at end of file Index: web-module/profiles/operation/support.properties =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r01b0a37c18e4c4f324b697ed56787e9a4c06ae7d --- web-module/profiles/operation/support.properties (.../support.properties) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/profiles/operation/support.properties (.../support.properties) (revision 01b0a37c18e4c4f324b697ed56787e9a4c06ae7d) @@ -35,4 +35,8 @@ allinone.monitoring.filebeatindex = filebeat-* allinone.monitoring.packetbeatindex = packetbeat-* allinone.monitoring.topbeatindex = topbeat-* -allinone.monitoring.apmindex = apm-* \ No newline at end of file +allinone.monitoring.apmindex = apm-* + + +allinone.monitoring.influx.url = http://www.313.co.kr:3000/api/datasources/proxy/1/query? +allinone.monitoring.influx.query = db=scouterCounter&q=SHOW%20TAG%20VALUES%20FROM%20%22counter%22%20WITH%20KEY%20%3D%20%22obj%22&epoch=ms \ No newline at end of file Index: web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java =================================================================== diff -u -r9fadf60d728e3c03ff2588003f7f93296f04862f -r01b0a37c18e4c4f324b697ed56787e9a4c06ae7d --- web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java (.../DeviceListServiceImpl.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) +++ web-module/src/main/java/egovframework/api/arms/devicelist/service/DeviceListServiceImpl.java (.../DeviceListServiceImpl.java) (revision 01b0a37c18e4c4f324b697ed56787e9a4c06ae7d) @@ -1,10 +1,8 @@ package egovframework.api.arms.devicelist.service; -import egovframework.api.arms.devicelist.batch.DeviceListBatch; import egovframework.api.arms.devicelist.vo.DeviceListDTO; import egovframework.com.cmm.service.EgovProperties; import egovframework.com.ext.jstree.springHibernate.core.service.JsTreeHibernateServiceImpl; -import org.apache.commons.collections.CollectionUtils; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.hibernate.criterion.Order; @@ -13,19 +11,15 @@ import org.json.simple.parser.JSONParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @@ -72,6 +66,25 @@ return deviceListDTOs; } + public List getDeviceListsFromInfluxDB() throws Exception { + + JSONArray jsonArrayInfoFromInfluxDB = this.getInfoFromInfluxDB(); + + ArrayList deviceListDTOs = new ArrayList(); + for (Object bucketJsonObj: jsonArrayInfoFromInfluxDB) { + JSONObject bucketJson = (JSONObject) bucketJsonObj; + logger.info(bucketJson.toString()); + + DeviceListDTO deviceListDTO = new DeviceListDTO(); + deviceListDTO.setC_title(bucketJson.toString()); + deviceListDTO.setC_monitor_device_hostname(bucketJson.toString()); + //포지션 잡아야 함 + deviceListDTOs.add(deviceListDTO); + } + + return deviceListDTOs; + } + @Override public List getDeviceListDifference(List jstreeDeviceList, List elkDeviceLists) throws Exception { @@ -121,14 +134,24 @@ //elasticsearch api 를 활용해서 full list 를 얻어온다. -> ELK에 등록된 host full list List deviceListsFromELK = getDeviceListsFromELK(); + //influxdb api 를 활용해서 full list 를 얻어온다 -> InfluxDB에 등록된 host full list + List deviceListsFromInfluxDB = getDeviceListsFromInfluxDB(); + //차집합을 통해 디비에 등록할 리스트를 추린다. List differenceUpdateSet = getDeviceListDifference(deviceListsFromJstree, deviceListsFromELK); for (DeviceListDTO deviceListDTO: differenceUpdateSet) { this.addNode(deviceListDTO); } - return differenceUpdateSet.size(); + //차집합을 통해 디비에 등록할 리스트를 추린다. + List diffUpdateSet = getDeviceListDifference(deviceListsFromJstree, deviceListsFromInfluxDB); + + for (DeviceListDTO deviceListDTO: diffUpdateSet) { + this.addNode(deviceListDTO); + } + + return differenceUpdateSet.size() + diffUpdateSet.size(); } public JSONArray getInfoFromELK() throws Exception { @@ -208,4 +231,44 @@ return bucketJsonObjs; } + + public JSONArray getInfoFromInfluxDB() throws Exception { + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); + factory.setReadTimeout(5000); // 읽기시간초과, ms + factory.setConnectTimeout(3000); // 연결시간초과, ms + HttpClient httpClient = HttpClientBuilder.create() + .setMaxConnTotal(100) // connection pool 적용 + .setMaxConnPerRoute(5) // connection pool 적용 + .build(); + factory.setHttpClient(httpClient); // 동기실행에 사용될 HttpClient 세팅 + RestTemplate restTemplate = new RestTemplate(factory); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + String influxdbBaseUrl = EgovProperties.getProperty("allinone.monitoring.influx.url"); + String influxdbBaseQuery = EgovProperties.getProperty("allinone.monitoring.influx.query"); + String returnResultStr = restTemplate.getForObject( influxdbBaseUrl + influxdbBaseQuery , String.class); + + JSONParser jsonParser = new JSONParser(); + Object jsonObj = jsonParser.parse( returnResultStr ); + JSONObject resultJsonObj = (JSONObject) jsonObj; + + JSONArray resultArrJsonObj = (JSONArray) jsonParser.parse( resultJsonObj.get("results").toString() ); + JSONObject filteredresultArrJsonObj = (JSONObject) resultArrJsonObj.get(0); + + JSONArray seriesJsonObj = (JSONArray) jsonParser.parse( filteredresultArrJsonObj.get("series").toString() ); + JSONObject filteredSeriesJsonObj = (JSONObject) seriesJsonObj.get(0); + + JSONArray hostStrJsonObjs = (JSONArray) jsonParser.parse( filteredSeriesJsonObj.get("values").toString() ); + + JSONArray returnJsonArray = new JSONArray(); + for (int i = 0; i < hostStrJsonObjs.size(); i++) { + JSONArray hostStrArr = (JSONArray) hostStrJsonObjs.get(i); + logger.info(hostStrArr.get(1).toString()); + returnJsonArray.add(hostStrArr.get(1).toString()); + } + + return returnJsonArray; + } } Index: web-module/src/main/resources/egovframework/egovProps/globals.properties =================================================================== diff -u -rfdf914ee43e64db758ebff17b82063a9504d121e -r01b0a37c18e4c4f324b697ed56787e9a4c06ae7d --- web-module/src/main/resources/egovframework/egovProps/globals.properties (.../globals.properties) (revision fdf914ee43e64db758ebff17b82063a9504d121e) +++ web-module/src/main/resources/egovframework/egovProps/globals.properties (.../globals.properties) (revision 01b0a37c18e4c4f324b697ed56787e9a4c06ae7d) @@ -57,4 +57,7 @@ allinone.monitoring.filebeatindex = ${allinone.monitoring.filebeatindex} allinone.monitoring.packetbeatindex = ${allinone.monitoring.packetbeatindex} allinone.monitoring.topbeatindex = ${allinone.monitoring.topbeatindex} -allinone.monitoring.apmindex = ${allinone.monitoring.apmindex} \ No newline at end of file +allinone.monitoring.apmindex = ${allinone.monitoring.apmindex} + +allinone.monitoring.influx.url = ${allinone.monitoring.influx.url} +allinone.monitoring.influx.query = ${allinone.monitoring.influx.query} \ No newline at end of file Index: web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java =================================================================== diff -u -r9fadf60d728e3c03ff2588003f7f93296f04862f -r01b0a37c18e4c4f324b697ed56787e9a4c06ae7d --- web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java (.../Java8LambdaTest.java) (revision 9fadf60d728e3c03ff2588003f7f93296f04862f) +++ web-module/src/test/java/egovframework/com/ext/jstree/support/util/Java8LambdaTest.java (.../Java8LambdaTest.java) (revision 01b0a37c18e4c4f324b697ed56787e9a4c06ae7d) @@ -186,7 +186,7 @@ } @Test - public void jsonObjectTest() throws ParseException { + public void getJsonObjectFromELKTest() throws ParseException { String orgStr = "{\n" + " \"took\": 3590,\n" + " \"timed_out\": false,\n" + @@ -254,4 +254,99 @@ logger.info("list size = " + deviceListDTOs.size()); } + + @Test + public void getJsonObjectFromInfluxDBTest() throws ParseException { + String orgStr = "{\n" + + " \"results\": [\n" + + " {\n" + + " \"statement_id\": 0,\n" + + " \"series\": [\n" + + " {\n" + + " \"name\": \"counter\",\n" + + " \"columns\": [\n" + + " \"key\",\n" + + " \"value\"\n" + + " ],\n" + + " \"values\": [\n" + + " [\n" + + " \"obj\",\n" + + " \"/16679af642a5/testwww313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/5d6951d245a1/testwww313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/6d6ea7e0b0f9/testwww313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/9eb75e7e6e3e/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/DELLR710-SERVER/dockerTomcat\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/a6bc99072812/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/cf91e7a17560/testwww313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/ef7ac7c4c30b/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/ff3377c71608/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/jstree-backend-5b5746d7cc-9npd2/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/jstree-backend-5bdb8776bb-5lklt/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/jstree-backend-5bdb8776bb-kqjmg/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/jstree-backend-5c6c68b8ff-m6rrp/www313cokr\"\n" + + " ],\n" + + " [\n" + + " \"obj\",\n" + + " \"/jstree-backend-654b68476c-jrtpg/www313cokr\"\n" + + " ]\n" + + " ]\n" + + " }\n" + + " ]\n" + + " }\n" + + " ]\n" + + "}"; + JSONParser jsonParser = new JSONParser(); + Object jsonObj = jsonParser.parse( orgStr ); + JSONObject resultJsonObj = (JSONObject) jsonObj; + + JSONArray resultArrJsonObj = (JSONArray) jsonParser.parse( resultJsonObj.get("results").toString() ); + JSONObject filteredresultArrJsonObj = (JSONObject) resultArrJsonObj.get(0); + + JSONArray seriesJsonObj = (JSONArray) jsonParser.parse( filteredresultArrJsonObj.get("series").toString() ); + JSONObject filteredSeriesJsonObj = (JSONObject) seriesJsonObj.get(0); + + JSONArray hostStrJsonObjs = (JSONArray) jsonParser.parse( filteredSeriesJsonObj.get("values").toString() ); + + for (int i = 0; i < hostStrJsonObjs.size(); i++) { + JSONArray hostStrArr = (JSONArray) hostStrJsonObjs.get(i); + logger.info(hostStrArr.get(1).toString()); + } + + } }