Weitere ähnliche Inhalte Ähnlich wie Sensor Data in InfluxDB by David Simmons, IoT Developer Evangelist | InfluxData (20) Kürzlich hochgeladen (20) Sensor Data in InfluxDB by David Simmons, IoT Developer Evangelist | InfluxData2. © 2018 InfluxData. All rights reserved. @davidgsIoT
Where To collect your IoT Data?
•Distributed collection vs. Centralized
collection
•How is the data used
•Who uses the data
3. © 2018 InfluxData. All rights reserved. @davidgsIoT
Collect it in the cloud
•All data flows directly to the cloud
•Requires highly available network
–Low latency
–No down-time
•Analysis and visualization from anywhere
4. © 2018 InfluxData. All rights reserved. @davidgsIoT
Collect it at the edge
•Collect close to the sensor
•Unreliable back-haul network
•Local processing and analysis
5. © 2018 InfluxData. All rights reserved. @davidgsIoT
Distributed data collection
•Data collected at multiple collections points
•Remote collection points feed back-end
system of record
•Distributes data collection load
•More tolerant of network outages, etc.
6. © 2018 InfluxData. All rights reserved. @davidgsIoT
Data Layer Architecture
•Data collected at the edge, where it’s generated
•Edge collectors also capable of analysis
•Edge collectors handle local event, etc.
•Down-sampled data forwarded to backend on a
network-available basis
–Lower network costs
–More fault tolerant
7. © 2018 InfluxData. All rights reserved.
InfluxData
• Telegraf
• Data Collection
• InfluxDB
• Short-term storage
• Long-term storage
• Kapacitor
• Local Alerts
• System-wide alerts
• Chronograf
• Dashboards
8. © 2018 InfluxData. All rights reserved. @davidgsIoT
How does InfluxData help?
• Extremely efficient data collection
• High-volume data collection
• IoT generates huge volumes of data very quickly
• Being able to ingest, analyze and query that data is key to IoT success
• Ease of Deployment
• Easy to deploy InfluxDB and the TICK stack for data collection, analysis
and action
• Very low time to value – Time To Awesome™
• Dashboards and visualization
• Easy to build useful, easy to read dashboards.
11. © 2018 InfluxData. All rights reserved. @davidgsIoT
What is flux?
Flux is a functional data scripting and query language
• Written to be:
– Useable
– Readable
– Composeable
– Testable
– Contributable
– Shareable
• JavaScript-esque
• MIT Licensed
12. © 2018 InfluxData. All rights reserved. @davidgsIoT
InfluxData as the IoT Data Platform
• What is IoT Data?
– sensor@time – that’s time series data!
• IoT data MUST be
– Timely – ingestion rates and query efficiency is key
– Accurate – data integrity and platform reliability is important
– Actionable – data visualization, anomaly detection & alerting are essential
• IoT deployments are struggling to find efficient, scalable, data
platform that meets all of these criteria
• The InfluxData Platform meets them all
13. © 2018 InfluxData. All rights reserved. @davidgsIoT
Download and Install
• Docker:
• Run
• Setup
http://localhost:9999
docker pull quay.io/influxdb/influxdb:2.0.0-alpha
docker run --name influxdb -p 9999:9999 quay.io/influxdb/influxdb:2.0.0-alpha
14. © 2018 InfluxData. All rights reserved. @davidgsIoT
Download and Install
• Download MacOS:
• Download Linux
• Uncompress
• Run
tar zxvf influxdb_2.0.0-alpha.9_*.tar.gz
https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-alpha.9_darwin_amd64.tar.gz
wget https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-alpha.9_linux_amd64.tar.gz
cd influxdb_2*; ./influxd
15. © 2018 InfluxData. All rights reserved. @davidgsIoT
Influx 2.0 Cloud
https://cloud2.influxdata.com/beta/signup
24. © 2018 InfluxData. All rights reserved. @davidgsIoT
A Word About Tokens
• As of 2.0, security is on by default
• It can’t be turned off
• All access is token-based
• Must have a token to read or write data
• Every request to InfluxDB must include the token
25. © 2018 InfluxData. All rights reserved. @davidgsIoT
But Wait, we didn’t install Telegraf!
26. © 2018 InfluxData. All rights reserved. @davidgsIoT
Install and start Telegraf
• Mac OS:
• Linux
• All
brew install telegraf; brew enable telegraf
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/
apt/sources.list.d/influxdb.list
export INFLUX_TOKEN=<TOKEN>
telegraf --config http://localhost:9999/api/v2/telegrafs/
31. © 2018 InfluxData. All rights reserved. @davidgsIoT
Writing Queries
• InfluxQL is dead
• Long live Flux!
• TICK Script is dead!
• Long live Tasks!
No one will miss TICK Script
32. © 2018 InfluxData. All rights reserved. @davidgsIoT
What is flux?
Flux is a functional data scripting and query language
• Written to be:
– Useable
– Readable
– Composeable
– Testable
– Contributable
– Shareable
• JavaScript-esque
• MIT Licensed
33. © 2018 InfluxData. All rights reserved. @davidgsIoT
Key Terms and Terminology
• Bucket: Named data source with retention policy
• Pipe-forward operator: Used to chain operation together in flux
|>
• Table: Data is returned in annotated CSVs, represented as tables
• Group key: list of columns for which every row in the table has
the same value
34. © 2018 InfluxData. All rights reserved. @davidgsIoT
Flux Query Example
from(bucket:"telegraf/autogen")
|> range(start: -1h)
|> filter(fn: (r) =>
r.measurement == “cpu” AND
r.field == “usage_system” AND
r.cpu == “cpu_total”
|> yield()
35. © 2018 InfluxData. All rights reserved. @davidgsIoT
What is a Task?
• Written in Flux
• Run at configurable intervals
• Completes a flux query and does ‘something’ with the result
38. © 2018 InfluxData. All rights reserved. @davidgsIoT
Task Example
import "mqtt"
option task = {name: "Gas", every: 4s, offset: 4s}
from(bucket: "telegraf")
|> range(start: -task.every)
|> filter(fn: (r) => (r._measurement == "k30_reader"))
|> filter(fn: (r) => (r._field == "co2"))
|> last()
|> mqtt.to(
broker: "tcp://davidgs.com:8883",
topic: "gas",
clientid: "gas-flux",
format: "JSON",
valueColumns: ["_value"],
)
39. © 2018 InfluxData. All rights reserved. @davidgsIoT
Sending Data to InfluxDB
• Remember, everything needs a token!
• Using Telegraf
• Using native libraries
40. © 2018 InfluxData. All rights reserved. @davidgsIoT
Telegraf and MQTT
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
qos = 0
connection_timeout = “30s"
username = “myUsername”
password = “MySecret”
topics = [ "/toNet", "/fromNet" ]
client_id = ""
data_format = "json"
insecure_skip_verify = true
41. © 2018 InfluxData. All rights reserved. @davidgsIoT
Arduino Native
#include <InfluxDb.h>
#define INFLUXDB_HOST “myhost.com”
#define BATCH_SIZE 10
Influxdb influx(INFLUXDB_HOST);
void setup() {
influx.setBucket("myBucket");
influx.setVersion(2);
influx.setOrg("myOrg");
influx.setPort(9999);
influx.setToken("MyLongTokenString==");
}
42. © 2018 InfluxData. All rights reserved. @davidgsIoT
Batch Writing
getReadings(); // read the sensors
int rssi = WiFi.RSSI();
if (batchCount >= BATCH_SIZE) {
influx.write();
batchCount = 0;
}
int power = analogRead(POWER_PIN) * 2;
InfluxData row("environment");
row.addTag("location", myName.c_str());
row.addValue("temp_c", temperature);
row.addValue("humidity", humidity);
row.addValue("pressure", pressure);
row.addValue("battery", power);
row.addValue("RSSI", rssi);
influx.prepare(row);
batchCount += 1;