SlideShare a Scribd company logo
Scott Anderson
Senior Technical Writer & Technical Lead of
the Docs team @ InfluxData
InfluxDB Tasks
Beyond Downsampling
© 2020 InfluxData. All rights reserved. 2
What is an InfluxDB task?
A scheduled Flux script
© 2020 InfluxData. All rights reserved. 3
Why tasks?
● Automate repeated operations
● A replacement for Continuous Queries
(CQs) in InfluxDB Cloud and InfluxDB
2.0
© 2020 InfluxData. All rights reserved. 4
Downsampling cascade
© 2020 InfluxData. All rights reserved. 5
CREATE CONTINUOUS QUERY "downsample-daily" ON "my-db"
BEGIN
SELECT mean("example-field")
INTO "average-example-measurement"
FROM "example-measurement"
GROUP BY time(1h)
END
© 2020 InfluxData. All rights reserved. 6
from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every)
|> filter(fn: (r) =>
r._measurement == "example-m" and
r._field == "value"
)
|> aggregateWindow(every: 1h, fn: mean())
|> to(bucket: "downsampled-daily", org: "my-org")
© 2020 InfluxData. All rights reserved. 7
Downsampling InfluxDB Template
github.com/influxdata/community-templates
© 2020 InfluxData. All rights reserved. 8
© 2020 InfluxData. All rights reserved. 9
and the potential of Flux
BEYOND Downsampling
Monitoring & Alerting
© 2020 InfluxData. All rights reserved. 12
© 2020 InfluxData. All rights reserved. 13
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/tasks"
import "influxdata/influxdb/v1"
check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}}
task_data = from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every), stop: now())
|> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem")
|> mean()
ok = (r) => r._value <= 60.0
crit = (r) => r._value > 95.0
warn = (r) => r._value > 80.0 and r._value <= 95.0
info = (r) => r._value > 60.0 and r._value <= 80.0
messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.")
task_data
|> v1.fieldsAsCols()
|> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info)
System-generated check task
© 2020 InfluxData. All rights reserved. 14
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/tasks"
import "influxdata/influxdb/v1"
check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}}
task_data = from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every), stop: now())
|> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem")
|> mean()
ok = (r) => r._value <= 60.0
crit = (r) => r._value > 95.0
warn = (r) => r._value > 80.0 and r._value <= 95.0
info = (r) => r._value > 60.0 and r._value <= 80.0
messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.")
task_data
|> v1.fieldsAsCols()
|> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info)
System-generated check task
© 2020 InfluxData. All rights reserved. 15
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/tasks"
import "influxdata/influxdb/v1"
check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}}
task_data = from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every), stop: now())
|> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem")
|> mean()
ok = (r) => r._value <= 60.0
crit = (r) => r._value > 95.0
warn = (r) => r._value > 80.0 and r._value <= 95.0
info = (r) => r._value > 60.0 and r._value <= 80.0
messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.")
task_data
|> v1.fieldsAsCols()
|> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info)
System-generated check task
© 2020 InfluxData. All rights reserved. 16
© 2020 InfluxData. All rights reserved. 17
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/tasks"
import "influxdata/influxdb/v1"
check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}}
task_data = from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every), stop: now())
|> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem")
|> mean()
ok = (r) => r._value <= 60.0
crit = (r) => r._value > 95.0
warn = (r) => r._value > 80.0 and r._value <= 95.0
info = (r) => r._value > 60.0 and r._value <= 80.0
messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.")
task_data
|> v1.fieldsAsCols()
|> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info)
System-generated check task
© 2020 InfluxData. All rights reserved. 18
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/tasks"
import "influxdata/influxdb/v1"
check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}}
task_data = from(bucket: "my-bucket")
|> range(start: tasks.lastSuccess(orTime: -task.every), stop: now())
|> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem")
|> mean()
ok = (r) => r._value <= 60.0
crit = (r) => r._value > 95.0
warn = (r) => r._value > 80.0 and r._value <= 95.0
info = (r) => r._value > 60.0 and r._value <= 80.0
messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.")
task_data
|> v1.fieldsAsCols()
|> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info)
System-generated check task
© 2020 InfluxData. All rights reserved. 19
© 2020 InfluxData. All rights reserved. 20
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/slack"
endpoint = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "SLACK_TOKEN")
)
monitor.from(
start: -task.every,
fn: (r) => r._level == "crit"
)
|> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))()
System-generated notification task
© 2020 InfluxData. All rights reserved. 21
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/slack"
endpoint = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "SLACK_TOKEN")
)
monitor.from(
start: -task.every,
fn: (r) => r._level == "crit"
)
|> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))()
System-generated notification task
© 2020 InfluxData. All rights reserved. 22
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/slack"
endpoint = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "SLACK_TOKEN")
)
monitor.from(
start: -task.every,
fn: (r) => r._level == "crit"
)
|> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))()
System-generated notification task
© 2020 InfluxData. All rights reserved. 23
*
Simple Custom Alerts
Send alerts without using InfluxDB
checks & notifications
© 2020 InfluxData. All rights reserved. 25
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 26
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 27
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 28
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 29
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 30
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
© 2020 InfluxData. All rights reserved. 31
import "influxata/influxdb/tasks"
import "influxata/influxdb/slack"
import anomaly "contrib/anaisdg/anomalydetection"
toSlack = slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: secrets.get(key: "SLACK_TOKEN")
)
from(bucket: "example")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> filter(fn: (r) => r._measurement == "m")
|> anomaly.mad()
|> filter(fn: (r) => r.level == "anomaly")
|> toSlack(
mapFn: (r) => { r with
channel: "anomalies",
text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}",
color: "danger"
}
)()
Custom anomaly detection alert
Execute generated function
Data Ingest
© 2020 InfluxData. All rights reserved. 33
import "csv"
csvData = "#datatype,string,long,dateTime:RFC3339,string,double
#group,false,false,false,true,false
#default,,,,,
,result,table,_time,region,_value
,,0,2018-05-08T20:50:00Z,east,15.43
,,0,2018-05-08T20:50:20Z,east,59.25
,,1,2018-05-08T20:50:00Z,west,62.73
"
csv.from(csv:csvData)
|> to(org: "my-org", bucket: "my-bucket")
Write data using annotated CSV
© 2020 InfluxData. All rights reserved. 34
import "experimental/csv"
csv.from(url: "https://influx-testdata.s3.amazonaws.com/noaa.csv")
|> to(org: "my-org", bucket: "noaa")
Write data using remote annotated CSV
© 2020 InfluxData. All rights reserved. 35
import "experimental/array"
data = [
{_time: 2018-05-08T20:50:00Z, region: "east", _value: 15.43},
{_time: 2018-05-08T20:50:20Z, region: "east", _value: 59.25},
{_time: 2018-05-08T20:50:00Z, region: "west", _value: 62.73}
]
array.from(rows: data)
|> to(org: "my-org", bucket: "my-bucket")
Write data with using an array of records
© 2020 InfluxData. All rights reserved. 36
// ...
response = http.get(
url: "http://localhost:8086/health",
headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"}
)
responseBody = response.body
seedRow = [{_time: now()}]
array.from(rows: seedRow)
|> map(fn: (r) => {
body = json.parse(data: responseBody)
return { r with
_measurement: "monitoring",
_field: "influxdb_status",
_value: body.message,
name: body.name
}
})
|> to(org: "my-org", bucket: "my-bucket")
Write data with using an HTTP response
© 2020 InfluxData. All rights reserved. 37
// ...
response = http.get(
url: "http://localhost:8086/health",
headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"}
)
responseBody = response.body
seedRow = [{_time: now()}]
array.from(rows: seedRow)
|> map(fn: (r) => {
body = json.parse(data: responseBody)
return { r with
_measurement: "monitoring",
_field: "influxdb_status",
_value: body.message,
name: body.name
}
})
|> to(org: "my-org", bucket: "my-bucket")
Write data with using an HTTP response
© 2020 InfluxData. All rights reserved. 38
// ...
response = http.get(
url: "http://localhost:8086/health",
headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"}
)
responseBody = response.body
seedRow = [{_time: now()}]
array.from(rows: seedRow)
|> map(fn: (r) => {
body = json.parse(data: responseBody)
return { r with
_measurement: "monitoring",
_field: "influxdb_status",
_value: body.message,
name: body.name
}
})
|> to(org: "my-org", bucket: "my-bucket")
Write data with using an HTTP response
© 2020 InfluxData. All rights reserved. 39
© 2020 InfluxData. All rights reserved. 40
import "experimental/prometheus"
prometheus.scrape(url: "http://localhost:8086/metrics")
|> to(
org: "my-org",
bucket: "my-bucket"
)
Scrape data from a Prometheus endpoint
© 2020 InfluxData. All rights reserved. 41
import "influxdata/influxdb/secrets"
import "sql"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM example_table"
)
Query a SQL datasource
Data Enrichment
© 2020 InfluxData. All rights reserved. 43
join()
© 2020 InfluxData. All rights reserved. 44
_time sensorID _field _value
2020-06-01T00:12:00Z TM02001 temp 70.32
2020-06-01T00:12:01Z TM02002 temp 70.45
2020-06-01T00:12:02Z TM02003 temp 98.41
sensorID location status
TM02001 SF1.RM406 OK
TM02002 SF1.RM412 OK
TM02003 SF2.RM290 Requires service
© 2020 InfluxData. All rights reserved. 45
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
telemetry = from(bucket: "sensor-data")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp")
assets = sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM temp-sensors"
)
join(tables: {data: telemetry, assets: assets}, on: ["sensorID"])
|> to(org: "my-org", bucket: "enriched-sensor-data")
Enrich data with external data
© 2020 InfluxData. All rights reserved. 46
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
telemetry = from(bucket: "sensor-data")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp")
assets = sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM temp-sensors"
)
join(tables: {data: telemetry, assets: assets}, on: ["sensorID"])
|> to(org: "my-org", bucket: "enriched-sensor-data")
Enrich data with external data
© 2020 InfluxData. All rights reserved. 47
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
telemetry = from(bucket: "sensor-data")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp")
assets = sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM temp-sensors"
)
join(tables: {data: telemetry, assets: assets}, on: ["sensorID"])
|> to(org: "my-org", bucket: "enriched-sensor-data")
Enrich data with external data
© 2020 InfluxData. All rights reserved. 48
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
telemetry = from(bucket: "sensor-data")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp")
assets = sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM temp-sensors"
)
join(tables: {data: telemetry, assets: assets}, on: ["sensorID"])
|> to(org: "my-org", bucket: "enriched-sensor-data")
Enrich data with external data
© 2020 InfluxData. All rights reserved. 49
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
telemetry = from(bucket: "sensor-data")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp")
assets = sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM temp-sensors"
)
join(tables: {data: telemetry, assets: assets}, on: ["sensorID"])
|> to(org: "my-org", bucket: "enriched-sensor-data")
Enrich data with external data
© 2020 InfluxData. All rights reserved. 50
_time sensorID location status _field _value
2020-06-01T00:12:00Z TM02001 SF1 .RM406 OK temp 70.32
2020-06-01T00:12:01Z TM02002 SF1.RM412 OK temp 70.45
2020-06-01T00:12:02Z TM02003 SF2.RM290 Requires service temp 98.41
Data Transfer
© 2020 InfluxData. All rights reserved. 52
© 2020 InfluxData. All rights reserved. 53
import "influxdata/influxdb/secrets"
import "influxdata/influxdb/tasks"
cloudToken = secrets.get(key: "INFLUXDB_CLOUD_TOKEN")
from(bucket: "telemetry")
|> range(start: tasks.lastSuccess(orTime: -task.every))
|> aggregateWindow(every: 5m, fn: mean)
|> to(
host: "https://us-west-2-1.aws.cloud2.influxdata.com",
org: "my-cloud-org",
bucket: "fleet",
token: cloudToken,
)
© 2020 InfluxData. All rights reserved. 54
© 2020 InfluxData. All rights reserved. 55
© 2020 InfluxData. All rights reserved. 56
© 2020 InfluxData. All rights reserved. 57
© 2020 InfluxData. All rights reserved. 58
Other Use Cases
● Data sanitization
● Machine learning
● Reports
● Event triggers
● Data generation
● and much more!!
© 2020 InfluxData. All rights reserved. 59
Thank you!
Time for some Q&A

