Skip to content

Instantly share code, notes, and snippets.

@ericxyan
Last active April 27, 2016 20:45
Show Gist options
  • Select an option

  • Save ericxyan/996bebef5834cda14c7e8e1ace2ffcfd to your computer and use it in GitHub Desktop.

Select an option

Save ericxyan/996bebef5834cda14c7e8e1ace2ffcfd to your computer and use it in GitHub Desktop.

Time Series Data

What is Time series data?

What is TSDB(Time Series Database)?

TSDB

  • InfluxDB
  • OpenTSDB
  • KDB+
  • Graphite
  • Riak TS

Why use TSDB?

Default functions.

InfluxDB

  • Easy to get started with
  • Familiar query syntax
  • No external dependencies
  • Allow regular/irregular
  • Horizontally scalable
  • Member of a cohesive time series platform

InfluxDB Data Model

  • Label(title): measurement
  • Legend(metadata): Tags, indexed, Tagset
  • y-axis: fields(floats, ints, string, bools), fieldset
  • x-axis: timestamp

LIne Protocol

measurement, tagset fieldset timestamp
Example:
stock_price,ticker=A,market=NASDAQ price=177.03 14452992000000000

Series

measurement + tagset = the series as whole

InfluxQL Basice

Similar to SQL

Meta Queries

SHOW DATABASES 
SHOW SERIES
SHOW MEASUREMENTS
SHOW TAG KEYS
SHOW FIELD KEYS

Queries

CREATE DATABASE IF NOT EXISTS mydb
USE mydb
INSERT cpu,host=server2,location=us-west value=12
# CURL https://s3-us-west-2.amazonaws.com/influx-sample-data/NOAA.txt
influx -import -path=NOAA.txt -precision=s
PRECISION RFC3339
SELECT <field> FROM <measurement> LIMIT <Int>
# SELECT * FROM cpu
# SELECT free FROM mem
# SELECT x + y FROM vars
# SELECT x,y FROM nums
SELECT <field> FROM <measurement> WHERE <conditions>
# SELECT * FROM mem WHERE some_tag = 'some_key'
# SELECT * FROM nums WHERE domain =~ /.*/

Select statement with Relative Time

SELECT FROM WHERE

SELECT * FROM cpu WHERE time > now() - 1h/10s/4d/10w/15m

Select statement with Absolute Time

Absolute time cam be specified in two ways

  • Date Time: YYYY-MM-DD HH:MM:SS.nnnnnnnnn (RFC 3339)
  • Epoch: number of nanoseconds since January 1, 1970

SELECT * FROM cpu WHERE time > '2015-08-18 23:00:01'/'2015-0-19'/'2015-08-18T23:00:01.23200000Z'/1388534400s

Select statement with ORDER BY time

SELECT * FROM cpu WHERE time > now() - 1h ORDER BY time DESC

Select statement with Conjunction

SELECT FROM WHERE < conditions> [AND | OR]

Select statement with GROUP BY Clause

[SELECT STATEMENT] GROUP BY
SELECT * FROM cpu GROUP BY *
SELECT * FROM cpu GROUP BY host

Functions

3 major types

  • Aggregators
  • Selectors
  • Transformers

Aggregators

SELECT () FROM [extra]

  • count()
  • distinct()
  • integral()
  • mean()
  • median()
  • spread()
  • sum()
  • stddev()

SELECT mean(free) FROM mem WHERE time > now() - 1h

SELCET max(busy) FROM cpu WHERE time > now() - 1h GROUP BY time(10m)

Selectors

SELECT () FROM [extra]

  • bottom()
  • first()
  • last()
  • max()
  • min()
  • percentile()
  • top()

Transformers

SELECT () FROM [extra]

  • derivative()
  • non_negative_derivative()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment