EventHelper { static void processJVMStatisticsData(String type, JVMStatisticsEventsProtos.JVMStatisticsData event, Map<String, Map<String, Object>> eventMaps) { for (JVMStatisticsEventsProtos.JVMStatisticsData.Section section : event.getSectionList()) { if (section.getName().equals("disk") || section.getName().equals("network")) { for (JVMStatisticsEventsProtos.JVMStatisticsData.Property property : section.getPropertyList()) { String[] device = property.getName().split("_"); if (device.length == 2) { Map<String, Object> eventMap = eventMaps.computeIfAbsent(device[0], s -> EventHelper.initEvent("OS")); eventMap.put(section.getName(), device[0]); eventMap.put(device[1], Double.parseDouble(property.getValue())); } } } else { Map<String, Object> eventMap = eventMaps.computeIfAbsent(type, s -> EventHelper.initEvent(type)); for (JVMStatisticsEventsProtos.JVMStatisticsData.Property property : section.getPropertyList()) { if (!property.getName().isEmpty()) { try { eventMap.put(section.getName() + "_" + property.getName(), Double.parseDouble(property.getValue())); } catch (NumberFormatException nfe) { eventMap.put(section.getName() + "_" + property.getName(), property.getValue()); } } } } } } protected  EventHelper();   }
@Test public void processJVMStatisticsData_should_add_3_hashmap_disk_network_and_jvm() { String disk = "sda"; JVMStatisticsEventsProtos.JVMStatisticsData.Property propertyDisk = JVMStatisticsEventsProtos.JVMStatisticsData.Property .newBuilder() .setName(disk + "_write") .setValue("10000") .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Section sectionDisk = JVMStatisticsEventsProtos.JVMStatisticsData.Section .newBuilder() .setName("disk") .addProperty(propertyDisk) .build(); String network = "enp129s0"; JVMStatisticsEventsProtos.JVMStatisticsData.Property propertyNetwork = JVMStatisticsEventsProtos.JVMStatisticsData.Property .newBuilder() .setName(network + "_rx") .setValue("100000") .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Section sectionNetwork = JVMStatisticsEventsProtos.JVMStatisticsData.Section .newBuilder() .setName("network") .addProperty(propertyNetwork) .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Property propertyOther = JVMStatisticsEventsProtos.JVMStatisticsData.Property .newBuilder() .setName("physical") .setValue("499") .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Section sectionOther1 = JVMStatisticsEventsProtos.JVMStatisticsData.Section .newBuilder() .setName("memory") .addProperty(propertyOther) .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Section sectionOther2 = JVMStatisticsEventsProtos.JVMStatisticsData.Section .newBuilder() .setName("machinecpu") .addProperty(propertyOther) .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Property propertyEmpty = JVMStatisticsEventsProtos.JVMStatisticsData.Property .newBuilder() .setName("") .setValue("") .build(); JVMStatisticsEventsProtos.JVMStatisticsData.Section sectionEmpty = JVMStatisticsEventsProtos.JVMStatisticsData.Section .newBuilder() .setName("class") .addProperty(propertyEmpty) .build(); JVMStatisticsEventsProtos.JVMStatisticsData event = JVMStatisticsEventsProtos.JVMStatisticsData .newBuilder() .addSection(sectionDisk) .addSection(sectionNetwork) .addSection(sectionOther1) .addSection(sectionOther2) .addSection(sectionEmpty) .build(); EventHelper.processJVMStatisticsData(GarmadonSerialization.getTypeName(1001), event, eventMaps); Assert.assertEquals(disk, eventMaps.get(disk).get("disk")); Assert.assertEquals(network, eventMaps.get(network).get("network")); Assert.assertEquals(499.0, eventMaps.get(GarmadonSerialization.getTypeName(1001)).get("memory_physical")); Assert.assertEquals(499.0, eventMaps.get(GarmadonSerialization.getTypeName(1001)).get("machinecpu_physical")); Assert.assertFalse(eventMaps.get(GarmadonSerialization.getTypeName(1001)).containsKey("class_")); }