From 1274d9e38bda9a05b5312852ff00008cbe6c22bf Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 7 Feb 2019 18:47:12 -0700 Subject: [PATCH] added influxdb v1 functions package --- .../flux/functions/influxdb-v1/_index.md | 3 +- .../fieldsascols.md} | 22 +++--- .../functions/influxdb-v1/measurements.md | 31 ++++++++ .../influxdb-v1/measurementtagkeys.md | 41 +++++++++++ .../influxdb-v1/measurementtagvalues.md | 52 +++++++++++++ .../flux/functions/influxdb-v1/tagkeys.md | 63 ++++++++++++++++ .../flux/functions/influxdb-v1/tagvalues.md | 73 +++++++++++++++++++ 7 files changed, 275 insertions(+), 10 deletions(-) rename content/v2.0/reference/flux/functions/{built-in/transformations/influxfieldsascols.md => influxdb-v1/fieldsascols.md} (56%) create mode 100644 content/v2.0/reference/flux/functions/influxdb-v1/measurements.md create mode 100644 content/v2.0/reference/flux/functions/influxdb-v1/measurementtagkeys.md create mode 100644 content/v2.0/reference/flux/functions/influxdb-v1/measurementtagvalues.md create mode 100644 content/v2.0/reference/flux/functions/influxdb-v1/tagkeys.md create mode 100644 content/v2.0/reference/flux/functions/influxdb-v1/tagvalues.md diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/_index.md b/content/v2.0/reference/flux/functions/influxdb-v1/_index.md index 600a55a97..fd22f1689 100644 --- a/content/v2.0/reference/flux/functions/influxdb-v1/_index.md +++ b/content/v2.0/reference/flux/functions/influxdb-v1/_index.md @@ -10,7 +10,8 @@ menu: 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: ```js diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/influxfieldsascols.md b/content/v2.0/reference/flux/functions/influxdb-v1/fieldsascols.md similarity index 56% rename from content/v2.0/reference/flux/functions/built-in/transformations/influxfieldsascols.md rename to content/v2.0/reference/flux/functions/influxdb-v1/fieldsascols.md index a7ed64d7d..948442d67 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/influxfieldsascols.md +++ b/content/v2.0/reference/flux/functions/influxdb-v1/fieldsascols.md @@ -1,37 +1,41 @@ --- -title: influxFieldsAsCols() function -description: The influxFieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp. +title: v1.fieldsAsCols() function +description: The v1.fieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp. aliases: - /v2.0/reference/flux/functions/inputs/fromrows - /v2.0/reference/flux/functions/transformations/influxfieldsascols menu: v2_0_ref: - name: influxFieldsAsCols - parent: built-in-transformations -weight: 401 + name: v1.fieldsAsCols + parent: InfluxDB v1 +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. _**Function type:** Transformation_ ```js -influxFieldsAsCols() +import "influxdata/influxdb/v1" + +v1.fieldsAsCols() ``` ## Examples ```js +import "influxdata/influxdb/v1" + from(bucket:"telegraf/autogen") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "cpu") - |> influxFieldsAsCols() + |> v1.fieldsAsCols() |> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"]) ``` ## Function definition ```js -influxFieldsAsCols = (tables=<-) => +fieldsAsCols = (tables=<-) => tables |> pivot( rowKey:["_time"], diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/measurements.md b/content/v2.0/reference/flux/functions/influxdb-v1/measurements.md new file mode 100644 index 000000000..6c815ad14 --- /dev/null +++ b/content/v2.0/reference/flux/functions/influxdb-v1/measurements.md @@ -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") +``` diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagkeys.md b/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagkeys.md new file mode 100644 index 000000000..5b652bbf2 --- /dev/null +++ b/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagkeys.md @@ -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) +``` diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagvalues.md b/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagvalues.md new file mode 100644 index 000000000..576374b31 --- /dev/null +++ b/content/v2.0/reference/flux/functions/influxdb-v1/measurementtagvalues.md @@ -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 + ) +``` diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/tagkeys.md b/content/v2.0/reference/flux/functions/influxdb-v1/tagkeys.md new file mode 100644 index 000000000..7cfd6f8c4 --- /dev/null +++ b/content/v2.0/reference/flux/functions/influxdb-v1/tagkeys.md @@ -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"]) +``` diff --git a/content/v2.0/reference/flux/functions/influxdb-v1/tagvalues.md b/content/v2.0/reference/flux/functions/influxdb-v1/tagvalues.md new file mode 100644 index 000000000..17f5845e0 --- /dev/null +++ b/content/v2.0/reference/flux/functions/influxdb-v1/tagvalues.md @@ -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"]) +```