Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
This gist contains a main.go
file that shows how flux can be used as a library in your programs.
The main components you need are:
- The interpreter
- The scope (aka Prelude)
- The builtin library and your additional functions, if you want to define them
- The language specification compiler
- A querier
This example takes all the components described above from the flux repo and uses them to compile, execute and print the results of this query.
fromGenerator(start: now(), stop: now(), count: 5, fn: (n) => 1)
The fromGenerator
function is not defined by the builtin
library but it is in the inputs
package,
you can define your own functions by registering them, you can see how that is done in from_generator.go
https://github.com/influxdata/flux/blob/48f4e86c8512ff79983d2ed0668c295d74203822/stdlib/inputs/from_generator.go#L43
Since fromGenerator
function as a data source we are completely decoupled from InfluxDB, to implement your own or know what are the supported ones you can take a look at this package https://github.com/influxdata/flux/tree/master/stdlib/inputs
go run main.go
Result: _result
Table: keys: [_start, _stop]
_time:time _value:int
------------------------------ --------------------------
2019-01-15T14:10:55.400516705Z 1
2019-01-15T14:10:55.400517551Z 1
2019-01-15T14:10:55.400518397Z 1
2019-01-15T14:10:55.400519243Z 1
2019-01-15T14:10:55.400520089Z 1