More Related Content

PPTX
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
PPTX
Taming the Tiger: Tips and Tricks for Using Telegraf
PPTX
Barbara Nelson [InfluxData] | How Can I Put That Dashboard in My App? | Influ...
PPTX
Scott Anderson [InfluxData] | Map & Reduce – The Powerhouses of Custom Flux F...
PDF
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
PDF
JS Fest 2019. Anjana Vakil. Serverless Bebop
PDF
Time Series Meetup: Virtual Edition | July 2020
PDF
INFLUXQL & TICKSCRIPT
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Taming the Tiger: Tips and Tricks for Using Telegraf
Barbara Nelson [InfluxData] | How Can I Put That Dashboard in My App? | Influ...
Scott Anderson [InfluxData] | Map & Reduce – The Powerhouses of Custom Flux F...
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
JS Fest 2019. Anjana Vakil. Serverless Bebop
Time Series Meetup: Virtual Edition | July 2020
INFLUXQL & TICKSCRIPT

What's hot (20)

PDF
Scaling up data science applications
PDF
Flux and InfluxDB 2.0 by Paul Dix
PDF
WattGo: Analyses temps-réél de series temporelles avec Spark et Solr (Français)
PDF
Goal Based Data Production with Sim Simeonov
PDF
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
PDF
RxJS - The Reactive extensions for JavaScript
PPTX
Time Series Analysis for Network Secruity
PDF
InfluxData Platform Future and Vision
PDF
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
PDF
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
PDF
PDF
AJUG April 2011 Cascading example
PPTX
Writing Hadoop Jobs in Scala using Scalding
PPTX
PDF
Hive Functions Cheat Sheet
DOCX
CellCoverage
PPTX
Storm is coming
PDF
RxJS101 - What you need to know to get started with RxJS tomorrow
PDF
Performance Profiling in Rust
PDF
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Scaling up data science applications
Flux and InfluxDB 2.0 by Paul Dix
WattGo: Analyses temps-réél de series temporelles avec Spark et Solr (Français)
Goal Based Data Production with Sim Simeonov
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
RxJS - The Reactive extensions for JavaScript
Time Series Analysis for Network Secruity
InfluxData Platform Future and Vision
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
AJUG April 2011 Cascading example
Writing Hadoop Jobs in Scala using Scalding
Hive Functions Cheat Sheet
CellCoverage
Storm is coming
RxJS101 - What you need to know to get started with RxJS tomorrow
Performance Profiling in Rust
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Ad

