@Test public void testGenerateMetricMappingTcpOpenConnections() { System.out.println("metrics mapping for TCP Open Connections"); String rawString = "--title=\"TCP Open Connections\" --vertical-label=\"TCP Opens Per Second\" DEF:actOpen={rrd1}:tcpActiveOpens:AVERAGE DEF:minActOpen={rrd1}:tcpActiveOpens:MIN DEF:maxActOpen={rrd1}:tcpActiveOpens:MAX DEF:passOpen={rrd2}:tcpPassiveOpens:AVERAGE DEF:minPassOpen={rrd2}:tcpPassiveOpens:MIN DEF:maxPassOpen={rrd2}:tcpPassiveOpens:MAX CDEF:negActOpen=0,actOpen,- AREA:passOpen#00ff00:\"In (Passive)\" GPRINT:passOpen:AVERAGE:\"Avg \\: %8.2lf %s\" GPRINT:passOpen:MIN:\"Min \\: %8.2lf %s\" GPRINT:passOpen:MAX:\"Max \\: %8.2lf %s\\n\" AREA:negActOpen#0000ff:\"Out (Active)\" GPRINT:actOpen:AVERAGE:\"Avg \\: %8.2lf %s\" GPRINT:actOpen:MIN:\"Min \\: %8.2lf %s\" GPRINT:actOpen:MAX:\"Max \\: %8.2lf %s\\n\""; String expectedResult = "'.1.3.6.1.2.1.6.5.0': '{rrd1}:tcpActiveOpens', \n'.1.3.6.1.2.1.6.6.0': '{rrd2}:tcpPassiveOpens'"; Map<String, String> rrdGraphAttributesToMetricIds = new LinkedHashMap<String, String>(); rrdGraphAttributesToMetricIds.put("tcpActiveOpens", ".1.3.6.1.2.1.6.5.0"); rrdGraphAttributesToMetricIds.put("tcpPassiveOpens", ".1.3.6.1.2.1.6.6.0"); String mappingResult = nrtHelper.generateJsMappingObject(rawString, rrdGraphAttributesToMetricIds); assertTrue(mappingResult.contains(".1.3.6.1.2.1.6.5.0")); assertTrue(mappingResult.contains(".1.3.6.1.2.1.6.6.0")); assertTrue(mappingResult.contains("{rrd1}:tcpActiveOpens")); assertTrue(mappingResult.contains("{rrd2}:tcpPassiveOpens")); 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; }