Package com.izettle.metrics.influxdb
Class GroupedInfluxDbHttpSender
- java.lang.Object
-
- com.izettle.metrics.influxdb.InfluxDbHttpSender
-
- com.izettle.metrics.influxdb.GroupedInfluxDbHttpSender
-
- All Implemented Interfaces:
InfluxDbSender
public class GroupedInfluxDbHttpSender extends InfluxDbHttpSender
Passthrough to ultimately select a different style of serializer: grouped fields on one influxdb protocol line, instead of one field per protocol line. This class will write out one protocol line per timestamp. For each point that occurred at a particular timestamp, a line is output in the following order with a comma delimiting the first two items and a space delimiting all other items: 1. measurementPrefix+groupMeasurement 2. tags (in the format of name=value) delimited by commas 3. each field is written prepended with a name that indicates its measurement delimited by commas. There is an assumption made here that the measurement naming convention is a set of strings delimited by a ".". In the case where there is at least two strings in the measurement name, the first string in that name is dropped. Also, if a particular point has only one field and that field has the key "value", the field name is dropped. 4. time (in milliseconds) To illustrate what is described above, here is an examples of what will be written for a given sets of points.EXAMPLE
[ // The first two points are intended to show how points with the same timestamp are merged. Point { measurement: confabulator.a.b.c, tags { foo: one, bar: two }, time: 0, fields { temp: 10, bytes: 7 } }, Point { measurement: confabulator.x.y.z, tags { foo: one, bar: two }, time: 0, fields { pressure: 50, status: good } }, // This next point shows the example of when the field has one key called "value" Point { measurement: confabulator.file.size.max, tags { foo: one, bar: two }, time: 1, fields { value = 10000000 } }, // This next point shows an example of what is written when measurement is only a single string Point { measurement: minimum, tags { foo: one, bar: two }, time: 2, fields { memory: 64000, temperature: 98.6 } } ]OUTPUT FOR ABOVE EXAMPLE
Assuming that the value for themeasurementPrefixisnulland thegroupMeasurementis the string "groupMeasurement", the output for the above example would result in three lines corresponding to the three unique timestamps. The lines would be as follows:groupMeasurement,foo=one,bar=two a.b.c.temp=10,a.b.c.bytes=7,x.y.z.pressure=50,x.y.z.status=good 0 groupMeasurement,foo=one,bar=two file.size.max=10000000 1 groupMeasurement,foo=one,bar=two minimum.memory=64000,minimum.temperature=98.6 2
-
-
Constructor Summary
Constructors Constructor Description GroupedInfluxDbHttpSender(String protocol, String hostname, int port, String database, String authString, TimeUnit timePrecision, int connectTimeout, int readTimeout, String measurementPrefix, String groupMeasurement)Creates a new http sender given connection details.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendPoints(InfluxDbPoint point)Adds this metric point to the buffer.voidflush()Flushes buffer, if applicable.protected InfluxDbWriteObjectSerializergetSerializer()Map<String,String>getTags()protected InfluxDbWriteObjectgetWriteObject()booleanhasSeriesData()voidsetTags(Map<String,String> tags)Set tags applicable for all the points.intwriteData()Writes buffer data to InfluxDb.-
Methods inherited from class com.izettle.metrics.influxdb.InfluxDbHttpSender
writeData
-
-
-
-
Constructor Detail
-
GroupedInfluxDbHttpSender
public GroupedInfluxDbHttpSender(String protocol, String hostname, int port, String database, String authString, TimeUnit timePrecision, int connectTimeout, int readTimeout, String measurementPrefix, String groupMeasurement) throws Exception
Creates a new http sender given connection details. This sender groups all the fields under one measurement and transmit them as one measurement.- Parameters:
protocol- the name of the protocol to usehostname- the influxDb hostnameport- the influxDb http portdatabase- the influxDb database to write toauthString- the authorization string to be used to connect to InfluxDb, of format username:passwordtimePrecision- the time precision of the metricsconnectTimeout- the connect timeoutreadTimeout- the read timeoutmeasurementPrefix- the measurement prefixgroupMeasurement- the group measurement name- Throws:
Exception- exception while creating the influxDb sender(MalformedURLException)
-
-
Method Detail
-
writeData
public int writeData() throws ExceptionDescription copied from interface:InfluxDbSenderWrites buffer data to InfluxDb.- Specified by:
writeDatain interfaceInfluxDbSender- Returns:
- the response code for the request sent to InfluxDb.
- Throws:
Exception- exception while writing to InfluxDb api
-
flush
public void flush()
Description copied from interface:InfluxDbSenderFlushes buffer, if applicable.- Specified by:
flushin interfaceInfluxDbSender
-
hasSeriesData
public boolean hasSeriesData()
- Specified by:
hasSeriesDatain interfaceInfluxDbSender- Returns:
- true if there is data available to send.
-
appendPoints
public void appendPoints(InfluxDbPoint point)
Description copied from interface:InfluxDbSenderAdds this metric point to the buffer.- Specified by:
appendPointsin interfaceInfluxDbSender- Parameters:
point- metric point with tags and fields
-
setTags
public void setTags(Map<String,String> tags)
Description copied from interface:InfluxDbSenderSet tags applicable for all the points.- Specified by:
setTagsin interfaceInfluxDbSender- Parameters:
tags- map containing tags common to all metrics
-
getTags
public Map<String,String> getTags()
- Specified by:
getTagsin interfaceInfluxDbSender
-
getWriteObject
protected InfluxDbWriteObject getWriteObject()
-
getSerializer
protected InfluxDbWriteObjectSerializer getSerializer()
-
-