@Test public void testGenerateMetricMappingSystemMemoryStats() { System.out.println("metrics mapping for System Memory Stats"); String rawString = "--title=\"System Memory Stats\" --width 565 --height 200 --lower-limit 0 --base=1024 --vertical-label=\"Bytes\" DEF:memavailswap={rrd1}:memAvailSwap:AVERAGE DEF:minMemavailswap={rrd1}:memAvailSwap:MIN DEF:maxMemavailswap={rrd1}:memAvailSwap:MAX DEF:memtotalreal={rrd2}:memTotalReal:AVERAGE DEF:minMemtotalreal={rrd2}:memTotalReal:MIN DEF:maxMemtotalreal={rrd2}:memTotalReal:MAX DEF:memavailreal={rrd3}:memAvailReal:AVERAGE DEF:minMemavailreal={rrd3}:memAvailReal:MIN DEF:maxMemavailreal={rrd3}:memAvailReal:MAX DEF:membuffer={rrd4}:memBuffer:AVERAGE DEF:minMembuffer={rrd4}:memBuffer:MIN DEF:maxMembuffer={rrd4}:memBuffer:MAX DEF:memcached={rrd5}:memCached:AVERAGE DEF:minMemcached={rrd5}:memCached:MIN DEF:maxMemcached={rrd5}:memCached:MAX DEF:memshared={rrd6}:memShared:AVERAGE DEF:minMemshared={rrd6}:memShared:MIN DEF:maxMemshared={rrd6}:memShared:MAX CDEF:memavailswapBytes=memavailswap,1024,* CDEF:minMemavailswapBytes=minMemavailswap,1024,* CDEF:maxMemavailswapBytes=maxMemavailswap,1024,* CDEF:memtotalrealBytes=memtotalreal,1024,* CDEF:minMemtotalrealBytes=minMemtotalreal,1024,* CDEF:maxMemtotalrealBytes=maxMemtotalreal,1024,* CDEF:memavailrealBytes=memavailreal,1024,* CDEF:minMemavailrealBytes=minMemavailreal,1024,* CDEF:maxMemavailrealBytes=maxMemavailreal,1024,* CDEF:membufferBytes=membuffer,1024,* CDEF:minMembufferBytes=minMembuffer,1024,* CDEF:maxMembufferBytes=maxMembuffer,1024,* CDEF:memcachedBytes=memcached,1024,* CDEF:minMemcachedBytes=minMemcached,1024,* CDEF:maxMemcachedBytes=maxMemcached,1024,* CDEF:memsharedBytes=memshared,UN,0,memshared,IF,1024,* CDEF:minMemsharedBytes=minMemshared,UN,0,minMemshared,IF,1024,* CDEF:maxMemsharedBytes=maxMemshared,UN,0,maxMemshared,IF,1024,* CDEF:usedBytes=memtotalrealBytes,membufferBytes,-,memcachedBytes,-,memsharedBytes,-,memavailrealBytes,- CDEF:minUsedBytes=minMemtotalrealBytes,minMembufferBytes,-,minMemcachedBytes,-,minMemsharedBytes,-,minMemavailrealBytes,- CDEF:maxUsedBytes=maxMemtotalrealBytes,maxMembufferBytes,-,maxMemcachedBytes,-,maxMemsharedBytes,-,maxMemavailrealBytes,- AREA:usedBytes#dd4400:\"Used (Other)\" GPRINT:usedBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:usedBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:usedBytes:MAX:\"Max \\: %8.2lf %s\\n\" STACK:membufferBytes#00ffff:\"IO Buff Ram \" GPRINT:membufferBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:membufferBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:membufferBytes:MAX:\"Max \\: %8.2lf %s\\n\" STACK:memsharedBytes#000a44:\"Shared Mem \" GPRINT:memsharedBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:memsharedBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:memsharedBytes:MAX:\"Max \\: %8.2lf %s\\n\" STACK:memcachedBytes#00aa00:\"Filesystem Cache\" GPRINT:memcachedBytes:AVERAGE:\"Avg \\: %8.2lf %s\" GPRINT:memcachedBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:memcachedBytes:MAX:\"Max \\: %8.2lf %s\\n\" STACK:memavailrealBytes#00ff00:\"Avail Real Mem\" GPRINT:memavailrealBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:memavailrealBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:memavailrealBytes:MAX:\"Max \\: %8.2lf %s\\n\" STACK:memavailswapBytes#ff0000:\"Total Swap \" GPRINT:memavailswapBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:memavailswapBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:memavailswapBytes:MAX:\"Max \\: %8.2lf %s\\n\" LINE2:memtotalrealBytes#0000ff:\"Total Real Mem\" GPRINT:memtotalrealBytes:AVERAGE:\" Avg \\: %8.2lf %s\" GPRINT:memtotalrealBytes:MIN:\"Min \\: %8.2lf %s\" GPRINT:memtotalrealBytes:MAX:\"Max \\: %8.2lf %s\\n\""; String expectedResult = "'.1.3.6.1.4.1.2021.4.4.0': '{rrd1}:memAvailSwap', \n" + "'.1.3.6.1.4.1.2021.4.5.0': '{rrd2}:memTotalReal', \n" + "'.1.3.6.1.4.1.2021.4.6.0': '{rrd3}:memAvailReal', \n" + "'.1.3.6.1.4.1.2021.4.14.0': '{rrd4}:memBuffer', \n" + "'.1.3.6.1.4.1.2021.4.15.0': '{rrd5}:memCached', \n" + "'.1.3.6.1.4.1.2021.4.13.0': '{rrd6}:memShared'"; Map<String, String> rrdGraphAttributesToMetricIds = new LinkedHashMap<String, String>(); rrdGraphAttributesToMetricIds.put("memAvailSwap", ".1.3.6.1.4.1.2021.4.4.0"); rrdGraphAttributesToMetricIds.put("memTotalReal", ".1.3.6.1.4.1.2021.4.5.0"); rrdGraphAttributesToMetricIds.put("memAvailReal", ".1.3.6.1.4.1.2021.4.6.0"); rrdGraphAttributesToMetricIds.put("memBuffer", ".1.3.6.1.4.1.2021.4.14.0"); rrdGraphAttributesToMetricIds.put("memCached", ".1.3.6.1.4.1.2021.4.15.0"); rrdGraphAttributesToMetricIds.put("memShared", ".1.3.6.1.4.1.2021.4.13.0"); String mappingResult = nrtHelper.generateJsMappingObject(rawString, rrdGraphAttributesToMetricIds); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.4.0")); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.5.0")); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.6.0")); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.14.0")); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.15.0")); assertTrue(mappingResult.contains(".1.3.6.1.4.1.2021.4.13.0")); assertTrue(mappingResult.contains("{rrd1}:memAvailSwap")); assertTrue(mappingResult.contains("{rrd2}:memTotalReal")); assertTrue(mappingResult.contains("{rrd3}:memAvailReal")); assertTrue(mappingResult.contains("{rrd4}:memBuffer")); assertTrue(mappingResult.contains("{rrd5}:memCached")); assertTrue(mappingResult.contains("{rrd6}:memShared")); assertEquals(expectedResult, mappingResult); }
public String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds) { final StringBuilder stringBuilder = new StringBuilder(); final String command = rrdCommand; final Pattern pattern = Pattern.compile("DEF:.*?=(\\{.*?\\}):(.*?):"); final Matcher matcher = pattern.matcher(command); final Map<String, String> rrdFileMapping = new HashMap<String, String>(); while (matcher.find()) { rrdFileMapping.put(matcher.group(2), matcher.group(1)); } for (final Map.Entry<String,String> entry : rrdGraphAttributesToMetricIds.entrySet()) { final String row = String.format("'%s': '%s:%s', \n", entry.getValue(), rrdFileMapping.get(entry.getKey()), entry.getKey()); stringBuilder.append(row); } return stringBuilder.toString().substring(0,stringBuilder.toString().length() - ", \n".length()); }
NrtHelper { public String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds) { final StringBuilder stringBuilder = new StringBuilder(); final String command = rrdCommand; final Pattern pattern = Pattern.compile("DEF:.*?=(\\{.*?\\}):(.*?):"); final Matcher matcher = pattern.matcher(command); final Map<String, String> rrdFileMapping = new HashMap<String, String>(); while (matcher.find()) { rrdFileMapping.put(matcher.group(2), matcher.group(1)); } for (final Map.Entry<String,String> entry : rrdGraphAttributesToMetricIds.entrySet()) { final String row = String.format("'%s': '%s:%s', \n", entry.getValue(), rrdFileMapping.get(entry.getKey()), entry.getKey()); stringBuilder.append(row); } return stringBuilder.toString().substring(0,stringBuilder.toString().length() - ", \n".length()); } }
NrtHelper { public String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds) { final StringBuilder stringBuilder = new StringBuilder(); final String command = rrdCommand; final Pattern pattern = Pattern.compile("DEF:.*?=(\\{.*?\\}):(.*?):"); final Matcher matcher = pattern.matcher(command); final Map<String, String> rrdFileMapping = new HashMap<String, String>(); while (matcher.find()) { rrdFileMapping.put(matcher.group(2), matcher.group(1)); } for (final Map.Entry<String,String> entry : rrdGraphAttributesToMetricIds.entrySet()) { final String row = String.format("'%s': '%s:%s', \n", entry.getValue(), rrdFileMapping.get(entry.getKey()), entry.getKey()); stringBuilder.append(row); } return stringBuilder.toString().substring(0,stringBuilder.toString().length() - ", \n".length()); }  }
NrtHelper { public String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds) { final StringBuilder stringBuilder = new StringBuilder(); final String command = rrdCommand; final Pattern pattern = Pattern.compile("DEF:.*?=(\\{.*?\\}):(.*?):"); final Matcher matcher = pattern.matcher(command); final Map<String, String> rrdFileMapping = new HashMap<String, String>(); while (matcher.find()) { rrdFileMapping.put(matcher.group(2), matcher.group(1)); } for (final Map.Entry<String,String> entry : rrdGraphAttributesToMetricIds.entrySet()) { final String row = String.format("'%s': '%s:%s', \n", entry.getValue(), rrdFileMapping.get(entry.getKey()), entry.getKey()); stringBuilder.append(row); } return stringBuilder.toString().substring(0,stringBuilder.toString().length() - ", \n".length()); }  String cleanUpRrdGraphStringForWebUi(final PrefabGraph prefabGraph, final Map<String,String> externalPropertyAttributes, final Map<String,String> stringPropertyAttributes); String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds); }
NrtHelper { public String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds) { final StringBuilder stringBuilder = new StringBuilder(); final String command = rrdCommand; final Pattern pattern = Pattern.compile("DEF:.*?=(\\{.*?\\}):(.*?):"); final Matcher matcher = pattern.matcher(command); final Map<String, String> rrdFileMapping = new HashMap<String, String>(); while (matcher.find()) { rrdFileMapping.put(matcher.group(2), matcher.group(1)); } for (final Map.Entry<String,String> entry : rrdGraphAttributesToMetricIds.entrySet()) { final String row = String.format("'%s': '%s:%s', \n", entry.getValue(), rrdFileMapping.get(entry.getKey()), entry.getKey()); stringBuilder.append(row); } return stringBuilder.toString().substring(0,stringBuilder.toString().length() - ", \n".length()); }  String cleanUpRrdGraphStringForWebUi(final PrefabGraph prefabGraph, final Map<String,String> externalPropertyAttributes, final Map<String,String> stringPropertyAttributes); String generateJsMappingObject(String rrdCommand, final Map<String, String> rrdGraphAttributesToMetricIds); final static List<String> RRD_KEYWORDS; }