Similar to Scott Anderson [InfluxData] | InfluxDB Tasks – Beyond Downsampling | InfluxDays Virtual Experience NA 2020 (20)

PPTX
9:40 am InfluxDB 2.0 and Flux – The Road Ahead Paul Dix, Founder and CTO | ...
PDF
Balaji Palani [InfluxData] | InfluxDB Tasks Overview | InfluxDays 2022
PPTX
Tools for Making Machine Learning more Reactive
PDF
Burn down the silos! Helping dev and ops gel on high availability websites
PPTX
Reactive programming every day
PPTX
Scale 16x: Terraform all the Things
PDF
Bonnes pratiques de développement avec Node js
PDF
Apache Spark for Library Developers with William Benton and Erik Erlandson
PDF
Monitoring with Prometheus
PDF
Flask patterns
PDF
TDC2018SP | Trilha Go - Processando analise genetica em background com Go
PDF
CAVE Overview
PDF
mobl - model-driven engineering lecture
DOCX
R (Shiny Package) - Server Side Code for Decision Support System
PDF
Emerging Languages: A Tour of the Horizon
PDF
Artimon - Apache Flume (incubating) NYC Meetup 20111108
PPTX
Exactly once with spark streaming
PDF
Analytics with Spark
PDF
Play vs Rails
PPTX
Terraform at Scale
9:40 am InfluxDB 2.0 and Flux – The Road Ahead Paul Dix, Founder and CTO | ...
Balaji Palani [InfluxData] | InfluxDB Tasks Overview | InfluxDays 2022
Tools for Making Machine Learning more Reactive
Burn down the silos! Helping dev and ops gel on high availability websites
Reactive programming every day
Scale 16x: Terraform all the Things
Bonnes pratiques de développement avec Node js
Apache Spark for Library Developers with William Benton and Erik Erlandson
Monitoring with Prometheus
Flask patterns
TDC2018SP | Trilha Go - Processando analise genetica em background com Go
CAVE Overview
mobl - model-driven engineering lecture
R (Shiny Package) - Server Side Code for Decision Support System
Emerging Languages: A Tour of the Horizon
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Exactly once with spark streaming
Analytics with Spark
Play vs Rails
Terraform at Scale
Ad

