In this InfluxDays NYC 2019 talk, InfluxData Founder & CTO Paul Dix will outline his vision around the platform and its new data scripting and query language Flux, and he will give the latest updates on InfluxDB time series database. This talk will walk through the vision and architecture with demonstrations of working prototypes of the projects.
22. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
23. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Comments
24. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Named Arguments
25. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
String Literals
26. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Buckets, not DBs
27. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Duration Literal
28. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:2018-11-07T00:00:00Z)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Time Literal
29. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Pipe forward operator
30. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system")
Anonymous Function
31. // get all data from the telegraf db
from(bucket:”telegraf/autogen”)
// filter that by the last hour
|> range(start:-1h)
// filter further by series with a specific measurement and field
|> filter(fn: (r) => (r._measurement == "cpu" or r._measurement == “cpu")
and r.host == “serverA")
Predicate Function
39. // defining a pipe forwardable function
square = (tables=<-) =>
tables
|> map(fn: (r) => {r with _value: r._value * r._value})
40. // defining a pipe forwardable function
square = (tables=<-) =>
tables
|> map(fn: (r) => {r with _value: r._value * r._value})
This is potentially new
55. // in a file called package.flux
package "paul"
option version = "0.1.1"
// define square here or…
56. // in a file called package.flux
package "paul"
option version = "0.1.1"
// import the other package files
// they must have package "paul" declaration at the top
// only package.flux has the version
import “packages”
packages.load(files: ["square.flux", "utils.flux"])
57. // in a file called package.flux
package "paul"
option version = "0.1.1"
// import the other package files
// they must have package "paul" declaration at the top
// only package.flux has the version
import “packages”
packages.load(files: ["square.flux", "utils.flux"])
// or this
packages.load(glob: "*.flux")
59. import "myorg/paul", "0.1.0" // specific version
// 1. look in $fluxhome/myorg/paul/package.flux
// 2. look in $fluxhome/myorg/paul/0.1.0/package.flux
// 3. look in cloud2.influxdata.com/api/v1/packages/myorg/paul
data |> paul.square()
71. while(fn: () => {
// do stuff
})
while = (fn) =>
if fn()
while(fn)
72. // or loop some number of times
loop(fn: (i) => {
// do stuff here
},
times: 10)
73. // or loop some number of times
loop(fn: (i) => {
// do stuff here
},
times: 10)
loop = (fn, times) =>
loopUntil(fn, 0, times)
74. // or loop some number of times
loop(fn: (i) => {
// do stuff here
},
times: 10)
loop = (fn, times) =>
loopUntil(fn, 0, times)
loopUntil = (fn, iteration, times) =>
if iteration < times {
fn(iteration)
loopUntil(fn, iteration + 1, times)
}
77. // <stream object>[<predicate>,<time>:<time>,<list of strings>]
// and here's an example
from(bucket:"foo")[_measurement == "cpu" and _field == "usage_user",
2018-11-07:2018-11-08,
["_measurement", "_time", "_value", “_field”]]
78. // <stream object>[<predicate>,<time>:<time>,<list of strings>]
// and here's an example
from(bucket:"foo")[_measurement == "cpu" and _field == "usage_user",
2018-11-07:2018-11-08,
["_measurement", "_time", "_value", “_field”]]
from(bucket:"foo")
|> filter(fn: (row) => row._measurement == "cpu" and row._field == "usage_user")
|> range(start: 2018-11-07, stop: 2018-11-08)
|> keep(columns: ["_measurement", "_time", "_value", “_field"])
82. bucket = "foo"
start = -3
from(bucket: bucket)
|> range(start: start, end: -1)
// shortcut if the variable name is the same as the argument
from(bucket)
|> range(start, end: -1)