@Test public void correctFormatIsSentToGraphite() throws IOException { WriterBasedOutputWriter outputWriter = new GraphiteWriter2(ImmutableList.<String>of(), "servers"); StringWriter writer = new StringWriter(); outputWriter.write(writer, dummyServer(), dummyQuery(), dummyResults()); String graphiteLine = writer.toString(); assertThat(graphiteLine) .hasLineCount(1) .startsWith("servers") .contains("example_net_4321") .endsWith(" 10 0\n"); }
@Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + SECONDS.convert(result.getEpoch(), MILLISECONDS) + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } }
GraphiteWriter2 implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + SECONDS.convert(result.getEpoch(), MILLISECONDS) + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } } }
GraphiteWriter2 implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + SECONDS.convert(result.getEpoch(), MILLISECONDS) + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } } GraphiteWriter2(@Nonnull ImmutableList<String> typeNames, @Nullable String rootPrefix); }
GraphiteWriter2 implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + SECONDS.convert(result.getEpoch(), MILLISECONDS) + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } } GraphiteWriter2(@Nonnull ImmutableList<String> typeNames, @Nullable String rootPrefix); @Override void write(
			@Nonnull Writer writer,
			@Nonnull Server server,
			@Nonnull Query query,
			@Nonnull Iterable<Result> results); }
GraphiteWriter2 implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { for (Result result : results) { log.debug("Query result: {}", result); Object value = result.getValue(); if (isValidNumber(value)) { String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix) .replaceAll("[()]", "_") + " " + value.toString() + " " + SECONDS.convert(result.getEpoch(), MILLISECONDS) + "\n"; log.debug("Graphite Message: {}", line); writer.write(line); } else { onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result); } } } GraphiteWriter2(@Nonnull ImmutableList<String> typeNames, @Nullable String rootPrefix); @Override void write(
			@Nonnull Writer writer,
			@Nonnull Server server,
			@Nonnull Query query,
			@Nonnull Iterable<Result> results);  }