Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flux and InfluxDB 2.0

Paul Dix
November 07, 2018

Flux and InfluxDB 2.0

Talk given at InfluxDays SF 2018 on Flux, the new language we're creating, and where we're going with InfluxDB 2.0.

Paul Dix

November 07, 2018
Tweet

More Decks by Paul Dix

Other Decks in Technology

Transcript

  1. 2.0

  2. • MIT Licensed • Multi-tenanted • Telegraf, InfluxDB, Chronograf, Kapacitor

    rolled into 1 • OSS single server • Cloud usage based pricing • Dedicated Cloud • Enterprise on-premise
  3. • MIT Licensed • Multi-tenanted • Telegraf, InfluxDB, Chronograf, Kapacitor

    rolled into 1 • OSS single server • Cloud usage based pricing • Dedicated Cloud • Enterprise on-premise
  4. // 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")
  5. // 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
  6. // 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
  7. // 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
  8. // 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
  9. // 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
  10. // 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
  11. // 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
  12. // 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
  13. // 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
  14. // variables some_int = 23 some_float = 23.2 some_string =

    “cpu" some_duration = 1h some_time = 2018-10-10T19:00:00
  15. // variables some_int = 23 some_float = 23.2 some_string =

    “cpu" some_duration = 1h some_time = 2018-10-10T19:00:00 some_array = [1, 6, 20, 22]
  16. // variables some_int = 23 some_float = 23.2 some_string =

    “cpu" some_duration = 1h some_time = 2018-10-10T19:00:00 some_array = [1, 6, 20, 22] some_object = {foo: "hello" bar: 22}
  17. Table _measurement host region _field _time _value mem A west

    free 2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 10
  18. _measurement host region _field _time _value mem A west free

    2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 10 Column
  19. _measurement host region _field _time _value mem A west free

    2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 10 Record
  20. _measurement host region _field _time _value mem A west free

    2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 10 Group Key _measurement=mem,host=A,region=west,_field=free
  21. _measurement host region _field _time _value mem A west free

    2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 10 Every record has the same value! _measurement=mem,host=A,region=west,_field=free
  22. Table Per Series _measurement host region _field _time _value mem

    A west free 2018-06-14T09:15:00 10 mem A west free 2018-06-14T09:14:50 11 _measurement host region _field _time _value mem B west free 2018-06-14T09:15:00 20 mem B west free 2018-06-14T09:14:50 22 _measurement host region _field _time _value cpu A west usage_user 2018-06-14T09:15:00 45 cpu A west usage_user 2018-06-14T09:14:50 49 _measurement host region _field _time _value cpu A west usage_system 2018-06-14T09:15:00 35 cpu A west usage_system 2018-06-14T09:14:50 38
  23. input tables -> function -> output tables // example query

    from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum()
  24. input tables -> function -> output tables What to sum

    on? // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum()
  25. input tables -> function -> output tables Default columns argument

    // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum(columns: [“_value”])
  26. input tables -> function -> output tables _meas ureme host

    region _field _time _valu e mem A west free 2018-06- 14T09:1 10 mem A west free 2018-06- 14T09:1 11 _meas ureme host region _field _time _valu e mem B west free 2018-06- 14T09:15 20 mem B west free 2018-06- 14T09:14 22 Input in table form // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum()
  27. input tables -> function -> output tables _meas ureme host

    region _field _time _valu e mem A west free 2018-06- 14T09:1 10 mem A west free 2018-06- 14T09:1 11 _meas ureme host region _field _time _valu e mem B west free 2018-06- 14T09:15 20 mem B west free 2018-06- 14T09:14 22 sum() // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum()
  28. input tables -> function -> output tables // example query

    from(db:"telegraf") |> range(start:2018-06-14T09:14:50, start:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> sum() _meas ureme host region _field _time _valu e mem A west free 2018-06- 14T09:1 10 mem A west free 2018-06- 14T09:1 11 _meas ureme host region _field _time _valu e mem B west free 2018-06- 14T09:15 20 mem B west free 2018-06- 14T09:14 22 sum() _meas ureme host region _field _time _valu e mem A west free 2018-06- 14T09:1 21 _meas ureme host region _field _time _valu e mem B west free 2018-06- 14T09:15 42
  29. window // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn:

    r => r._measurement == “mem" and r._field == “free”) |> window(every:20s) 30s of data (4 samples)
  30. window // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn:

    r => r._measurement == “mem" and r._field == “free”) |> window(every:20s) split into 20s windows
  31. window _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> window(every:20s) Input
  32. window _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 window( every:20s) // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> window(every:20s)
  33. window _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 window( every:20s) // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> window(every:20s) _meas ureme host region _field _time _valu e mem A west free …14:30 10 mem A west free …14:40 11 _meas ureme host region _field _time _valu e mem B west free …14:50 23 mem B west free …15:00 24 _meas ureme host region _field _time _valu e mem B west free …14:30 20 mem B west free …14:40 22 _meas ureme host region _field _time _valu e mem A west free …14:50 12 mem A west free …15:00 13
  34. window _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 window( every:20s) // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> window(every:20s) _meas ureme host region _field _time _valu e mem A west free …14:30 10 mem A west free …14:40 11 _meas ureme host region _field _time _valu e mem B west free …14:50 23 mem B west free …15:00 24 _meas ureme host region _field _time _valu e mem B west free …14:30 20 mem B west free …14:40 22 _meas ureme host region _field _time _valu e mem A west free …14:50 12 mem A west free …15:00 13 N to M tables
  35. group // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn:

    r => r._measurement == “mem" and r._field == “free”) |> group(keys:[“region"])
  36. group // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn:

    r => r._measurement == “mem" and r._field == “free”) |> group(keys:[“region"]) new group key
  37. group _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> group(keys:[“region"])
  38. group _meas host region _field _time _valu mem A west

    free …14:30 10 mem A west free …14:40 11 mem A west free …14:50 12 mem A west free …15:00 13 _meas host region _field _time _valu mem B west free …14:30 20 mem B west free …14:40 22 mem B west free …14:50 23 mem B west free …15:00 24 group( keys: [“region”]) // example query from(db:"telegraf") |> range(start:2018-06-14T09:14:30, end:2018-06-14T09:15:01) |> filter(fn: r => r._measurement == “mem" and r._field == “free”) |> group(keys:[“region"]) _meas ureme host region _field _time _valu e mem A west free …14:30 10 mem B west free …14:30 20 mem A west free …14:40 11 mem B west free …14:40 21 mem A west free …14:50 12 mem B west free …14:50 22 mem B west free …15:00 13 mem B west free …15:00 23 N to M tables M == cardinality(group keys)
  39. import "mysql" customers = mysql.from(connect: loadSecret(name:”mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results")
  40. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Imports for sharing code!
  41. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Pulling data from a non-InfluxDB source
  42. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Raw query (for now)
  43. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Loading Secret
  44. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Renaming & Shaping Data
  45. import "mysql" customers = mysql.from(connect: loadSecret(name:"mysql_prod"), query: "select id, name

    from customers") data = from(bucket: "my_data") |> range(start: -4h) |> filter(fn: (r) => r._measurement == “write_requests") |> rename(columns: {customer_id: “id"}) join(tables: {customers, data}, on: ["id"]) |> yield(name: "results") Join on any column
  46. option task = { name: “Alert on disk", every: 5m,

    } crit = 90 // alert at this percentage warn = 80 // warn at this percentage data = from(bucket: "telegraf/autogen") |> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent") |> last() data |> filter(fn: (r) => r._value > crit) |> addColumn(key: "level", value: "critical") |> addColumn(key: "alert", value: task.name) |> to(bucket: "alerts") data |> filter(fn: (r) => r._value > warn && r._value < crit) |> addColumn(key: "level", value: "warn") |> to(bucket: "alerts")
  47. option task = { name: “Alert on disk", every: 5m,

    } crit = 90 // alert at this percentage warn = 80 // warn at this percentage data = from(bucket: "telegraf/autogen") |> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent") |> last() data |> filter(fn: (r) => r._value > crit) |> addColumn(key: "level", value: "critical") |> addColumn(key: "alert", value: task.name) |> to(bucket: "alerts") data |> filter(fn: (r) => r._value > warn && r._value < crit) |> addColumn(key: "level", value: "warn") |> to(bucket: "alerts") Option syntax for tasks
  48. option task = { name: “Alert on disk", every: 5m,

    } crit = 90 // alert at this percentage warn = 80 // warn at this percentage data = from(bucket: "telegraf/autogen") |> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent") |> last() data |> filter(fn: (r) => r._value > crit) |> addColumn(key: "level", value: "critical") |> addColumn(key: "alert", value: task.name) |> to(bucket: "alerts") data |> filter(fn: (r) => r._value > warn && r._value < crit) |> addColumn(key: "level", value: "warn") |> to(bucket: "alerts") Get at the last value without specifying time range
  49. option task = { name: “Alert on disk", every: 5m,

    } crit = 90 // alert at this percentage warn = 80 // warn at this percentage data = from(bucket: "telegraf/autogen") |> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent") |> last() data |> filter(fn: (r) => r._value > crit) |> addColumn(key: "level", value: “critical") |> addColumn(key: "alert", value: task.name) |> to(bucket: "alerts") data |> filter(fn: (r) => r._value > warn && r._value < crit) |> addColumn(key: "level", value: "warn") |> to(bucket: "alerts") Adding a column to decorate the data
  50. option task = { name: “Alert on disk", every: 5m,

    } crit = 90 // alert at this percentage warn = 80 // warn at this percentage data = from(bucket: "telegraf/autogen") |> filter(fn: (r) => r._measurement == "disk" and r._field == "used_percent") |> last() data |> filter(fn: (r) => r._value > crit) |> addColumn(key: "level", value: "critical") |> addColumn(key: "alert", value: task.name) |> to(bucket: "alerts") data |> filter(fn: (r) => r._value > warn && r._value < crit) |> addColumn(key: "level", value: "warn") |> to(bucket: "alerts") To writes to the local InfluxDB
  51. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: “slack_alert_config”), message: “_value”) |> to(bucket: “notifications")
  52. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == “critical”) // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") We have state so we don’t resend
  53. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") Use last time as argument to range
  54. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") Now function for current time
  55. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") Map function to iterate over values
  56. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") String interpolation
  57. option task = {name: "slack critical alerts", every: 1m} import

    "slack" lastNotificationTime = from(bucket: "notificatons") |> filter(fn: (r) => r.level == "critical" and r._field == "alert_time") |> group(none:true) |> last() |> recordValue(column:"_value") from(bucket: "alerts") |> range(start: lastNotificationTime) |> filter(fn: (r) => r.level == "critical") // shape the alert data to what we care about in notifications |> renameColumn(from: "_time", to: "alert_time") |> renameColumn(from: "_value", to: "used_percent") // set the time the notification is being sent |> addColumn(key: "_time", value: now()) // get rid of unneeded columns |> drop(columns: ["_start", "_stop"]) // write the message |> map(fn: (r) => r._value = "{r.host} disk usage is at {r.used_percent}%") |> slack.to(config: loadSecret(name: "slack_alert")) |> to(bucket: “notifications") Send to Slack and record in InfluxDB
  58. option task = { name: "email alert digest", cron: "0

    5 * * 0" } import "smtp" body = "" from(bucket: "alerts") |> range(start: -24h) |> filter(fn: (r) => (r.level == "warn" or r.level == "critical") and r._field == "message") |> group(by: ["alert"]) |> count() |> group(none: true) |> map(fn: (r) => body = body + "Alert {r.alert} triggered {r._value} times\n") smtp.to( config: loadSecret(name: "smtp_digest"), to: "[email protected]", title: "Alert digest for {now()}", body: message)
  59. option task = { name: "email alert digest", cron: "0

    5 * * 0" } import "smtp" body = "" from(bucket: "alerts") |> range(start: -24h) |> filter(fn: (r) => (r.level == "warn" or r.level == "critical") and r._field == "message") |> group(by: ["alert"]) |> count() |> group(none: true) |> map(fn: (r) => body = body + "Alert {r.alert} triggered {r._value} times\n") smtp.to( config: loadSecret(name: "smtp_digest"), to: "[email protected]", title: "Alert digest for {now()}", body: message) Cron syntax
  60. option task = { name: "email alert digest", cron: "0

    5 * * 0" } import "smtp" body = "" from(bucket: "alerts") |> range(start: -24h) |> filter(fn: (r) => (r.level == "warn" or r.level == "critical") and r._field == "message") |> group(by: ["alert"]) |> count() |> group(none: true) |> map(fn: (r) => body = body + "Alert {r.alert} triggered {r._value} times\n") smtp.to( config: loadSecret(name: "smtp_digest"), to: "[email protected]", title: "Alert digest for {now()}", body: message) Closures
  61. 2.0