added influxdb v1 functions package

pull/50/head
Scott Anderson 2019-02-07 18:47:12 -07:00
parent de96dd5bc3
commit 1274d9e38b
7 changed files with 275 additions and 10 deletions

View File

@ -10,7 +10,8 @@ menu:
weight: 202 weight: 202
--- ---
InfluxDB v1 Flux functions provide tools for managing data from an InfluxDB v1.x database. InfluxDB v1 Flux functions provide tools for managing data from an InfluxDB v1.x
database or structured using the InfluxDB v1 data structure.
To use them, import the `influxdata/influxdb/v1` package: To use them, import the `influxdata/influxdb/v1` package:
```js ```js

View File

@ -1,37 +1,41 @@
--- ---
title: influxFieldsAsCols() function title: v1.fieldsAsCols() function
description: The influxFieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp. description: The v1.fieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp.
aliases: aliases:
- /v2.0/reference/flux/functions/inputs/fromrows - /v2.0/reference/flux/functions/inputs/fromrows
- /v2.0/reference/flux/functions/transformations/influxfieldsascols - /v2.0/reference/flux/functions/transformations/influxfieldsascols
menu: menu:
v2_0_ref: v2_0_ref:
name: influxFieldsAsCols name: v1.fieldsAsCols
parent: built-in-transformations parent: InfluxDB v1
weight: 401 weight: 301
--- ---
The `influxFieldsAsCols()` function is a special application of the `pivot()` function that The `v1.fieldsAsCols()` function is a special application of the `pivot()` function that
automatically aligns fields within each input table that have the same timestamp. automatically aligns fields within each input table that have the same timestamp.
_**Function type:** Transformation_ _**Function type:** Transformation_
```js ```js
influxFieldsAsCols() import "influxdata/influxdb/v1"
v1.fieldsAsCols()
``` ```
## Examples ## Examples
```js ```js
import "influxdata/influxdb/v1"
from(bucket:"telegraf/autogen") from(bucket:"telegraf/autogen")
|> range(start: -1h) |> range(start: -1h)
|> filter(fn: (r) => r._measurement == "cpu") |> filter(fn: (r) => r._measurement == "cpu")
|> influxFieldsAsCols() |> v1.fieldsAsCols()
|> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"]) |> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"])
``` ```
## Function definition ## Function definition
```js ```js
influxFieldsAsCols = (tables=<-) => fieldsAsCols = (tables=<-) =>
tables tables
|> pivot( |> pivot(
rowKey:["_time"], rowKey:["_time"],

View File

@ -0,0 +1,31 @@
---
title: v1.measurements() function
description: The v1.measurements() function returns a list of measurements in a specific bucket.
menu:
v2_0_ref:
name: v1.measurements
parent: InfluxDB v1
weight: 301
---
The `v1.measurements()` function returns a list of measurements in a specific bucket.
The return value is always a single table with a single column, `_value`.
```js
import "influxdata/influxdb/v1"
v1.measurements(bucket: "example-bucket")
```
## Parameters
### bucket
The bucket from which to list measurements.
_**Data type:** String_
## Function definition
```js
measurements = (bucket) =>
tagValues(bucket: bucket, tag: "_measurement")
```

View File

@ -0,0 +1,41 @@
---
title: v1.measurementTagKeys() function
description: The v1.measurementTagKeys() function returns a list of tag keys for a specific measurement.
menu:
v2_0_ref:
name: v1.measurementTagKeys
parent: InfluxDB v1
weight: 301
---
The `v1.measurementTagKeys()` function returns a list of tag keys for a specific measurement.
The return value is always a single table with a single column, `_value`.
```js
import "influxdata/influxdb/v1"
v1.measurementTagKeys(
bucket: "example-bucket",
measurement: "cpu"
)
```
## Parameters
### bucket
The bucket from which to return tag keys for a specific measurement.
_**Data type:** String_
### measurement
The measurement from which to return tag keys.
_**Data type:** String_
## Function definition
```js
measurementTagKeys = (bucket, measurement) =>
tagKeys(
bucket: bucket,
predicate: (r) => r._measurement == measurement)
```

View File

@ -0,0 +1,52 @@
---
title: v1.measurementTagValues() function
description: The v1.measurementTagValues() function returns a list of tag values for a specific measurement.
menu:
v2_0_ref:
name: v1.measurementTagValues
parent: InfluxDB v1
weight: 301
---
The `v1.measurementTagValues()` function returns a list of tag values for a specific measurement.
The return value is always a single table with a single column, `_value`.
```js
import "influxdata/influxdb/v1"
v1.measurementTagValues(
bucket: "example-bucket",
measurement: "cpu",
tag: "host"
)
```
## Parameters
### bucket
The bucket from which to return tag values for a specific measurement.
_**Data type:** String_
### measurement
The measurement from which to return tag values.
_**Data type:** String_
### tag
The tag from which to return all unique values.
_**Data type:** String_
## Function definition
```js
measurementTagValues = (bucket, measurement, tag) =>
tagValues(
bucket: bucket,
tag: tag,
predicate: (r) => r._measurement == measurement
)
```

View File

@ -0,0 +1,63 @@
---
title: v1.tagKeys() function
description: The v1.tagKeys() function returns a list of tag keys for all series that match the predicate.
menu:
v2_0_ref:
name: v1.tagKeys
parent: InfluxDB v1
weight: 301
---
The `v1.tagKeys()` function returns a list of tag keys for all series that match the [`predicate`](#predicate).
The return value is always a single table with a single column, `_value`.
```js
import "influxdata/influxdb/v1"
v1.tagKeys(
bucket: "example-bucket",
predicate: (r) => true,
start: -30d
)
```
## Parameters
### bucket
The bucket from which to list tag keys.
_**Data type:** String_
### predicate
The predicate function that filters tag keys.
_Defaults to `(r) => true`._
_**Data type:** Function_
### start
Specifies the oldest time to be included in the results.
_Defaults to `-30d`._
Relative start times are defined using negative durations.
Negative durations are relative to now.
Absolute start times are defined using timestamps.
_**Data type:** Duration_
## Examples
```js
import "influxdata/influxdb/v1"
v1.tagKeys(bucket: "my-bucket")
```
## Function definition
```js
tagKeys = (bucket, predicate=(r) => true, start=-30d) =>
from(bucket: bucket)
|> range(start: start)
|> filter(fn: predicate)
|> keys()
|> keep(columns: ["_value"])
```

View File

@ -0,0 +1,73 @@
---
title: v1.tagValues() function
description: placeholder
menu:
v2_0_ref:
name: v1.tagValues
parent: InfluxDB v1
weight: 301
---
The `v1.tagValues()` function returns a list unique values for a given tag.
The return value is always a single table with a single column, `_value`.
```js
import "influxdata/influxdb/v1"
v1.tagValues(
bucket: "example-bucket",
tag: "host",
predicate: (r) => true,
start: -30d
)
```
## Parameters
### bucket
The bucket from which to list tag values.
_**Data type:** String_
### tag
The tag for which to return unique values.
_**Data type:** String_
### predicate
The predicate function that filters tag values.
_Defaults to `(r) => true`._
_**Data type:** Function_
### start
Specifies the oldest time to be included in the results.
_Defaults to `-30d`._
Relative start times are defined using negative durations.
Negative durations are relative to now.
Absolute start times are defined using timestamps.
_**Data type:** Duration_
## Examples
```js
import "influxdata/influxdb/v1"
v1.tagKeys(
bucket: "my-bucket",
tag: "host",
)
```
## Function definition
```js
tagValues = (bucket, tag, predicate=(r) => true, start=-30d) =>
from(bucket: bucket)
|> range(start: start)
|> filter(fn: predicate)
|> group(columns: [tag])
|> distinct(column: tag)
|> keep(columns: ["_value"])
```