-
Notifications
You must be signed in to change notification settings - Fork 31
InfluxDB 101
> curl -G 'https://scala-ci.typesafe.com/influx/query?pretty=true' --data-urlencode "u=scala" --data-urlencode "p=<>" --data-urlencode "db=scala_benchmark" --data-urlencode "q=SELECT * FROM result WHERE time > now() - 1d"
...
> ssh [email protected]
> influx -username scala -password <>
> use scala_benchmark
> SELECT * FROM result WHERE time > now() - 1d
...
> ssh [email protected] -L 8086:localhost:8086 -N &
> ssh [email protected] -L 8083:localhost:8083 -N &
Open http://localhost:8083. Host: localhost
, port: 8086
, no SSL.
In principle, it should work without the first tunnel (host: scala-ci.typesafe.com/influx
, port: 443
, with SSL), but I couldn't get it to work.
Try with query SELECT * FROM result WHERE time > now() - 1d
.
Measurement
- Similar to an sql table
- Examples in
scala_benchmark
:result
,commit
- Query:
SHOW MEASUREMENTS
Tags
- Similar to an indexed column in sql
- Examples:
benchmark
,branch
,source
, ... - Use for commonly queried meta-data
- Tag values are always strings
- Queries:
SHOW TAG KEYS FROM result
,SHOW TAG VALUES FROM result WITH KEY = benchmark
Fields
- Similar to non-indexed columns in sql
- Data and metadata
- Examples:
javaVersion
,score
, ... - Query:
SHOW FIELD KEYS FROM result
Point
- A data entry, similar to a row in sql
- Contains a timestamp, values for all tag keys, values for some field keys (sparse)
Series
- A measurement with a unique "tag set" (a set of tag key-value pairs)
- Example:
result,benchmark=HotScalacBenchmark.compile,branch=2.12.x,source=better-files
Writing the same (measurement,timestamp,tagSet)
twice overwrites the existing point. We can exploit this to re-run a benchmark.
https://docs.influxdata.com/influxdb/v1.2/query_language/data_exploration/
- A query requires at least one field key in the
SELECT
clause to return data - Tag and field keys can be quoted in double quotes (if necessary)
- String literals need to be in single quotes
- Example:
SELECT * FROM result WHERE "benchmark" = 'HotScalacBenchmark.compile' LIMIT 5
- Example:
- Regex matching:
WHERE tagName =~ /regex/
- Query by time:
SELECT * FROM result WHERE time > now() - 7d
-
now()
is the current time in nanoseconds
-
InfluxDB is a schemaless database: measurements, tags, and fields are created on demand.
Write commands
- https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/
- Example:
'result,benchmark=<>,branch=<>... javaVersion=<>,score=<>,... 1434055562000000000'
Types
- Measurements, tag keys, tag values and field keys are strings. Don't double-quote!
- If a tag is not provided, its value is
''
. If a write introduces a new tag, all existing points get tag value''
.
- If a tag is not provided, its value is
- Timestamps are unix timestamps in nanos (
365199550781253
) - Types for field values:
-
1
,1.0
areDouble
-
1i
isInt
-
t
,F
,true
,False
,TRUE
areBoolean
-
"s"
isString
-
Writing with curl
curl -i -XPOST 'https://scala-ci.typesafe.com/influx/write?db=scala_benchmark' --data-binary 'result,benchmark=<>,branch=<>... javaVersion=<>,score=<>,... 1434055562000000000'
SELECT * INTO new_name FROM old_name GROUP BY *
-
GROUP BY *
is important to preserve tags as tags, otherwise they are converted to fields which causes data loss. - http://docs.influxdata.com/influxdb/v1.2/query_language/data_exploration/#common-issues-with-the-into-clause
- http://docs.influxdata.com/influxdb/v1.2/troubleshooting/frequently-asked-questions/#why-are-my-into-queries-missing-data
- https://github.com/influxdata/influxdb/issues/4155#issuecomment-268719194
Delete one or multiple series from a measurement: DROP SERIES
- Can be used to drop a tag that's no longer in use
Delete an entire measurement: DROP MEASUREMENT
Fields cannot be deleted, need to copy into a new measurement