diff options
author | 2019-01-29 00:37:36 +0530 | |
---|---|---|
committer | 2019-01-29 00:54:18 +0530 | |
commit | c51c2a71c930df4ccbb87492f0450aa7db740ebe (patch) | |
tree | a4ec7542bf0b3585dd94fbb6468ce6a95ffa49d0 /veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java | |
parent | 493ed75799223784bdd6f9363d3bc4d189ddb370 (diff) |
VES 7.1 JAVA LIB-Agent Enhancements
HB-Fault-Measurement-Syslog-2Collector enhancements
Issue-ID: VNFSDK-362
Change-Id: I4db391ce8dbc763021ba15f6335d2df1e0b10e40
Signed-off-by: SrikanthN <sn00469487@techmahindra.com>
Diffstat (limited to 'veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java')
-rw-r--r-- | veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java | 744 |
1 files changed, 483 insertions, 261 deletions
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java index 38c517a..9fa537e 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java @@ -24,352 +24,574 @@ package evel_javalibrary.att.com.loadbalance; import java.io.BufferedReader; -import java.io.File; + +import java.io.FileReader; +import java.io.IOException; import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.file.Files; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.log4j.Level; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import evel_javalibrary.att.com.AgentMain; import evel_javalibrary.att.com.EvelBatch; import evel_javalibrary.att.com.EvelScalingMeasurement; public class MeasureData extends Thread{ - static HashMap<String, String> hm = new HashMap<>(); - static HashMap<String, String> vpp_metrics = new HashMap<>(); - static HashMap<String, String> common_meas = new HashMap<>(); - - static int bytes_in_this_round; - static int bytes_out_this_round; - static int packets_in_this_round; - static int packets_out_this_round; + static HashMap<String, String> measConfig = new HashMap<>(); + static String[] resDevice =null; + static String[] tempInitres; + static String[] tempcommandres; + static String[] tempcommandres1; + static HashMap<String, String> vNicPerformanceCommand1 = new HashMap<>(); + static HashMap<String, String> vNicPerformanceArray = new HashMap<>(); + static HashMap<String, String> initTempCommand = new HashMap<>(); + static float bytesInLo; + static float bytesOutLo; + static float packetsInLo; + static float packetsOutLo; - static int gm_event_id = 1; - static String event_id1 = "mvfs"; - static String event_id = "00000000"; - static String event_id2=null; + static float bytesInEnps03; + static float bytesOutEnps03; + static float packetsInEnps03; + static float packetsOutEnps03; - static int request_rate = 0; + static float bytesInDocker0; + static float bytesOutDocker0; + static float packetsInDocker0; + static float packetsOutDocker0; - static long epoch_start = 0; + static int gmEventId = 1; + static String eventId1 = "mvfs"; + static String eventId = "00000000"; + static String eventId2=null; + + static int requestRate = 0; static String linkStart = ""; static int linkCount; Long start_epoch_microsec = 0L; Long last_epoch_microsec = 0L; - - //public static void main(String[] args) { public void run() { - // TODO Auto-generated method stub - //read_config_file(); - read_meas_traffic(); - read_common_config_file(); - read_meas_config_file(); + + try { + + readMeasurementConfig(); + readVppMetrics(resDevice); + } catch (IOException | ParseException e1) { + e1.printStackTrace(); + } + + String[] intFaceMap = resDevice; - HashMap<String, String> intFaceMap = read_interface_config_file(); int numOfInterfaces = 0; - if( !intFaceMap.isEmpty() ) - numOfInterfaces = intFaceMap.size(); + if( intFaceMap != null) + numOfInterfaces = intFaceMap.length; if( numOfInterfaces <= 0) { - System.out.println("ERROR : Didn't find interfacess in config file, exiting thread"); + return; - } + } - System.out.println("MAP values: " + hm.values()); - HashMap last_metrics = read_vpp_metrics(linkStart); + + try { - Thread.sleep(Integer.parseInt(common_meas.get("measurementInterval"))); + Thread.sleep(1000); }catch(Exception e) {} while(true) { - //request_rate = rand()%10000; - request_rate =2; - EvelBatch ebt = new EvelBatch(); - event_id2 = event_id1+ event_id+(gm_event_id++); - EvelScalingMeasurement eveMeas = new EvelScalingMeasurement( Double.parseDouble(common_meas.get("measurementInterval")) , - common_meas.get("eventName"), - event_id2); - - for( String vNic : intFaceMap.keySet() ) { - //System.out.println("INFO:: getting vpp metrics for vNic "+vNic); + HashMap<String, DeviceData> lastMetrics = readVppMetrics(resDevice); + //HashMap<String, DeviceData> currentMetrics = readVppMetrics(resDevice);; + HashMap<String, DeviceData> currentMetrics = lastMetrics; + requestRate =2; + eventId2 = eventId1+ eventId+(gmEventId++); + String measurmentInterval=""; + long milliseconds = 60000; + if(measConfig.get("measurementInterval") == null) { + measurmentInterval = Long.toString(milliseconds); + }else { + measurmentInterval = measConfig.get("measurementInterval"); + } + EvelScalingMeasurement eveMeas = new EvelScalingMeasurement(Integer.parseInt(measurmentInterval) , + measConfig.get("eventName"), + eventId2); - HashMap current_metrics = read_vpp_metrics(vNic); - if( current_metrics.size() !=4 ) { - System.out.println("ERROR:: Did't get vpp metrics for vNic "+vNic); - continue; - } - - if (Integer.parseInt((String) current_metrics.get("bytes_in")) - - Integer.parseInt((String) last_metrics.get("bytes_in")) > 0) { - bytes_in_this_round = Integer.parseInt((String) current_metrics.get("bytes_in")) - - Integer.parseInt((String) last_metrics.get("bytes_in")); - } else { - bytes_in_this_round = 0; - } - - if (Integer.parseInt((String) current_metrics.get("bytes_out")) - - Integer.parseInt((String) last_metrics.get("bytes_out")) > 0) { - bytes_out_this_round = Integer.parseInt((String) current_metrics.get("bytes_out")) - - Integer.parseInt((String) last_metrics.get("bytes_out")); - } else { - bytes_out_this_round = 0; - } + for( String vNic : intFaceMap) { + + int receivedOctetsDeltaLo = 0; + int receivedTotalPacketsDeltaLo = 0; + int transmittedOctetsDeltaLo = 0; + int transmittedTotalPacketsDeltaLo = 0; + + System.out.println("Data Array T0 "+vNic+" , "+ currentMetrics.get(vNic).getT0bytesIn()+" " + + currentMetrics.get(vNic).getT0bytesOut()+" " + + currentMetrics.get(vNic).getT0packetIn()+" " + + currentMetrics.get(vNic).getT0packetOut()); + System.out.println("Data Array T1 "+vNic+" , "+ currentMetrics.get(vNic).getT1Bytesin()+" " + + currentMetrics.get(vNic).getT1Bytesout()+" " + + currentMetrics.get(vNic).getT1Packetsin()+" " + + currentMetrics.get(vNic).getT1Packetsout()); - if (Integer.parseInt((String) current_metrics.get("packets_in")) - - Integer.parseInt((String) last_metrics.get("packets_in")) > 0) { - packets_in_this_round = Integer.parseInt((String) current_metrics.get("packets_in")) - - Integer.parseInt((String) last_metrics.get("packets_in")); - } else { - packets_in_this_round = 0; - } - - if (Integer.parseInt((String) current_metrics.get("packets_out")) - - Integer.parseInt((String) last_metrics.get("packets_out")) > 0) { - packets_out_this_round = Integer.parseInt((String) current_metrics.get("packets_out")) - - Integer.parseInt((String) last_metrics.get("packets_out")); - } else { - packets_out_this_round = 0; - } - event_id2 = event_id1+ (gm_event_id++); - /* EvelScalingMeasurement eveMeas = new EvelScalingMeasurement( Double.parseDouble(hm.get("measurementInterval")) , - hm.get("eventName"), - event_id2); */ - - - EvelScalingMeasurement.MEASUREMENT_NIC_PERFORMANCE vNicPerf = eveMeas.evel_measurement_new_vnic_performance(vNic, "true"); - eveMeas.evel_meas_vnic_performance_add(vNicPerf ); - if( hm.get("eventType")!=null) { - - start_epoch_microsec = last_epoch_microsec; - last_epoch_microsec = System.nanoTime()/1000; - - eveMeas.evel_last_epoch_set(start_epoch_microsec); - eveMeas.evel_start_epoch_set(last_epoch_microsec); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesin())) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesIn()) ) > 0) { + receivedOctetsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesin()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesIn()) )); + } else { + receivedOctetsDeltaLo = 0; + } + + if (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsin())) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetIn()) ) > 0) { + receivedTotalPacketsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsin()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetIn()) )); + } else { + receivedTotalPacketsDeltaLo = 0; + } - eveMeas.evel_measurement_type_set( hm.get("eventType").toString()); - eveMeas.evel_measurement_request_rate_set(request_rate ); - eveMeas.evel_vnic_performance_rx_total_pkt_delta_set(vNicPerf, packets_in_this_round); - eveMeas.evel_vnic_performance_tx_total_pkt_delta_set(vNicPerf, packets_out_this_round); - eveMeas.evel_vnic_performance_rx_octets_delta_set( vNicPerf, bytes_in_this_round); - eveMeas.evel_vnic_performance_tx_octets_delta_set( vNicPerf, bytes_out_this_round); - eveMeas.evel_nfcnamingcode_set(hm.get("nfcNamingCode").toString()); - eveMeas.evel_nfnamingcode_set(hm.get("nfNamingCode").toString()); - eveMeas.evel_reporting_entity_name_set(hm.get("reportingEntityName").toString()); - eveMeas.evel_reporting_entity_id_set(hm.get("reportingEntityId").toString()); - eveMeas.evel_nfVendorName_set(hm.get("nfVendorName").toString()); - eveMeas.evel_header_set_sourceid(true,hm.get("sourceId").toString()); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesout())) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesOut()) ) > 0) { + transmittedOctetsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesout()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesOut()))); + } else { + transmittedOctetsDeltaLo = 0; + } + - eveMeas.evel_header_set_source_name(hm.get("sourceName").toString()); - eveMeas.evel_timeZoneOffset_set(hm.get("timeZoneOffset").toString()); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsout())) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetOut()) ) > 0) { + transmittedTotalPacketsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsout()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetOut()))); + } else { + transmittedTotalPacketsDeltaLo = 0; + } + + EvelScalingMeasurement.MEASUREMENT_NIC_PERFORMANCE vNicPerf = eveMeas.evel_measurement_new_vnic_performance(vNic.replaceAll("^[\"']+|[\"']+$", ""), "true"); + //eveMeas.evel_meas_vnic_performance_add(vNicPerf); + + if( measConfig.get("eventType")!=null) { + String hostName = hostName(); + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + eveMeas.evel_last_epoch_set(start_epoch_microsec); + eveMeas.evel_start_epoch_set(last_epoch_microsec); + eveMeas.evel_measurement_type_set( measConfig.get("eventType").toString()); - + eveMeas.evel_vnic_performance_rx_octets_delta_set( vNicPerf, receivedOctetsDeltaLo); + eveMeas.evel_vnic_performance_rx_total_pkt_delta_set(vNicPerf, receivedTotalPacketsDeltaLo); + eveMeas.evel_vnic_performance_tx_octets_delta_set( vNicPerf, transmittedOctetsDeltaLo); + eveMeas.evel_vnic_performance_tx_total_pkt_delta_set(vNicPerf, transmittedTotalPacketsDeltaLo); + + eveMeas.evel_nfcnamingcode_set(measConfig.get("nfcNamingCode").toString()); + eveMeas.evel_nfnamingcode_set(measConfig.get("nfNamingCode").toString()); + if(measConfig.get("reportingEntityName") == null) { + eveMeas.evel_reporting_entity_name_set(hostName); + }else { + eveMeas.evel_reporting_entity_name_set(measConfig.get("reportingEntityName").toString()); + } + eveMeas.evel_reporting_entity_id_set(measConfig.get("reportingEntityId").toString()); + eveMeas.evel_nfVendorName_set(measConfig.get("nfVendorName").toString()); + eveMeas.evel_header_set_sourceid(true,measConfig.get("sourceId").toString()); + if(measConfig.get("sourceName") == null) { + eveMeas.evel_header_set_source_name(hostName); + }else { + eveMeas.evel_header_set_source_name(measConfig.get("sourceName").toString()); + } + eveMeas.evel_timeZoneOffset_set(measConfig.get("timeZoneOffset").toString()); } - - - try { - Thread.sleep(Integer.parseInt(common_meas.get("measurementInterval"))); - }catch(Exception e) {} - last_metrics = current_metrics; - } - //ebt.addEvent(eveMeas); + } AgentMain.evel_post_event(eveMeas); - System.out.println(" Event sent"); - + boolean continues = true; + long curr = System.currentTimeMillis(); + while(continues) { + try { + Thread.sleep(100); + }catch (Exception e) { + // TODO: handle exception + } + if(System.currentTimeMillis() >= (curr+Integer.parseInt(measurmentInterval))) { + continues = false; + } + + + } } } - - - - public static HashMap<String, String> read_vpp_metrics(String linkStart) { - Process p; - - String s=""; - HashMap<String, String> vpp_metrics_map = new HashMap<>(); - String params[] = {"-f3", "-f11", "-f4", "-f12"}; - try { - Runtime rt = Runtime.getRuntime(); - for(int i=0;i<4;i++) { - String[] command = {"/bin/sh", "-c", "cat /proc/net/dev | grep \""+linkStart+"\" | tr -s \' \' | cut -d\' \' "+params[i]+""}; - Process child = rt.exec(command); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - child.getInputStream())); - - while ((s= reader.readLine()) != null) { - String[] res = s.split(" "); - if( i==0) - vpp_metrics_map.put("bytes_in", res[0]); - if( i==1) - vpp_metrics_map.put("packets_in", res[0]); - if( i==2) - vpp_metrics_map.put("bytes_out", res[0]); - if( i==3) - vpp_metrics_map.put("packets_out", res[0]); - - } - } - - } catch (Exception e) { + private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + private static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + public static String hostName() { + String hostname = "Unknown"; + String uuid = "Unknown"; + try + { + InetAddress addr; + addr = InetAddress.getLocalHost(); + hostname = addr.getHostName(); + } + catch (UnknownHostException ex) + { + } + try{ + Enumeration<NetworkInterface> networks = + NetworkInterface.getNetworkInterfaces(); + while(networks.hasMoreElements()) { + NetworkInterface network = networks.nextElement(); + byte[] mac = network.getHardwareAddress(); + + if(hostname.equalsIgnoreCase("unknown")) + { + Enumeration inetAddrs = network.getInetAddresses(); + while(inetAddrs.hasMoreElements()){ + InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); + if (!inetAddr.isLoopbackAddress()) { + hostname = inetAddr.getHostAddress(); + break; + } + } + } + if (mac != null) { + uuid = bytesToHex(mac); + } + } + } catch (SocketException e) { + // TODO Auto-generated catch block e.printStackTrace(); } - return vpp_metrics_map; + + return hostname; } - public static HashMap<String, String> read_common_config_file() { - - List<String> list = new ArrayList<String>(); - - - hm.put("eventType", ""); - hm.put("nfcNamingCode", ""); - hm.put("nfNamingCode", ""); - hm.put("nfVendorName", ""); - hm.put("reportingEntityId", ""); - hm.put("reportingEntityName", ""); - hm.put("sourceId", ""); - hm.put("sourceName", ""); - hm.put("timeZoneOffset", ""); + public static HashMap<String, String> readMeasurementConfig() throws IOException, ParseException { + JSONParser jsonParser = new JSONParser(); - - - System.out.println("KEYS: " + hm.keySet().size()); - System.out.println("VALUES: " + hm.values()); - try { - // File file = new File("/home/ves/users/admin/temp/fw_common_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_common_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - hm.put(res[0], res[1]); - System.out.println("File reading after split ---" + res[0]); - System.out.println("File reading after split second---" + res[1]); - } - } catch (Exception ex) { - ex.printStackTrace(); + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/meas_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry directPair = null; + String directObject =""; + String[] directres; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + directPair = itr1.next(); + directObject=String.valueOf(directPair); + directres = directObject.split("="); + measConfig.put(directres[0], directres[1]); + } + + String eventName = measConfig.get("eventName").toString(); + JSONArray arrJson = (JSONArray) directParameters.get("tmp_device"); + resDevice = new String[arrJson.size()]; + for(int i = 0; i < arrJson.size(); i++) + resDevice[i] = (String) arrJson.get(i); + + + //tmp_indirectParameters + Map.Entry indirectPair = null; + String indirectObject =""; + String[] indirectres; + Map indirectParameters = ((Map)obj.get("tmp_indirectParameters")); + Iterator<Map.Entry> itr2 = indirectParameters.entrySet().iterator(); + while (itr2.hasNext()) { + indirectPair = itr2.next(); + indirectObject=String.valueOf(indirectPair); + indirectres = indirectObject.split("="); + measConfig.put(indirectres[0], indirectres[1]); + } + + + + //tmp_init + // Map tempInitParameters = ((Map)indirectParameters.get("tmp_init")); + + //tmp_init + Map.Entry tempcommandPair = null; + String tempcommandObject =""; + Map tempcommandParameters = ((Map)indirectParameters.get("tmp_init")); + Iterator<Map.Entry> itr3 = tempcommandParameters.entrySet().iterator(); + while (itr3.hasNext()) { + tempcommandPair = itr3.next(); + tempcommandObject=String.valueOf(tempcommandPair); + tempcommandres = tempcommandObject.split("="); + initTempCommand.put(tempcommandres[0], tempcommandres[1]); + } + + //tmp_command1 + Map.Entry tempcommand1Pair = null; + String tempcommand1Object =""; + JSONArray nicPerfomenceArray = (JSONArray) indirectParameters.get("vNicPerformance"); + Map vNic = (Map)nicPerfomenceArray.get(0); + Map perf = ((Map)vNic.get("tmp_vnic_command")); + Iterator<Map.Entry> itr5 = perf.entrySet().iterator(); + while (itr5.hasNext()) { + tempcommand1Pair = itr5.next(); + tempcommand1Object=String.valueOf(tempcommand1Pair); + tempcommandres1 = tempcommand1Object.split("="); + vNicPerformanceCommand1.put(tempcommandres1[0], tempcommandres1[1]); + } + Map.Entry vnicPair = null; + String vnicObject =""; + String[] nicPerfomenceArrayRes; + vNic = (Map)nicPerfomenceArray.get(0); + Iterator<Map.Entry> itr6 = vNic.entrySet().iterator(); + while (itr6.hasNext()) { + vnicPair = itr6.next(); + vnicObject=String.valueOf(vnicPair); + nicPerfomenceArrayRes = vnicObject.split("="); + vNicPerformanceArray.put(nicPerfomenceArrayRes[0], nicPerfomenceArrayRes[1]); + } + + String receivedOctetsDelta = vNicPerformanceArray.get("receivedOctetsDelta"); + + } catch (ClassCastException ex) { + } - System.out.println("KEYS: " + hm.keySet().size()); - System.out.println("VALUES: " + hm.values()); - return hm; + return measConfig; } + + public static HashMap<String, DeviceData> readVppMetrics(String[] linkStart) { + DeviceData mddata = null; new DeviceData(); - public static HashMap<String, String> read_interface_config_file() { - - List<String> list = new ArrayList<String>(); - HashMap<String, String> interface_config = new HashMap<>(); - //interface_config.put("lo", ""); + //tmp_t0 + String t0BytesIn = initTempCommand.get("tmp_t0BytesIn"); + String t0BytesOut = initTempCommand.get("tmp_t0BytesOut"); + String t0PacketsIn = initTempCommand.get("tmp_t0PacketsIn"); + String t0PacketsOut = initTempCommand.get("tmp_t0PacketsOut"); - System.out.println("KEYS: " + interface_config.keySet().size()); - System.out.println("VALUES: " + interface_config.values()); - - try { - //File file = new File("/home/ves/users/admin/temp/fw_interface_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_interface_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - interface_config.put(res[0], res[1]); - } + //tmp_t1 + String t1BytesIn = vNicPerformanceCommand1.get("tmp_t1BytesIn"); + String t1BytesOut = vNicPerformanceCommand1.get("tmp_t1BytesOut").toString(); + String t1PacketsIn = vNicPerformanceCommand1.get("tmp_t1PacketsIn"); + String t1PacketsOut = vNicPerformanceCommand1.get("tmp_t1PacketsOut"); + + + HashMap<String, DeviceData> vppMetrics = new HashMap<>(); + for(int i = 0; i < linkStart.length; i++) { + mddata =new DeviceData(); + String device = linkStart[i]; - linkStart = (String)interface_config.keySet().toArray()[1]; - linkCount = interface_config.keySet().size(); + //t0_ + String replaceInitBytesint0 =""; + if(t0BytesIn.contains("$tmp_device")) { + String repString = t0BytesIn.replace("$tmp_device", device.trim()); + replaceInitBytesint0 = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t0BytesinArray= replaceInitBytesint0.split(","); - } catch (Exception ex) { - ex.printStackTrace(); - } - - return interface_config; - } + String replaceInitBytesout=""; + if(t0BytesOut.contains("$tmp_device")) { + String repString = t0BytesOut.replace("$tmp_device", device.trim()); + replaceInitBytesout = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t0BytesoutArray= replaceInitBytesout.split(","); + + String replaceInitPacketsin =""; + if(t0PacketsIn.contains("$tmp_device")) { + String repString = t0PacketsIn.replace("$tmp_device", device.trim()); + replaceInitPacketsin = repString.replace("sudo", "/bin/sh,-c,"); - - - + } + String[] t0PacketsinArray= replaceInitPacketsin.split(","); + + + String replaceInitPacketsout =""; + if(t0PacketsOut.contains("$tmp_device")) { + String repString = t0PacketsOut.replace("$tmp_device", device.trim()); + replaceInitPacketsout = repString.replace("sudo", "/bin/sh,-c,"); - - public static HashMap<String, String> read_meas_config_file() { + } + String[] t0PacketsoutArray= replaceInitPacketsout.split(","); + + //t1 + String replaceBytesin =""; + if(t1BytesIn.contains("$tmp_device")) { + String repString = t1BytesIn.replace("$tmp_device", device.trim()); + replaceBytesin = repString.replace("sudo", "/bin/sh,-c,"); - List<String> list = new ArrayList<String>(); + } + String[] t1BytesinArray= replaceBytesin.split(","); + + String replaceBytesOut =""; + if(t1BytesOut.contains("$tmp_device")) { + String repString = t1BytesOut.replace("$tmp_device", device.trim()); + replaceBytesOut = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1BytesoutArray = replaceBytesOut.split(","); + + String replacePacketsIn =""; + if(t1PacketsIn.contains("$tmp_device")) { + String repString = t1PacketsIn.replace("$tmp_device", device.trim()); + replacePacketsIn = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1PacketsInArray= replacePacketsIn.split(","); + + String replacePacketsOut =""; + if(t1PacketsOut.contains("$tmp_device")) { + String repString = t1PacketsOut.replace("$tmp_device", device.trim()); + replacePacketsOut = repString.replace("sudo", "/bin/sh,-c,"); - common_meas.put("eventName", "Measurement_vFirewall-AT&T_nicPerformance"); - common_meas.put("measurementInterval", ""); + } + String[] t1PacketsOutArray= replacePacketsOut.split(","); - System.out.println("KEYS: " + common_meas.keySet().size()); - System.out.println("VALUES: " + common_meas.values()); + try { + //t0_Commands run + Runtime rt5 = Runtime.getRuntime(); + Process initBytesint0child = rt5.exec(t0BytesinArray); + BufferedReader readerinitBytesint0 = new BufferedReader(new InputStreamReader( + initBytesint0child.getInputStream())); + String readinitMetrics= readerinitBytesint0.readLine(); + + Runtime rt6 = Runtime.getRuntime(); + Process initBytesoutchild = rt6.exec(t0BytesoutArray); + BufferedReader readerinitBytesout = new BufferedReader(new InputStreamReader( + initBytesoutchild.getInputStream())); + String readinitMetrics2= readerinitBytesout.readLine(); + + + Runtime rt7 = Runtime.getRuntime(); + Process initPacketsinchild = rt7.exec(t0PacketsinArray); + BufferedReader readerinitPacketsin = new BufferedReader(new InputStreamReader( + initPacketsinchild.getInputStream())); + String readinitMetrics3= readerinitPacketsin.readLine(); + + + + Runtime rt8 = Runtime.getRuntime(); + Process initPacketsoutchild = rt8.exec(t0PacketsoutArray); + BufferedReader readerinitPacketsout = new BufferedReader(new InputStreamReader( + initPacketsoutchild.getInputStream())); + String readinitMetrics4= readerinitPacketsout.readLine(); + + - try { - //File file = new File("/home/ves/users/admin/temp/fw_meas_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_meas_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - common_meas.put(res[0], res[1]); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - System.out.println("KEYS: " + common_meas.keySet().size()); - System.out.println("VALUES: " + common_meas.values()); - return common_meas; - } + //t1_Commands run + Thread.sleep(Integer.parseInt(measConfig.get("measurementInterval"))); + Runtime rt1 = Runtime.getRuntime(); + Process bytesinchild = rt1.exec(t1BytesinArray); + // bytesinchild.waitFor(); + BufferedReader readerBytesin = new BufferedReader(new InputStreamReader( + bytesinchild.getInputStream())); + String readMetrics= readerBytesin.readLine(); + + + + Runtime rt2 = Runtime.getRuntime(); + Process bytesoutchild = rt2.exec(t1BytesoutArray); + BufferedReader readerBytesout = new BufferedReader(new InputStreamReader( + bytesoutchild.getInputStream())); + String readMetrics1= readerBytesout.readLine(); + + Runtime rt3 = Runtime.getRuntime(); + Process packetsInchild = rt3.exec(t1PacketsInArray); + BufferedReader readerPacketsIn = new BufferedReader(new InputStreamReader( + packetsInchild.getInputStream())); + String readMetrics2= readerPacketsIn.readLine(); + + Runtime rt4 = Runtime.getRuntime(); + Process packetsOutchild = rt4.exec(t1PacketsOutArray); + BufferedReader readerpacketsOut = new BufferedReader(new InputStreamReader( + packetsOutchild.getInputStream())); + String readMetrics3= readerpacketsOut.readLine(); + + // System.out.println(device+" , T1 command data: "+ readMetrics+"," + readMetrics1+"," + readMetrics2+"," + readMetrics3); + // System.out.println(device+" , T0 command data: "+ readinitMetrics+"," + readinitMetrics2+"," + readinitMetrics3+"," + readinitMetrics4); + + //t1 + mddata.setT1Bytesin(readMetrics); + mddata.setT1Bytesout(readMetrics1); + mddata.setT1Packetsin(readMetrics2); + mddata.setT1Packetsout(readMetrics3); + + //t0 + mddata.setT0bytesIn(readinitMetrics); + mddata.setT0bytesOut(readinitMetrics2); + mddata.setT0packetIn(readinitMetrics3); + mddata.setT0packetOut(readinitMetrics4); + + if(device.equals("enp0s3")) { + vppMetrics.put("enp0s3", mddata); + + }else if(device.equals("lo")) { + vppMetrics.put("lo", mddata); + }else if(device.equals("docker0")) { + vppMetrics.put("docker0", mddata); + } + + }catch (Exception e) { + e.printStackTrace(); + } + } + return vppMetrics; + } - public static HashMap<String, String> read_meas_traffic() { - Process p; - List<String> vpp_params = new ArrayList(); - String s=""; - // HashMap<String, String> vpp_metrics_map = new HashMap<>(); - String params[] = {"-f3", "-f11", "-f4", "-f12"}; + + public static void main(String[] args) { + // TODO Auto-generated method stub + try { -// System.out.println("***********inside read_vpp_metrics"); -// String command = "cat /proc/net/dev | grep \"Receive\" | tr -s \' \' | cut -d\' \' -f3"; - //{"-f3", "-f11", "-f4", "-f12"}; -// String command = "cat /proc/net/dev | grep \""+vnic+"\" "; - for(int i=0;i<4;i++) { - String[] command = {"/bin/sh", "-c", "docker logs vHello | grep -c"}; -// System.out.println("**COMMAND***: "+command); - Process child = Runtime.getRuntime().exec(command); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - child.getInputStream())); - - while ((s= reader.readLine()) != null) { - vpp_params.add(s); - System.out.println("VPP meas_traffic:----" + s); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return vpp_metrics; + AgentMain.evel_initialize("http://127.0.0.1",30000, + null,null, + "will", + "pill", + null, null, null, + "http://127.0.0.1",30001, "will", + "pill", + Level.TRACE); + }catch(Exception e) { + e.printStackTrace(); + return; + } + MeasureData mdataThread = new MeasureData(); + mdataThread.start(); + } + + + } |