use of org.influxdb.dto.BatchPoints in project jmxtrans by jmxtrans.
the class InfluxDbWriterTests method emptyCustomTagsDoesntBotherWrite.
@Test
public void emptyCustomTagsDoesntBotherWrite() throws Exception {
InfluxDbWriter writer = getTestInfluxDbWriterWithDefaultSettings();
writer.doWrite(dummyServer(), dummyQuery(), results);
verify(influxDB).write(messageCaptor.capture());
BatchPoints batchPoints = messageCaptor.getValue();
assertThat(batchPoints.getDatabase()).isEqualTo(DATABASE_NAME);
List<Point> points = batchPoints.getPoints();
assertThat(points).hasSize(1);
}
use of org.influxdb.dto.BatchPoints in project camel by apache.
the class InfluxDbProducer method doInsert.
private void doInsert(Exchange exchange, String dataBaseName, String retentionPolicy) throws InvalidPayloadException {
if (!endpoint.isBatch()) {
Point p = exchange.getIn().getMandatoryBody(Point.class);
try {
LOG.debug("Writing point {}", p.lineProtocol());
connection.write(dataBaseName, retentionPolicy, p);
} catch (Exception ex) {
exchange.setException(new CamelInfluxDbException(ex));
}
} else {
BatchPoints batchPoints = exchange.getIn().getMandatoryBody(BatchPoints.class);
try {
LOG.debug("Writing BatchPoints {}", batchPoints.lineProtocol());
connection.write(batchPoints);
} catch (Exception ex) {
exchange.setException(new CamelInfluxDbException(ex));
}
}
}
use of org.influxdb.dto.BatchPoints in project jmxtrans by jmxtrans.
the class InfluxDbWriter method doWrite.
/**
* <p>
* Each {@link Result} is written as a {@link Point} to InfluxDB
* </p>
*
* <p>
* The measurement for the {@link Point} is to {@link Result#getKeyAlias()}
* <p>
* <a href=
* "https://influxdb.com/docs/v0.9/concepts/key_concepts.html#retention-policy">
* The retention policy</a> for the measurement is set to "default" unless
* overridden in settings:
* </p>
*
* <p>
* The write consistency level defaults to "ALL" unless overridden in
* settings:
*
* <ul>
* <li>ALL = Write succeeds only if write reached all cluster members.</li>
* <li>ANY = Write succeeds if write reached any cluster members.</li>
* <li>ONE = Write succeeds if write reached at least one cluster members.
* </li>
* <li>QUORUM = Write succeeds only if write reached a quorum of cluster
* members.</li>
* </ul>
*
* <p>
* The time key for the {@link Point} is set to {@link Result#getEpoch()}
* </p>
*
* <p>
* All {@link Result#getValues()} are written as fields to the {@link Point}
* </p>
*
* <p>
* The following properties from {@link Result} are written as tags to the
* {@link Point} unless overriden in settings:
*
* <ul>
* <li>{@link Result#getAttributeName()}</li>
* <li>{@link Result#getClassName()}</li>
* <li>{@link Result#getObjDomain()}</li>
* <li>{@link Result#getTypeName()}</li>
* </ul>
* <p>
* {@link Server#getHost()} is set as a tag on every {@link Point}
* </p>
*
*/
@Override
public void doWrite(Server server, Query query, Iterable<Result> results) throws Exception {
// Creates only if it doesn't already exist
if (createDatabase)
influxDB.createDatabase(database);
BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database).retentionPolicy(retentionPolicy).tag(TAG_HOSTNAME, server.getSource());
for (Map.Entry<String, String> tag : tags.entrySet()) {
batchPointsBuilder.tag(tag.getKey(), tag.getValue());
}
BatchPoints batchPoints = batchPointsBuilder.consistency(writeConsistency).build();
for (Result result : results) {
HashMap<String, Object> filteredValues = newHashMap(Maps.filterValues(result.getValues(), isNotNaN));
// send the point if filteredValues isn't empty
if (!filteredValues.isEmpty()) {
filteredValues.put("_jmx_port", Integer.parseInt(server.getPort()));
Map<String, String> resultTagsToApply = buildResultTagMap(result);
Point point = Point.measurement(result.getKeyAlias()).time(result.getEpoch(), MILLISECONDS).tag(resultTagsToApply).fields(filteredValues).build();
batchPoints.point(point);
}
}
influxDB.write(batchPoints);
}
use of org.influxdb.dto.BatchPoints in project jmxtrans by jmxtrans.
the class InfluxDbWriterTests method customTagsAreWrittenToDb.
@Test
public void customTagsAreWrittenToDb() throws Exception {
ImmutableMap<String, String> tags = ImmutableMap.of("customTag", "customValue");
InfluxDbWriter writer = getTestInfluxDbWriterWithCustomTags(tags);
writer.doWrite(dummyServer(), dummyQuery(), results);
verify(influxDB).write(messageCaptor.capture());
BatchPoints batchPoints = messageCaptor.getValue();
assertThat(batchPoints.getDatabase()).isEqualTo(DATABASE_NAME);
List<Point> points = batchPoints.getPoints();
assertThat(points).hasSize(1);
Point point = points.get(0);
assertThat(point.lineProtocol()).contains("customTag=customValue");
}
Aggregations