More from InfluxData (20)

PPTX
Announcing InfluxDB Clustered
PDF
Best Practices for Leveraging the Apache Arrow Ecosystem
PDF
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
PDF
Power Your Predictive Analytics with InfluxDB
PDF
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
PDF
Build an Edge-to-Cloud Solution with the MING Stack
PDF
Meet the Founders: An Open Discussion About Rewriting Using Rust
PDF
Introducing InfluxDB Cloud Dedicated
PDF
Gain Better Observability with OpenTelemetry and InfluxDB
PPTX
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
PDF
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
PPTX
Introducing InfluxDB’s New Time Series Database Storage Engine
PDF
Start Automating InfluxDB Deployments at the Edge with balena
PDF
Understanding InfluxDB’s New Storage Engine
PDF
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
PPTX
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
PDF
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Announcing InfluxDB Clustered
Best Practices for Leveraging the Apache Arrow Ecosystem
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
Power Your Predictive Analytics with InfluxDB
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
Build an Edge-to-Cloud Solution with the MING Stack
Meet the Founders: An Open Discussion About Rewriting Using Rust
Introducing InfluxDB Cloud Dedicated
Gain Better Observability with OpenTelemetry and InfluxDB
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
Introducing InfluxDB’s New Time Series Database Storage Engine
Start Automating InfluxDB Deployments at the Edge with balena
Understanding InfluxDB’s New Storage Engine
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Scott Anderson [InfluxData] | InfluxDB Tasks – Beyond Downsampling | InfluxDays Virtual Experience NA 2020

  • 1. Scott Anderson Senior Technical Writer & Technical Lead of the Docs team @ InfluxData InfluxDB Tasks Beyond Downsampling
  • 2. © 2020 InfluxData. All rights reserved. 2 What is an InfluxDB task? A scheduled Flux script
  • 3. © 2020 InfluxData. All rights reserved. 3 Why tasks? ● Automate repeated operations ● A replacement for Continuous Queries (CQs) in InfluxDB Cloud and InfluxDB 2.0
  • 4. © 2020 InfluxData. All rights reserved. 4 Downsampling cascade
  • 5. © 2020 InfluxData. All rights reserved. 5 CREATE CONTINUOUS QUERY "downsample-daily" ON "my-db" BEGIN SELECT mean("example-field") INTO "average-example-measurement" FROM "example-measurement" GROUP BY time(1h) END
  • 6. © 2020 InfluxData. All rights reserved. 6 from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every) |> filter(fn: (r) => r._measurement == "example-m" and r._field == "value" ) |> aggregateWindow(every: 1h, fn: mean()) |> to(bucket: "downsampled-daily", org: "my-org")
  • 7. © 2020 InfluxData. All rights reserved. 7 Downsampling InfluxDB Template github.com/influxdata/community-templates
  • 8. © 2020 InfluxData. All rights reserved. 8
  • 9. © 2020 InfluxData. All rights reserved. 9
  • 10. and the potential of Flux BEYOND Downsampling
  • 12. © 2020 InfluxData. All rights reserved. 12
  • 13. © 2020 InfluxData. All rights reserved. 13 import "influxdata/influxdb/monitor" import "influxdata/influxdb/tasks" import "influxdata/influxdb/v1" check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}} task_data = from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every), stop: now()) |> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem") |> mean() ok = (r) => r._value <= 60.0 crit = (r) => r._value > 95.0 warn = (r) => r._value > 80.0 and r._value <= 95.0 info = (r) => r._value > 60.0 and r._value <= 80.0 messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.") task_data |> v1.fieldsAsCols() |> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info) System-generated check task
  • 14. © 2020 InfluxData. All rights reserved. 14 import "influxdata/influxdb/monitor" import "influxdata/influxdb/tasks" import "influxdata/influxdb/v1" check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}} task_data = from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every), stop: now()) |> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem") |> mean() ok = (r) => r._value <= 60.0 crit = (r) => r._value > 95.0 warn = (r) => r._value > 80.0 and r._value <= 95.0 info = (r) => r._value > 60.0 and r._value <= 80.0 messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.") task_data |> v1.fieldsAsCols() |> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info) System-generated check task
  • 15. © 2020 InfluxData. All rights reserved. 15 import "influxdata/influxdb/monitor" import "influxdata/influxdb/tasks" import "influxdata/influxdb/v1" check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}} task_data = from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every), stop: now()) |> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem") |> mean() ok = (r) => r._value <= 60.0 crit = (r) => r._value > 95.0 warn = (r) => r._value > 80.0 and r._value <= 95.0 info = (r) => r._value > 60.0 and r._value <= 80.0 messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.") task_data |> v1.fieldsAsCols() |> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info) System-generated check task
  • 16. © 2020 InfluxData. All rights reserved. 16
  • 17. © 2020 InfluxData. All rights reserved. 17 import "influxdata/influxdb/monitor" import "influxdata/influxdb/tasks" import "influxdata/influxdb/v1" check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}} task_data = from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every), stop: now()) |> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem") |> mean() ok = (r) => r._value <= 60.0 crit = (r) => r._value > 95.0 warn = (r) => r._value > 80.0 and r._value <= 95.0 info = (r) => r._value > 60.0 and r._value <= 80.0 messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.") task_data |> v1.fieldsAsCols() |> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info) System-generated check task
  • 18. © 2020 InfluxData. All rights reserved. 18 import "influxdata/influxdb/monitor" import "influxdata/influxdb/tasks" import "influxdata/influxdb/v1" check = {_check_id: "00000000deadbeef", _check_name: "Average memory monitor", _type: "threshold", tags: {}} task_data = from(bucket: "my-bucket") |> range(start: tasks.lastSuccess(orTime: -task.every), stop: now()) |> filter(fn: (r) => r._measurement == "telegraf" and r._field == "mem") |> mean() ok = (r) => r._value <= 60.0 crit = (r) => r._value > 95.0 warn = (r) => r._value > 80.0 and r._value <= 95.0 info = (r) => r._value > 60.0 and r._value <= 80.0 messageFn = (r) => ("Average mem check: ${r.host}'s average memory usage is ${r._value}%.") task_data |> v1.fieldsAsCols() |> monitor.check(data: check, messageFn: messageFn, ok: ok, crit: crit, warn: warn, info: info) System-generated check task
  • 19. © 2020 InfluxData. All rights reserved. 19
  • 20. © 2020 InfluxData. All rights reserved. 20 import "influxdata/influxdb/monitor" import "influxdata/influxdb/slack" endpoint = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "SLACK_TOKEN") ) monitor.from( start: -task.every, fn: (r) => r._level == "crit" ) |> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))() System-generated notification task
  • 21. © 2020 InfluxData. All rights reserved. 21 import "influxdata/influxdb/monitor" import "influxdata/influxdb/slack" endpoint = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "SLACK_TOKEN") ) monitor.from( start: -task.every, fn: (r) => r._level == "crit" ) |> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))() System-generated notification task
  • 22. © 2020 InfluxData. All rights reserved. 22 import "influxdata/influxdb/monitor" import "influxdata/influxdb/slack" endpoint = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "SLACK_TOKEN") ) monitor.from( start: -task.every, fn: (r) => r._level == "crit" ) |> endpoint(mapFn: (r) => ({ r with channel: "alerts", text: r.message, color: "danger"}))() System-generated notification task
  • 23. © 2020 InfluxData. All rights reserved. 23 *
  • 24. Simple Custom Alerts Send alerts without using InfluxDB checks & notifications
  • 25. © 2020 InfluxData. All rights reserved. 25 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 26. © 2020 InfluxData. All rights reserved. 26 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 27. © 2020 InfluxData. All rights reserved. 27 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 28. © 2020 InfluxData. All rights reserved. 28 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 29. © 2020 InfluxData. All rights reserved. 29 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 30. © 2020 InfluxData. All rights reserved. 30 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert
  • 31. © 2020 InfluxData. All rights reserved. 31 import "influxata/influxdb/tasks" import "influxata/influxdb/slack" import anomaly "contrib/anaisdg/anomalydetection" toSlack = slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: secrets.get(key: "SLACK_TOKEN") ) from(bucket: "example") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> filter(fn: (r) => r._measurement == "m") |> anomaly.mad() |> filter(fn: (r) => r.level == "anomaly") |> toSlack( mapFn: (r) => { r with channel: "anomalies", text: "An anomaly has been detected on ${r.host}. ${r._field} is ${r._value}", color: "danger" } )() Custom anomaly detection alert Execute generated function
  • 33. © 2020 InfluxData. All rights reserved. 33 import "csv" csvData = "#datatype,string,long,dateTime:RFC3339,string,double #group,false,false,false,true,false #default,,,,, ,result,table,_time,region,_value ,,0,2018-05-08T20:50:00Z,east,15.43 ,,0,2018-05-08T20:50:20Z,east,59.25 ,,1,2018-05-08T20:50:00Z,west,62.73 " csv.from(csv:csvData) |> to(org: "my-org", bucket: "my-bucket") Write data using annotated CSV
  • 34. © 2020 InfluxData. All rights reserved. 34 import "experimental/csv" csv.from(url: "https://influx-testdata.s3.amazonaws.com/noaa.csv") |> to(org: "my-org", bucket: "noaa") Write data using remote annotated CSV
  • 35. © 2020 InfluxData. All rights reserved. 35 import "experimental/array" data = [ {_time: 2018-05-08T20:50:00Z, region: "east", _value: 15.43}, {_time: 2018-05-08T20:50:20Z, region: "east", _value: 59.25}, {_time: 2018-05-08T20:50:00Z, region: "west", _value: 62.73} ] array.from(rows: data) |> to(org: "my-org", bucket: "my-bucket") Write data with using an array of records
  • 36. © 2020 InfluxData. All rights reserved. 36 // ... response = http.get( url: "http://localhost:8086/health", headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"} ) responseBody = response.body seedRow = [{_time: now()}] array.from(rows: seedRow) |> map(fn: (r) => { body = json.parse(data: responseBody) return { r with _measurement: "monitoring", _field: "influxdb_status", _value: body.message, name: body.name } }) |> to(org: "my-org", bucket: "my-bucket") Write data with using an HTTP response
  • 37. © 2020 InfluxData. All rights reserved. 37 // ... response = http.get( url: "http://localhost:8086/health", headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"} ) responseBody = response.body seedRow = [{_time: now()}] array.from(rows: seedRow) |> map(fn: (r) => { body = json.parse(data: responseBody) return { r with _measurement: "monitoring", _field: "influxdb_status", _value: body.message, name: body.name } }) |> to(org: "my-org", bucket: "my-bucket") Write data with using an HTTP response
  • 38. © 2020 InfluxData. All rights reserved. 38 // ... response = http.get( url: "http://localhost:8086/health", headers: {Authorization: "Token mYsuP3rS3cRe7T0kEn"} ) responseBody = response.body seedRow = [{_time: now()}] array.from(rows: seedRow) |> map(fn: (r) => { body = json.parse(data: responseBody) return { r with _measurement: "monitoring", _field: "influxdb_status", _value: body.message, name: body.name } }) |> to(org: "my-org", bucket: "my-bucket") Write data with using an HTTP response
  • 39. © 2020 InfluxData. All rights reserved. 39
  • 40. © 2020 InfluxData. All rights reserved. 40 import "experimental/prometheus" prometheus.scrape(url: "http://localhost:8086/metrics") |> to( org: "my-org", bucket: "my-bucket" ) Scrape data from a Prometheus endpoint
  • 41. © 2020 InfluxData. All rights reserved. 41 import "influxdata/influxdb/secrets" import "sql" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM example_table" ) Query a SQL datasource
  • 43. © 2020 InfluxData. All rights reserved. 43 join()
  • 44. © 2020 InfluxData. All rights reserved. 44 _time sensorID _field _value 2020-06-01T00:12:00Z TM02001 temp 70.32 2020-06-01T00:12:01Z TM02002 temp 70.45 2020-06-01T00:12:02Z TM02003 temp 98.41 sensorID location status TM02001 SF1.RM406 OK TM02002 SF1.RM412 OK TM02003 SF2.RM290 Requires service
  • 45. © 2020 InfluxData. All rights reserved. 45 import "sql" import "influxdata/influxdb/secrets" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") telemetry = from(bucket: "sensor-data") |> range(start: -task.every) |> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp") assets = sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM temp-sensors" ) join(tables: {data: telemetry, assets: assets}, on: ["sensorID"]) |> to(org: "my-org", bucket: "enriched-sensor-data") Enrich data with external data
  • 46. © 2020 InfluxData. All rights reserved. 46 import "sql" import "influxdata/influxdb/secrets" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") telemetry = from(bucket: "sensor-data") |> range(start: -task.every) |> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp") assets = sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM temp-sensors" ) join(tables: {data: telemetry, assets: assets}, on: ["sensorID"]) |> to(org: "my-org", bucket: "enriched-sensor-data") Enrich data with external data
  • 47. © 2020 InfluxData. All rights reserved. 47 import "sql" import "influxdata/influxdb/secrets" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") telemetry = from(bucket: "sensor-data") |> range(start: -task.every) |> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp") assets = sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM temp-sensors" ) join(tables: {data: telemetry, assets: assets}, on: ["sensorID"]) |> to(org: "my-org", bucket: "enriched-sensor-data") Enrich data with external data
  • 48. © 2020 InfluxData. All rights reserved. 48 import "sql" import "influxdata/influxdb/secrets" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") telemetry = from(bucket: "sensor-data") |> range(start: -task.every) |> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp") assets = sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM temp-sensors" ) join(tables: {data: telemetry, assets: assets}, on: ["sensorID"]) |> to(org: "my-org", bucket: "enriched-sensor-data") Enrich data with external data
  • 49. © 2020 InfluxData. All rights reserved. 49 import "sql" import "influxdata/influxdb/secrets" username = secrets.get(key: "POSTGRES_USER") password = secrets.get(key: "POSTGRES_PASS") telemetry = from(bucket: "sensor-data") |> range(start: -task.every) |> filter(fn: (r) => r._measurement == "sensor-data" and r._field == "temp") assets = sql.from( driverName: "postgres", dataSourceName: "postgresql://${username}:${password}@localhost", query:"SELECT * FROM temp-sensors" ) join(tables: {data: telemetry, assets: assets}, on: ["sensorID"]) |> to(org: "my-org", bucket: "enriched-sensor-data") Enrich data with external data
  • 50. © 2020 InfluxData. All rights reserved. 50 _time sensorID location status _field _value 2020-06-01T00:12:00Z TM02001 SF1 .RM406 OK temp 70.32 2020-06-01T00:12:01Z TM02002 SF1.RM412 OK temp 70.45 2020-06-01T00:12:02Z TM02003 SF2.RM290 Requires service temp 98.41
  • 52. © 2020 InfluxData. All rights reserved. 52
  • 53. © 2020 InfluxData. All rights reserved. 53 import "influxdata/influxdb/secrets" import "influxdata/influxdb/tasks" cloudToken = secrets.get(key: "INFLUXDB_CLOUD_TOKEN") from(bucket: "telemetry") |> range(start: tasks.lastSuccess(orTime: -task.every)) |> aggregateWindow(every: 5m, fn: mean) |> to( host: "https://us-west-2-1.aws.cloud2.influxdata.com", org: "my-cloud-org", bucket: "fleet", token: cloudToken, )
  • 54. © 2020 InfluxData. All rights reserved. 54
  • 55. © 2020 InfluxData. All rights reserved. 55
  • 56. © 2020 InfluxData. All rights reserved. 56
  • 57. © 2020 InfluxData. All rights reserved. 57
  • 58. © 2020 InfluxData. All rights reserved. 58 Other Use Cases ● Data sanitization ● Machine learning ● Reports ● Event triggers ● Data generation ● and much more!!
  • 59. © 2020 InfluxData. All rights reserved. 59 Thank you! Time for some Q&A