Advertisement
Advertisement

More Related Content

Similar to Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi(20)

Advertisement

More from InfluxData(20)

Advertisement

Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi

  1. Grafana & Flux New Flux support in Grafana Jacob Lisi @JacobLisi
  2. TL;DR ● Flux is powerful ● You can start playing with Flux in Grafana today ○ Flux support in Grafana is available via a new datasource plugin ● For now, no automated way to migrate dashboards ○ Transpiler for Influx queries is being worked on ○ You can migrate your dashboards and panels manually
  3. Flux Design Goals ● Decouple language from the execution engine ○ Execution engine takes a DAG of transformations ○ Transpilers: Flux, Influx Query, PromQL ● Decouple database from query computation ○ Iterate faster on query engine ○ Keep database untouched ○ Independently scalable ● Add more functions ○ Chainable: transformation from input table to output table
  4. Flux recap from(db: “telegraf”) |> filter(fn: (r) => r[“host”] == “myServer”) |> range(start: -1h)
  5. Flux recap: Select one value from a table from(db: “telegraf”) |> filter(fn: (r) => r[“host”] == “myServer”) |> range(start: -1h) |> max() // Selector
  6. Flux primer: Window-chunk and aggregate from(db: “telegraf”) |> filter(fn: (r) => r[“_measurement”] == “cpu”) |> range(start: -1h) |> window(every: 10m) |> mean() // Aggregator |> filter(fn: (r) => r._value > 1) // Having
  7. Flux query planning from(db: “telegraf”) |> filter(fn: (r) => r[“host”] == “myServer”) |> range(start: -1h) |> max() from(db: “telegraf”) |> range(start: -1h) |> filter(fn: (r) => r[“host”] == “myServer”) |> max() ● Same plan DAG
  8. Flux query planning gotchas from(db: “telegraf”) |> filter(fn: (r) => r[“host”] == “myServer”) |> range(start: -1h) |> max() from(db: “telegraf”) |> filter(fn: (r) => r[“host”] == “myServer”) |> max() // Selector function returns 1 record |> range(start: -1h) from(db: “telegraf”) |> range(start: -1h) |> filter(fn: (r) => r[“_value”] > 1) // Full table scan
  9. User defined functions select = (db=”telegraf”, m, f) => { return from(db:db) |> filter(fn: (r) => r._measurement == m and r._field == f) } select(m: “cpu”, f: “usage_user”) |> filter(fn: (r) => r[“host”] == “myServer”) |> range(start: -1h)
  10. Chainable user defined functions myFilter = (m, f, table=<-) => { return table |> filter(fn: (r) => r._measurement == m and r._field == f) } from(db: “telegraf”) |> myFilter(m: “cpu”, f: “usage_user”) |> range(start: -1h)
  11. Flux StdLib https://github.com/influxdata/flux/tree/master/stdlib
  12. Math on tables cpu = from(db)... CpuRequests = from(db)... join( tables: {cpu: cpu, req: CpuRequests}, fn: (t) => t.cpu._value / t.req._value ) // Implicit join on time
  13. New response format: CSV
  14. Getting Started With Flux ● Run latest influxd ○ https://portal.influxdata.com/downloads ○ Update your influxdb.conf to include ● Generate data ○ Telegraf # ... [http] # ... flux-enabled = true # ...
  15. Get started: Grafana datasource ● Get Grafana 5.3+ ● Install Flux datasource plugin ○ https://github.com/grafana/influxdb-flux-datasource ○ Clone into your grafanas data/plugins ○ Restart Grafana ● Add your Flux datasource ● Add a dashboard ● Add a panel
  16. Demo https://github.com/jtlisi/grafana_flux_demo
  17. Datasource feature summary ● Syntax highlighting, tab completion, raw table preview ● Inline function documentation ● $range variable
  18. Datasource feature summary ● Shortcodes ● Template variables with helper functions ○ measurements() ○ field_keys() ○ tags() ○ tag_values() ● Annotations
  19. Roadmap ● Alerting ● UI improvements ● Improve Query Shortcuts ● Transitioning to a default plugin ● Dashboard Migrations?
  20. Thanks for listening! Questions? @JacobLisi
Advertisement