Skip to content
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.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci ci: add GOFLAGS -p=8 to circleci config (#1180) Apr 16, 2019
.github chore: add PR template for definition of done Dec 14, 2018
arrow refactor(arrow): delete unnecessary arrow utils (#808) Jan 11, 2019
ast fix(ast): format conditional expression (#1188) Apr 19, 2019
benchmarks/flux
builtin refactor(stdlib): Flux testing package Jan 14, 2019
cmd/flux fix(control): enforce memory and concurrency limits in controller Apr 22, 2019
compiler feat(compiler): add support for conditional exprs to compiler Apr 19, 2019
complete fix(values): make read-like access patterns for objects thread-safe (#… Mar 15, 2019
control chore(control): log controller config when starting up (#1207) Apr 23, 2019
csv fix(test): fix test to pass in influxdb (#1024) Mar 5, 2019
docs feat(stdlib): Allow choosing sample/population mode in stddev() (#1210) Apr 24, 2019
etc chore: make checkgenerate output ragel version Apr 17, 2019
examples
execute feat(stdlib): Allow choosing sample/population mode in stddev() (#1210) Apr 24, 2019
influxql feat(control): support attaching arbitrary query metadata from the ex… Feb 25, 2019
internal fix(ast): format right child with good parens (#1166) Apr 17, 2019
interpreter feat(interpreter): add conditional expression handling to interpreter Apr 19, 2019
iocounter feat(query): Change Encode interface to return bytes written Jun 27, 2018
lang test(lang): add tests for query (#1153) Apr 19, 2019
line feat(control): support attaching arbitrary query metadata from the ex… Feb 25, 2019
memory feat: create memory package with a memory allocator Nov 6, 2018
mock fix(control): enforce memory and concurrency limits in controller Apr 22, 2019
parser feat(parser): parse signed duration Mar 25, 2019
plan
querytest fix(control): enforce memory and concurrency limits in controller Apr 22, 2019
repl refactor(lang): move spec compiler to repl package (#1137) Apr 12, 2019
semantic feat(semantic): add handling for conditional expressions to type infe… Apr 17, 2019
stdlib feat(stdlib): Allow choosing sample/population mode in stddev() (#1210) Apr 24, 2019
values feat: define comparison operators between time types (#999) Mar 26, 2019
.dockerignore chore(Docker): add Dockerfile for building Flux Dec 21, 2018
.gitignore build: add automatic release support Dec 11, 2018
.goreleaser.yml build: add automatic release support Dec 11, 2018
CONTRIBUTING.md docs: Reference conventional commits in CONTRIBUTING.md (#1108) Mar 29, 2019
Dockerfile_build
LICENSE LICENSE (#133) Oct 30, 2018
Makefile feat(stdlib): organizes builtin code into Flux packages Jan 11, 2019
README.md docs(README): update README with whirlwind Flux tour Dec 19, 2018
bounds.go add the notion of bounds to plan nodes (#142) Oct 26, 2018
bounds_test.go chore: fix current megacheck errors Nov 2, 2018
compile.go feat(stdlib/strings): Add trim{Suffix,Prefix} functions (#1192) Apr 22, 2019
compile_internal_test.go feat(ast): implement and require builtin statements Jan 15, 2019
compiler.go refactor(lang): Update Compiler interface to produce a Program (#1095) Apr 12, 2019
dialect.go chore: Remove platform dependency Sep 12, 2018
format.go refactor: Initial migration Sep 5, 2018
go.mod refactor(control): update the controller to use the new compile and p… Apr 12, 2019
go.sum feat(builtin): add ability to define built in packages Jan 8, 2019
group_mode.go feat(stdlib): organizes builtin code into Flux packages Jan 11, 2019
operation.go chore: Remove platform dependency Sep 12, 2018
query.go
release.sh fix: require a github token to perform a release (#1150) Apr 11, 2019
resource_management.go refactor: Initial migration Sep 5, 2018
result.go
result_iterator.go fix: Allow flux unit tests to pass (#1103) Apr 12, 2019
result_iterator_test.go test(lang): add tests for query (#1153) Apr 19, 2019
result_test.go refactor: rename DataType to ColType and add a ColumnType function ut… Oct 22, 2018
spec.go chore: Remove platform dependency Sep 12, 2018
spec_test.go feat(stdlib/universe): add contains function to check for membership … Feb 7, 2019
time.go tests: add tests for time marshaling and unmarshaling Nov 6, 2018
time_test.go tests: add tests for time marshaling and unmarshaling Nov 6, 2018
tools.go chore(Makefile): add checks to Makefile Dec 21, 2018

README.md

Flux - Influx data language

CircleCI

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 repo represents the language definition and an implementation of the language core.

NOTE: We plan to provide a flux command line program that exposes a REPL and talks to various data sources. In the meantime see the influx command in this repo as it has working Flux installation against the 2.0 InfluxDB database.

Specification

A complete specification can be found in SPEC.md. The specification contains many examples to start learning Flux.

Getting Started

Currently Flux is only avaliable via InfluxDB, see http://docs.influxdata.com/flux/ for getting started.

Basic Syntax

Here are a few examples of the language to get an idea of the syntax.

// This line is a comment

// Support for traditional math operators
1 + 1

// Several data types are built-in
true                     // a boolean true value
1                        // an int
1.0                      // a float
"this is a string"       // a string literal
1h5m                     // a duration of time representing 1 hour and 5 minutes
2018-10-10               // a time starting at midnight for the default timezone on Oct 10th 2018
2018-10-10T10:05:00      // a time at 10:05 AM for the default timezone on Oct 10th 2018
[1,1,2]                  // an array of integers
{foo: "str", bar: false} // an object with two keys and their values

// Values can be assigned to identifers
x = 5.0
x + 3.0 // 8.0

// Import libraries
import "math"

// Call functions always using keyword arguments
math.pow(base: 5, exponent: 3) // 5^3 = 125

// Functions are defined by assigning them to identifers
add = (a, b) => a + b

// Call add using keyword arguments
add(a: 5, b: 3) // 8

// Functions are polymorphic
add(a: 5.5, b: 2.5) // 8.0

// Access data from a database and store it as an identifer
import "influxdb"
data = influxdb.from(bucket:"telegraf/autogen")

// Chain more transformation functions to further specify the desired data
cpu = data 
    // only get the last 5m of data
    |> range(start: -5m)
    // only get the "usage_user" data from the _measurement "cpu"
    |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_user")

// Return the data to the client
cpu |> yield()

// Group an aggregate along different dimensions
cpu
    // organize data into groups by host and region
    |> group(columns:["host","region"])
    // compute the mean of each group
    |> mean()
    // yield this result to the client
    |> yield()

// Window an aggregate over time
cpu
    // organize data into groups of 1 minute
    // compute the mean of each group
    |> aggregateWindow(every: 1m, fn: mean)
    // yield this result to the client
    |> yield()

// Gather different data
mem = data 
    // only get the last 5m of data
    |> range(start: -5m)
    // only get the "used_percent" data from the _measurement "mem"
    |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent")


// Join data to create wider tables and map a function over the result
join(tables: {cpu:cpu, mem:mem}, on:["_time", "host"])
    // compute the ratio of cpu usage to mem used_percent
    |> map(fn:(r) => {_time: r._time, _value: r._value_cpu / r._value_mem)
    // again yield this result to the client
    |> yield()

The above examples give only a taste of what is possible with Flux. See the complete documentation for more complete examples and installation instructions.

You can’t perform that action at this time.