@Test public void hashResultAttribues() throws IOException { StatsDTelegrafWriter w = new StatsDTelegrafWriter(new String[]{StatsDMetricType.COUNTER.getKey()}, ImmutableMap.<String, String>of(), ImmutableSet.<ResultAttribute>of()); w.write(writer, dummyServer(), dummyQuery(), hashResults()); assertThat(writer.toString()).isEqualTo( "MemoryAlias,jmxport=4321,attribute=NonHeapMemoryUsage,resultKey=committed:12345|c\n" + "MemoryAlias,jmxport=4321,attribute=NonHeapMemoryUsage,resultKey=init:23456|c\n" + "MemoryAlias,jmxport=4321,attribute=NonHeapMemoryUsage,resultKey=used:45678|c\n"); }
@Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { int resultIndex = -1; for (Result result : results) { resultIndex++; String bucketType = getBucketType(resultIndex); String attributeName = result.getAttributeName(); List<String> resultTagList = new ArrayList<>(); resultTagList.add(",jmxport=" + server.getPort()); resultTagList.add("attribute=" + attributeName); if (isNotValidValue(result.getValue())) { log.debug("Skipping message key[{}] with value: {}.", result.getAttributeName(), result.getValue()); continue; } List<String> tagList = new ArrayList(resultTagList); if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result)); } for (Map.Entry e : tags.entrySet()) { tagList.add(e.getKey() + "=" + e.getValue()); } Number actualValue = computeActualValue(result.getValue()); StringBuilder sb = new StringBuilder(result.getKeyAlias()) .append(StringUtils.join(tagList, ",")) .append(":").append(actualValue) .append("|").append(bucketType).append("\n"); String output = sb.toString(); if( actualValue.floatValue() < 0 && !StatsDMetricType.GAUGE.getKey().equals(bucketType) ) { log.debug("Negative values are only supported for gauges, not sending: {}.", output); } else{ log.debug(output); writer.write(output); } } }
StatsDTelegrafWriter implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { int resultIndex = -1; for (Result result : results) { resultIndex++; String bucketType = getBucketType(resultIndex); String attributeName = result.getAttributeName(); List<String> resultTagList = new ArrayList<>(); resultTagList.add(",jmxport=" + server.getPort()); resultTagList.add("attribute=" + attributeName); if (isNotValidValue(result.getValue())) { log.debug("Skipping message key[{}] with value: {}.", result.getAttributeName(), result.getValue()); continue; } List<String> tagList = new ArrayList(resultTagList); if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result)); } for (Map.Entry e : tags.entrySet()) { tagList.add(e.getKey() + "=" + e.getValue()); } Number actualValue = computeActualValue(result.getValue()); StringBuilder sb = new StringBuilder(result.getKeyAlias()) .append(StringUtils.join(tagList, ",")) .append(":").append(actualValue) .append("|").append(bucketType).append("\n"); String output = sb.toString(); if( actualValue.floatValue() < 0 && !StatsDMetricType.GAUGE.getKey().equals(bucketType) ) { log.debug("Negative values are only supported for gauges, not sending: {}.", output); } else{ log.debug(output); writer.write(output); } } } }
StatsDTelegrafWriter implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { int resultIndex = -1; for (Result result : results) { resultIndex++; String bucketType = getBucketType(resultIndex); String attributeName = result.getAttributeName(); List<String> resultTagList = new ArrayList<>(); resultTagList.add(",jmxport=" + server.getPort()); resultTagList.add("attribute=" + attributeName); if (isNotValidValue(result.getValue())) { log.debug("Skipping message key[{}] with value: {}.", result.getAttributeName(), result.getValue()); continue; } List<String> tagList = new ArrayList(resultTagList); if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result)); } for (Map.Entry e : tags.entrySet()) { tagList.add(e.getKey() + "=" + e.getValue()); } Number actualValue = computeActualValue(result.getValue()); StringBuilder sb = new StringBuilder(result.getKeyAlias()) .append(StringUtils.join(tagList, ",")) .append(":").append(actualValue) .append("|").append(bucketType).append("\n"); String output = sb.toString(); if( actualValue.floatValue() < 0 && !StatsDMetricType.GAUGE.getKey().equals(bucketType) ) { log.debug("Negative values are only supported for gauges, not sending: {}.", output); } else{ log.debug(output); writer.write(output); } } } StatsDTelegrafWriter(String[] bucketTypes, ImmutableMap<String, String> tags, ImmutableSet<ResultAttribute> resultAttributesToWriteAsTags); }
StatsDTelegrafWriter implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { int resultIndex = -1; for (Result result : results) { resultIndex++; String bucketType = getBucketType(resultIndex); String attributeName = result.getAttributeName(); List<String> resultTagList = new ArrayList<>(); resultTagList.add(",jmxport=" + server.getPort()); resultTagList.add("attribute=" + attributeName); if (isNotValidValue(result.getValue())) { log.debug("Skipping message key[{}] with value: {}.", result.getAttributeName(), result.getValue()); continue; } List<String> tagList = new ArrayList(resultTagList); if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result)); } for (Map.Entry e : tags.entrySet()) { tagList.add(e.getKey() + "=" + e.getValue()); } Number actualValue = computeActualValue(result.getValue()); StringBuilder sb = new StringBuilder(result.getKeyAlias()) .append(StringUtils.join(tagList, ",")) .append(":").append(actualValue) .append("|").append(bucketType).append("\n"); String output = sb.toString(); if( actualValue.floatValue() < 0 && !StatsDMetricType.GAUGE.getKey().equals(bucketType) ) { log.debug("Negative values are only supported for gauges, not sending: {}.", output); } else{ log.debug(output); writer.write(output); } } } StatsDTelegrafWriter(String[] bucketTypes, ImmutableMap<String, String> tags, ImmutableSet<ResultAttribute> resultAttributesToWriteAsTags); @Override void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results); }
StatsDTelegrafWriter implements WriterBasedOutputWriter { @Override public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { int resultIndex = -1; for (Result result : results) { resultIndex++; String bucketType = getBucketType(resultIndex); String attributeName = result.getAttributeName(); List<String> resultTagList = new ArrayList<>(); resultTagList.add(",jmxport=" + server.getPort()); resultTagList.add("attribute=" + attributeName); if (isNotValidValue(result.getValue())) { log.debug("Skipping message key[{}] with value: {}.", result.getAttributeName(), result.getValue()); continue; } List<String> tagList = new ArrayList(resultTagList); if( !result.getValuePath().isEmpty() ){ tagList.add("resultKey="+ KeyUtils.getValuePathString(result)); } for (Map.Entry e : tags.entrySet()) { tagList.add(e.getKey() + "=" + e.getValue()); } Number actualValue = computeActualValue(result.getValue()); StringBuilder sb = new StringBuilder(result.getKeyAlias()) .append(StringUtils.join(tagList, ",")) .append(":").append(actualValue) .append("|").append(bucketType).append("\n"); String output = sb.toString(); if( actualValue.floatValue() < 0 && !StatsDMetricType.GAUGE.getKey().equals(bucketType) ) { log.debug("Negative values are only supported for gauges, not sending: {}.", output); } else{ log.debug(output); writer.write(output); } } } StatsDTelegrafWriter(String[] bucketTypes, ImmutableMap<String, String> tags, ImmutableSet<ResultAttribute> resultAttributesToWriteAsTags); @Override void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results);  }