@Test public void metricsAreFormattedCorrectly() throws IOException { ZabbixWriter zabbixWriter = new ZabbixWriter(new JsonFactory(), ImmutableList.<String>of()); StringWriter writer = new StringWriter(); zabbixWriter.write(writer, dummyServer(), dummyQuery(), dummyResults()); String json = writer.toString(); assertThatJson(json) .node("request").isEqualTo("sender data"); assertThatJson(json) .node("data").isArray().ofLength(3); assertThatJson(json) .node("data[0].host").isEqualTo("host.example.net") .node("data[0].key").isEqualTo("jmxtrans.MemoryAlias.ObjectPendingFinalizationCount") .node("data[0].value").isEqualTo("\"10\"") .node("data[0].clock").isEqualTo(0); }
@Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("request", "sender data"); g.writeArrayFieldStart("data"); for (Result result : results) { log.debug("Query result: {}", result); String key = "jmxtrans." + KeyUtils.getKeyString(query, result, typeNames); Object value = result.getValue(); g.writeStartObject(); g.writeStringField("host", server.getLabel()); g.writeStringField("key", key); g.writeStringField("value", value.toString()); g.writeNumberField("clock", result.getEpoch() / 1000); g.writeEndObject(); } g.writeEndArray(); g.writeNumberField("clock", System.currentTimeMillis() / 1000); g.writeEndObject(); g.flush(); } }
ZabbixWriter implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("request", "sender data"); g.writeArrayFieldStart("data"); for (Result result : results) { log.debug("Query result: {}", result); String key = "jmxtrans." + KeyUtils.getKeyString(query, result, typeNames); Object value = result.getValue(); g.writeStartObject(); g.writeStringField("host", server.getLabel()); g.writeStringField("key", key); g.writeStringField("value", value.toString()); g.writeNumberField("clock", result.getEpoch() / 1000); g.writeEndObject(); } g.writeEndArray(); g.writeNumberField("clock", System.currentTimeMillis() / 1000); g.writeEndObject(); g.flush(); } } }
ZabbixWriter implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("request", "sender data"); g.writeArrayFieldStart("data"); for (Result result : results) { log.debug("Query result: {}", result); String key = "jmxtrans." + KeyUtils.getKeyString(query, result, typeNames); Object value = result.getValue(); g.writeStartObject(); g.writeStringField("host", server.getLabel()); g.writeStringField("key", key); g.writeStringField("value", value.toString()); g.writeNumberField("clock", result.getEpoch() / 1000); g.writeEndObject(); } g.writeEndArray(); g.writeNumberField("clock", System.currentTimeMillis() / 1000); g.writeEndObject(); g.flush(); } } ZabbixWriter(@Nonnull JsonFactory jsonFactory, @Nonnull ImmutableList<String> typeNames); }
ZabbixWriter implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("request", "sender data"); g.writeArrayFieldStart("data"); for (Result result : results) { log.debug("Query result: {}", result); String key = "jmxtrans." + KeyUtils.getKeyString(query, result, typeNames); Object value = result.getValue(); g.writeStartObject(); g.writeStringField("host", server.getLabel()); g.writeStringField("key", key); g.writeStringField("value", value.toString()); g.writeNumberField("clock", result.getEpoch() / 1000); g.writeEndObject(); } g.writeEndArray(); g.writeNumberField("clock", System.currentTimeMillis() / 1000); g.writeEndObject(); g.flush(); } } ZabbixWriter(@Nonnull JsonFactory jsonFactory, @Nonnull ImmutableList<String> typeNames); @Override void write(
			@Nonnull Writer writer,
			@Nonnull Server server,
			@Nonnull Query query,
			@Nonnull Iterable<Result> results); }
ZabbixWriter implements WriterBasedOutputWriter { @Override public void write( @Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException { try ( JsonGenerator g = jsonFactory.createGenerator(writer); ) { g.useDefaultPrettyPrinter(); g.writeStartObject(); g.writeStringField("request", "sender data"); g.writeArrayFieldStart("data"); for (Result result : results) { log.debug("Query result: {}", result); String key = "jmxtrans." + KeyUtils.getKeyString(query, result, typeNames); Object value = result.getValue(); g.writeStartObject(); g.writeStringField("host", server.getLabel()); g.writeStringField("key", key); g.writeStringField("value", value.toString()); g.writeNumberField("clock", result.getEpoch() / 1000); g.writeEndObject(); } g.writeEndArray(); g.writeNumberField("clock", System.currentTimeMillis() / 1000); g.writeEndObject(); g.flush(); } } ZabbixWriter(@Nonnull JsonFactory jsonFactory, @Nonnull ImmutableList<String> typeNames); @Override void write(
			@Nonnull Writer writer,
			@Nonnull Server server,
			@Nonnull Query query,
			@Nonnull Iterable<Result> results);  }