Just couldn’t help my self, but started fiddling with InfluxDB and usually that means I start writing on my own client just to learn how it works. If I find the fiddling code useful and of use for others, I start packaging it up. This is exactly what is happening now, with my InfluxDB fiddle.
The first milestone “Gecko” will provide business value in the sense of being able to create a database and write points to it. That will look something like the sample below.
Points
The first step is to create a collection of points. A point is defined by having at least: a measurement
and one or many Fields
. Optionally, you can also define Tags
.
Time series data, is about time. And to control the time stamp of a point, you can either explicitly take control of the TimeStamp
or let InfluxDB generate that for you (defaults to nano second resolution). If you assign it, you also need to determine what resolution level you want:
- Nanoseconds
- Microseconds
- Milliseconds
- Seconds
- Minutes
- Hours
var points = new InfluxPoints()
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "1")
.AddTag("cur", "SEK")
.AddField("amt", 150.0)
.AddField("fee", 50.0)) //TimeStamp assigned in DB
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "1")
.AddTag("cur", "USD")
.AddField("amt", 10.0)
.AddField("fee", 2.5)
.AddTimeStamp())
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "2")
.AddTag("cur", "USD")
.AddField("amt", 10.0)
.AddField("fee", 2.5).AddTimeStamp(DateTime.Now))
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "1")
.AddTag("cur", "EUR")
.AddField("amt", 9.5)
.AddField("fee", 5.0)
.AddTimeStamp(TimeStampResolutions.Nanoseconds)) //Default
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "2")
.AddTag("cur", "SEK")
.AddField("amt", 225.5)
.AddField("fee", 50.0)
.AddTimeStamp(TimeStampResolutions.Microseconds))
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "3")
.AddTag("cur", "SEK")
.AddField("amt", 110.0)
.AddField("fee", 30.0)
.AddTimeStamp(TimeStampResolutions.Milliseconds))
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "3")
.AddTag("cur", "SEK")
.AddField("amt", 2350.0)
.AddField("fee", 10.0)
.AddTimeStamp(TimeStampResolutions.Seconds))
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "2")
.AddTag("cur", "EUR")
.AddField("amt", 51.8)
.AddField("fee", 5.0)
.AddTimeStamp(TimeStampResolutions.Minutes))
.Add(new InfluxPoint("ticketsold")
.AddTag("seller", "1")
.AddTag("cur", "USD")
.AddField("amt", 1.0)
.AddField("fee", 1.0)
.AddTimeStamp(TimeStampResolutions.Hours));
Create the DB and Write the points
You communicate with your InfluxDB installation with the InfluxDbClient
.
If you want, you can create the DB with the client (authentication coming), but I’m guessing the DB will be created else where. But the code is shown anyway.
The points are written using WriteAsync
.
using (var client = new InfluxDbClient("http://192.168.1.176:9086"))
{
await client.CreateDbAsync("mydb");
await client.WriteAsync("mydb", points);
}
Exceptions
If you have passed some weird arguments, simple validation is performed, and will result in an ArgumentException
of some kind.
If an operation fails against InfluxDB, the InfluxDbClient
will throw a InfluxDbClientException
.
To be continued
So, still early days, but “Gecko” should be done really soon. Keep track of the GitHub repo activity if you are interested.
Cheers,
//Daniel