public void testCopy() { TagMap tags = new TagMap(); tags.put("tagkey", "tagval"); MetricMap metrics = new MetricMap(); metrics.put("metrickey", 123.4); OutputRecord r = new OutputRecord(tags, metrics); assertEquals(tags, r.getTagsCopy()); assertNotSame(tags, r.getTagsCopy()); assertEquals(metrics, r.getMetricsCopy()); assertNotSame(metrics, r.getMetricsCopy()); } }
/** * Emits a metrics record to a file. */ public void emitRecord(String contextName, String recordName, OutputRecord outRec) { writer.print(contextName); writer.print("."); writer.print(recordName); String separator = ": "; for (String tagName : outRec.getTagNames()) { writer.print(separator); separator = ", "; writer.print(tagName); writer.print("="); writer.print(outRec.getTag(tagName)); } for (String metricName : outRec.getMetricNames()) { writer.print(separator); separator = ", "; writer.print(metricName); writer.print("="); writer.print(outRec.getMetric(metricName)); } writer.println(); }
public void processMetricsRecord(OutputRecord outRec) { for (String metricName : outRec.getMetricNames()) { Number metricValue = outRec.getMetric(metricName); metrics.put(metricName, metricValue); } }
public void testTagsMetricsPair() throws IOException { TagsMetricsPair pair = new TagsMetricsPair(outputRecord.getTagsCopy(), outputRecord.getMetricsCopy()); String s = JSON.toString(pair); assertEquals( "[{\"testTag1\":\"testTagValue1\",\"testTag2\":\"testTagValue2\"},"+ "{\"testMetric1\":1,\"testMetric2\":33}]", s); }
sb.append('.'); if (contextName.equals("jvm") && outRec.getTag("processName") != null) { sb.append(outRec.getTag("processName")); sb.append('.'); for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); if (type != null) {
/** * Retrieves all the records managed by this MetricsContext. * Useful for monitoring systems that are polling-based. * @return A non-null collection of all monitoring records. */ public synchronized Map<String, Collection<OutputRecord>> getAllRecords() { Map<String, Collection<OutputRecord>> out = new TreeMap<String, Collection<OutputRecord>>(); for (Map.Entry<String,RecordMap> recordEntry : bufferedData.entrySet()) { RecordMap recordMap = recordEntry.getValue(); synchronized (recordMap) { List<OutputRecord> records = new ArrayList<OutputRecord>(); Set<Entry<TagMap, MetricMap>> entrySet = recordMap.entrySet(); for (Entry<TagMap, MetricMap> entry : entrySet) { OutputRecord outRec = new OutputRecord(entry.getKey(), entry.getValue()); records.add(outRec); } out.put(recordEntry.getKey(), records); } } return out; }
sb.append('.'); if (contextName.equals("jvm") && outRec.getTag("processName") != null) { sb.append(outRec.getTag("processName")); sb.append('.'); for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); if (type != null) {
/** * Collects all metric data, and returns a map: * contextName -> recordName -> [ (tag->tagValue), (metric->metricValue) ]. * The values are either String or Number. The final value is implemented * as a list of TagsMetricsPair. */ Map<String, Map<String, List<TagsMetricsPair>>> makeMap( Collection<MetricsContext> contexts) throws IOException { Map<String, Map<String, List<TagsMetricsPair>>> map = new TreeMap<String, Map<String, List<TagsMetricsPair>>>(); for (MetricsContext context : contexts) { Map<String, List<TagsMetricsPair>> records = new TreeMap<String, List<TagsMetricsPair>>(); map.put(context.getContextName(), records); for (Map.Entry<String, Collection<OutputRecord>> r : context.getAllRecords().entrySet()) { List<TagsMetricsPair> metricsAndTags = new ArrayList<TagsMetricsPair>(); records.put(r.getKey(), metricsAndTags); for (OutputRecord outputRecord : r.getValue()) { TagMap tagMap = outputRecord.getTagsCopy(); MetricMap metricMap = outputRecord.getMetricsCopy(); metricsAndTags.add(new TagsMetricsPair(tagMap, metricMap)); } } } return map; }
/** * Retrieves all the records managed by this MetricsContext. * Useful for monitoring systems that are polling-based. * @return A non-null collection of all monitoring records. */ public synchronized Map<String, Collection<OutputRecord>> getAllRecords() { Map<String, Collection<OutputRecord>> out = new TreeMap<String, Collection<OutputRecord>>(); for (Map.Entry<String,RecordMap> recordEntry : bufferedData.entrySet()) { RecordMap recordMap = recordEntry.getValue(); synchronized (recordMap) { List<OutputRecord> records = new ArrayList<OutputRecord>(); Set<Entry<TagMap, MetricMap>> entrySet = recordMap.entrySet(); for (Entry<TagMap, MetricMap> entry : entrySet) { OutputRecord outRec = new OutputRecord(entry.getKey(), entry.getValue()); records.add(outRec); } out.put(recordEntry.getKey(), records); } } return out; }
public void emitRecord(String contextName, String recordName, OutputRecord outRec) throws IOException { // emit each metric in turn for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); emitMetric(metricName, type, metric.toString()); } }
@Override public void emitRecord(String contextName, String recordName, OutputRecord outRec) { writer.print(iso8601()); writer.print(" "); writer.print(contextName); writer.print("."); writer.print(recordName); String separator = ": "; for (String tagName : outRec.getTagNames()) { writer.print(separator); separator = ", "; writer.print(tagName); writer.print("="); writer.print(outRec.getTag(tagName)); } for (String metricName : outRec.getMetricNames()) { writer.print(separator); separator = ", "; writer.print(metricName); writer.print("="); writer.print(outRec.getMetric(metricName)); } writer.println(); }
sb.append('.'); if (contextName.equals("jvm") && outRec.getTag("processName") != null) { sb.append(outRec.getTag("processName")); sb.append('.'); for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); if (type != null) {
/** * Collects all metric data, and returns a map: * contextName -> recordName -> [ (tag->tagValue), (metric->metricValue) ]. * The values are either String or Number. The final value is implemented * as a list of TagsMetricsPair. */ Map<String, Map<String, List<TagsMetricsPair>>> makeMap( Collection<MetricsContext> contexts) throws IOException { Map<String, Map<String, List<TagsMetricsPair>>> map = new TreeMap<String, Map<String, List<TagsMetricsPair>>>(); for (MetricsContext context : contexts) { Map<String, List<TagsMetricsPair>> records = new TreeMap<String, List<TagsMetricsPair>>(); map.put(context.getContextName(), records); for (Map.Entry<String, Collection<OutputRecord>> r : context.getAllRecords().entrySet()) { List<TagsMetricsPair> metricsAndTags = new ArrayList<TagsMetricsPair>(); records.put(r.getKey(), metricsAndTags); for (OutputRecord outputRecord : r.getValue()) { TagMap tagMap = outputRecord.getTagsCopy(); MetricMap metricMap = outputRecord.getMetricsCopy(); metricsAndTags.add(new TagsMetricsPair(tagMap, metricMap)); } } } return map; }
public void testCopy() { TagMap tags = new TagMap(); tags.put("tagkey", "tagval"); MetricMap metrics = new MetricMap(); metrics.put("metrickey", 123.4); OutputRecord r = new OutputRecord(tags, metrics); assertEquals(tags, r.getTagsCopy()); assertNotSame(tags, r.getTagsCopy()); assertEquals(metrics, r.getMetricsCopy()); assertNotSame(metrics, r.getMetricsCopy()); } }
/** * Retrieves all the records managed by this MetricsContext. * Useful for monitoring systems that are polling-based. * @return A non-null collection of all monitoring records. */ public synchronized Map<String, Collection<OutputRecord>> getAllRecords() { Map<String, Collection<OutputRecord>> out = new TreeMap<String, Collection<OutputRecord>>(); for (Map.Entry<String,RecordMap> recordEntry : bufferedData.entrySet()) { RecordMap recordMap = recordEntry.getValue(); synchronized (recordMap) { List<OutputRecord> records = new ArrayList<OutputRecord>(); Set<Entry<TagMap, MetricMap>> entrySet = recordMap.entrySet(); for (Entry<TagMap, MetricMap> entry : entrySet) { OutputRecord outRec = new OutputRecord(entry.getKey(), entry.getValue()); records.add(outRec); } out.put(recordEntry.getKey(), records); } } return out; }
public void emitRecord(String contextName, String recordName, OutputRecord outRec) throws IOException { // Setup so that the records have the proper leader names so they are // unambiguous at the ganglia level, and this prevents a lot of rework StringBuilder sb = new StringBuilder(); sb.append(contextName); sb.append('.'); sb.append(recordName); sb.append('.'); int sbBaseLen = sb.length(); // emit each metric in turn for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); if (type != null) { sb.append(metricName); emitMetric(sb.toString(), type, metric.toString()); sb.setLength(sbBaseLen); } else { LOG.warn("Unknown metrics type: " + metric.getClass()); } } }
writer.print(recordName); String separator = ": "; for (String tagName : outRec.getTagNames()) { writer.print(separator); separator = ", "; writer.print(tagName); writer.print("="); writer.print(outRec.getTag(tagName)); for (String metricName : outRec.getMetricNames()) { writer.print(separator); separator = ", "; writer.print(metricName); writer.print("="); writer.print(outRec.getMetric(metricName));
sb.append('.'); if (contextName.equals("jvm") && outRec.getTag("processName") != null) { sb.append(outRec.getTag("processName")); sb.append('.'); for (String metricName : outRec.getMetricNames()) { Object metric = outRec.getMetric(metricName); String type = typeTable.get(metric.getClass()); if (type != null) {
/** * Collects all metric data, and returns a map: * contextName -> recordName -> [ (tag->tagValue), (metric->metricValue) ]. * The values are either String or Number. The final value is implemented * as a list of TagsMetricsPair. */ Map<String, Map<String, List<TagsMetricsPair>>> makeMap( Collection<MetricsContext> contexts) throws IOException { Map<String, Map<String, List<TagsMetricsPair>>> map = new TreeMap<String, Map<String, List<TagsMetricsPair>>>(); for (MetricsContext context : contexts) { Map<String, List<TagsMetricsPair>> records = new TreeMap<String, List<TagsMetricsPair>>(); map.put(context.getContextName(), records); for (Map.Entry<String, Collection<OutputRecord>> r : context.getAllRecords().entrySet()) { List<TagsMetricsPair> metricsAndTags = new ArrayList<TagsMetricsPair>(); records.put(r.getKey(), metricsAndTags); for (OutputRecord outputRecord : r.getValue()) { TagMap tagMap = outputRecord.getTagsCopy(); MetricMap metricMap = outputRecord.getMetricsCopy(); metricsAndTags.add(new TagsMetricsPair(tagMap, metricMap)); } } } return map; }
public void testCopy() { TagMap tags = new TagMap(); tags.put("tagkey", "tagval"); MetricMap metrics = new MetricMap(); metrics.put("metrickey", 123.4); OutputRecord r = new OutputRecord(tags, metrics); assertEquals(tags, r.getTagsCopy()); assertNotSame(tags, r.getTagsCopy()); assertEquals(metrics, r.getMetricsCopy()); assertNotSame(metrics, r.getMetricsCopy()); } }