Merge pull request #1068 from influxdata/beta-12

Beta 12
pull/1104/head
kelseiv 2020-06-12 11:52:08 -07:00 committed by GitHub
commit 4bdc6be831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 3360 additions and 1490 deletions

File diff suppressed because it is too large Load Diff

View File

@ -117,7 +117,7 @@ executables, and running the initial setup process.
### Download and install InfluxDB v2.0 beta
Download InfluxDB v2.0 beta for macOS.
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.10_darwin_amd64.tar.gz" download>InfluxDB v2.0 beta (macOS)</a>
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.12_darwin_amd64.tar.gz" download>InfluxDB v2.0 beta (macOS)</a>
### Unpackage the InfluxDB binaries
To unpackage the downloaded archive, **double click the archive file in Finder**
@ -126,7 +126,7 @@ or run the following command in a macOS command prompt application such
```sh
# Unpackage contents to the current working directory
tar zxvf ~/Downloads/influxdb_2.0.0-beta.10_darwin_amd64.tar.gz
tar zxvf ~/Downloads/influxdb_2.0.0-beta.12_darwin_amd64.tar.gz
```
#### (Optional) Place the binaries in your $PATH
@ -135,7 +135,7 @@ prefix the executables with `./` to run then in place.
```sh
# (Optional) Copy the influx and influxd binary to your $PATH
sudo cp influxdb_2.0.0-beta.10_darwin_amd64/{influx,influxd} /usr/local/bin/
sudo cp influxdb_2.0.0-beta.12_darwin_amd64/{influx,influxd} /usr/local/bin/
```
{{% note %}}
@ -199,8 +199,8 @@ influxd --reporting-disabled
### Download and install InfluxDB v2.0 beta
Download the InfluxDB v2.0 beta package appropriate for your chipset.
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.10_linux_amd64.tar.gz" download >InfluxDB v2.0 beta (amd64)</a>
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.10_linux_arm64.tar.gz" download >InfluxDB v2.0 beta (arm)</a>
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.12_linux_amd64.tar.gz" download >InfluxDB v2.0 beta (amd64)</a>
<a class="btn download" href="https://dl.influxdata.com/influxdb/releases/influxdb_2.0.0-beta.12_linux_arm64.tar.gz" download >InfluxDB v2.0 beta (arm)</a>
### Place the executables in your $PATH
Unpackage the downloaded archive and place the `influx` and `influxd` executables in your system `$PATH`.
@ -209,10 +209,10 @@ _**Note:** The following commands are examples. Adjust the file names, paths, an
```sh
# Unpackage contents to the current working directory
tar xvzf path/to/influxdb_2.0.0-beta.10_linux_amd64.tar.gz
tar xvzf path/to/influxdb_2.0.0-beta.12_linux_amd64.tar.gz
# Copy the influx and influxd binary to your $PATH
sudo cp influxdb_2.0.0-beta.10_linux_amd64/{influx,influxd} /usr/local/bin/
sudo cp influxdb_2.0.0-beta.12_linux_amd64/{influx,influxd} /usr/local/bin/
```
{{% note %}}

View File

@ -0,0 +1,30 @@
---
title: InfluxDB templates in InfluxDB Cloud
list_title: InfluxDB templates in Cloud
description: >
Download and use the `influx` CLI to apply and manage InfluxDB templates with
your InfluxDB Cloud account.
menu:
v2_0:
parent: InfluxDB templates
name: Templates in Cloud
weight: 101
aliases:
- /v2.0/influxdb-templates/get_started_cloud/
v2.0/tags: [templates]
products: [cloud]
---
If using InfluxDB Cloud, download and use the [`influx` command line interface (CLI)](/v2.0/reference/cli/influx/)
to apply and manage templates in your InfluxDB Cloud account.
InfluxDB OSS 2.0 includes the InfluxDB CLI (`influx`). If you havent already, do the following:
1. [Download and install InfluxDB 2.0 OSS](/v2.0/get-started/#start-with-influxdb-oss).
2. [Configure the `influx` CLI](/v2.0/get-started/#set-up-influxdb) to use your
InfluxDB Cloud instance URL, organization, and tokens.
3. [Use the `influx` CLI](/v2.0/reference/cli/influx/) to use, manage, and create
InfluxDB templates:
- [Use templates](/v2.0/influxdb-templates/use/)
- [Create templates](/v2.0/influxdb-templates/create/)

View File

@ -1,7 +1,7 @@
---
title: Create an InfluxDB template
description: >
Use the InfluxDB UI and the `influx pkg export` command to create InfluxDB templates.
Use the InfluxDB UI and the `influx export` command to create InfluxDB templates.
menu:
v2_0:
parent: InfluxDB templates
@ -10,11 +10,11 @@ menu:
weight: 103
v2.0/tags: [templates]
related:
- /v2.0/reference/cli/influx/pkg/export/
- /v2.0/reference/cli/influx/pkg/export/all/
- /v2.0/reference/cli/influx/export/
- /v2.0/reference/cli/influx/export/all/
---
Use the InfluxDB user interface (UI) and the `influx pkg export` command to
Use the InfluxDB user interface (UI) and the `influx export` command to
create InfluxDB templates.
Add resources (buckets, Telegraf configurations, tasks, and more) in the InfluxDB
UI and export the resources as a template.
@ -61,7 +61,7 @@ Do one of the following to export a template:
### Export all resources
To export all templatable resources within an organization to a template manifest,
use the `influx pkg export all` command.
use the `influx export all` command.
Provide the following:
- **Organization name** or **ID**
@ -73,17 +73,17 @@ Provide the following:
###### Export all resources to a template
```sh
# Syntax
influx pkg export all -o <org-name> -f <file-path> -t <token>
influx export all -o <org-name> -f <file-path> -t <token>
# Example
influx pkg export all \
influx export all \
-o my-org \
-f ~/templates/awesome-template.yml \
-t $INFLUX_TOKEN
```
#### Export resources filtered by labelName or resourceKind
The `influx pkg export all` command has an optional `--filter` flag that exports
The `influx export all` command has an optional `--filter` flag that exports
only resources that match specified label names or resource kinds.
Provide multiple filters for both `labelName` and `resourceKind`
@ -97,7 +97,7 @@ and
```
```sh
influx pkg export all \
influx export all \
-o my-org \
-f ~/templates/awesome-template.yml \
-t $INFLUX_TOKEN \
@ -107,15 +107,12 @@ influx pkg export all \
--filter=labelName=Example2
```
For information about flags, see the
[`influx pkg export all` documentation](/v2.0/reference/cli/influx/pkg/export/all/).
[`influx export all` documentation](/v2.0/reference/cli/influx/export/all/).
### Export specific resources
To export specific resources within an organization to a template manifest,
use the `influx pkg export` with resource flags for each resource to include.
use the `influx export` with resource flags for each resource to include.
Provide the following:
- **Organization name** or **ID**
@ -125,15 +122,15 @@ Provide the following:
**JSON** (`.json`) are supported.
- **Resource flags** with corresponding lists of resource IDs to include in the template.
For information about what resource flags are available, see the
[`influx pkg export` documentation](/v2.0/reference/cli/influx/pkg/export/).
[`influx export` documentation](/v2.0/reference/cli/influx/export/).
###### Export specific resources to a template
```sh
# Syntax
influx pkg export all -o <org-name> -f <file-path> -t <token> [resource-flags]
influx export all -o <org-name> -f <file-path> -t <token> [resource-flags]
# Example
influx pkg export all \
influx export all \
-o my-org \
-f ~/templates/awesome-template.yml \
-t $INFLUX_TOKEN \
@ -193,13 +190,13 @@ metadata:
{{< /code-tabs-wrapper >}}
Using the example above, users are prompted to provide a value for `bucket-name-1`
when [installing the template](/v2.0/influxdb-templates/use/#install-templates).
when [applying the template](/v2.0/influxdb-templates/use/#apply-templates).
Users can also include the `--env-ref` flag with the appropriate key-value pair
when installing the template.
```sh
# Set bucket-name-1 to "myBucket"
influx pkg \
influx apply \
-f /path/to/template.yml \
--env-ref=bucket-name-1=myBucket
```
@ -211,7 +208,9 @@ exist in the template and what keys to use to replace them._
#### Resource fields that support environment references
Only the following fields support environment references:
- `metadata.name`
- `spec.endpointName`
- `spec.associations.name`
{{% /note %}}
## Share your InfluxDB templates

View File

@ -1,26 +0,0 @@
---
title: Get started with InfluxDB templates
description: >
To get started with InfluxDB templates, you need to download the InfluxDB CLI.
menu:
v2_0:
parent: InfluxDB templates
name: Get started with templates in Cloud
identifier: Templates requires CLI
weight: 101
v2.0/tags: [templates]
products: [cloud]
---
If you're an InfluxDB Cloud user, you'll need the InfluxDB CLI (`influx`) to run `pkg` commands against your Cloud account.
InfluxDB OSS 2.0 includes the InfluxDB CLI (`influx`). If you havent already, do the following:
- [Install OSS 2.0](/v2.0/get-started/#start-with-influxdb-oss).
- [Set up and use InfluxDB CLI](/v2.0/reference/cli/influx/) with the appropriate InfluxDB Cloud instance URL, organization, and tokens associated with your account.
Next, discover how to use `influx` and `pkg` to do the following:
- [Use templates](/v2.0/influxdb-templates/use/)
- [Create templates](/v2.0/influxdb-templates/create/)

View File

@ -1,8 +1,8 @@
---
title: Use InfluxDB templates
description: >
Use the `influx pkg` command to view and install templates from your local
filesystem or from URLs.
Use the `influx` command line interface (CLI) to summarize, validate, and apply
templates from your local filesystem and from URLs.
menu:
v2_0:
parent: InfluxDB templates
@ -10,23 +10,25 @@ menu:
weight: 102
v2.0/tags: [templates]
related:
- /v2.0/reference/cli/influx/pkg/
- /v2.0/reference/cli/influx/apply/
- /v2.0/reference/cli/influx/template/
- /v2.0/reference/cli/influx/template/validate/
---
Use the `influx pkg` command to summarize, validate, and install templates from
your local filesystem and from URLs.
Use the `influx` command line interface (CLI) to summarize, validate, and apply
templates from your local filesystem and from URLs.
- [Use InfluxDB community templates](#use-influxdb-community-templates)
- [View a template summary](#view-a-template-summary)
- [Validate a template](#validate-a-template)
- [Install templates](#install-templates)
- [Apply templates](#apply-templates)
## Use InfluxDB community templates
The [InfluxDB community templates repository](https://github.com/influxdata/community-templates/)
is home to a growing number of InfluxDB templates developed and maintained by
others in the InfluxData community.
Install community templates directly from GitHub using a template's download URL
Apply community templates directly from GitHub using a template's download URL
or download the template.
{{% note %}}
@ -47,8 +49,8 @@ https://raw.githubusercontent.com/influxdata/community-templates/master/docker/d
<a class="btn" href="https://github.com/influxdata/community-templates/" target="\_blank">View InfluxDB Community Templates</a>
## View a template summary
To view a summary of what's included in a template before installing the template,
use the [`influx pkg summary` command](/v2.0/reference/cli/influx/pkg/summary/).
To view a summary of what's included in a template before applying the template,
use the [`influx template` command](/v2.0/reference/cli/influx/template/).
View a summary of a template stored in your local filesystem or from a URL.
{{% code-tabs-wrapper %}}
@ -59,26 +61,26 @@ View a summary of a template stored in your local filesystem or from a URL.
{{% code-tab-content %}}
```sh
# Syntax
influx pkg summary -f <template-file-path>
influx template -f <template-file-path>
# Example
influx pkg summary -f /path/to/template.yml
influx template -f /path/to/template.yml
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```sh
# Syntax
influx pkg summary -u <template-url>
influx template -u <template-url>
# Example
influx pkg summary -u https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml
influx template -u https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml
```
{{% /code-tab-content %}}
{{% /code-tabs-wrapper %}}
## Validate a template
To validate a template before you install it or troubleshoot a template, use
the [`influx pkg validate` command](/v2.0/reference/cli/influx/pkg/validate/).
the [`influx template validate` command](/v2.0/reference/cli/influx/template/validate/).
Validate a template stored in your local filesystem or from a URL.
{{% code-tabs-wrapper %}}
@ -89,99 +91,99 @@ Validate a template stored in your local filesystem or from a URL.
{{% code-tab-content %}}
```sh
# Syntax
influx pkg validate -f <template-file-path>
influx template validate -f <template-file-path>
# Example
influx pkg validate -f /path/to/template.yml
influx template validate -f /path/to/template.yml
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```sh
# Syntax
influx pkg validate -u <template-url>
influx template validate -u <template-url>
# Example
influx pkg validate -u https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml
influx template validate -u https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml
```
{{% /code-tab-content %}}
{{% /code-tabs-wrapper %}}
## Install templates
Use the [`influx pkg` command](/v2.0/reference/cli/influx/pkg/) to install templates
## Apply templates
Use the [`influx apply` command](/v2.0/reference/cli/influx/apply/) to install templates
from your local filesystem or from URLs.
- [Install a template from a file](#install-a-template-from-a-file)
- [Install all templates in a directory](#install-all-templates-in-a-directory)
- [Install a template from a URL](#install-a-template-from-a-url)
- [Install templates from both files and URLs](#install-templates-from-both-files-and-urls)
- [Apply a template from a file](#apply-a-template-from-a-file)
- [Apply all templates in a directory](#apply-all-templates-in-a-directory)
- [Apply a template from a URL](#apply-a-template-from-a-url)
- [Apply templates from both files and URLs](#apply-templates-from-both-files-and-urls)
- [Define environment references](#define-environment-references)
- [Include a secret when installing a template](#include-a-secret-when-installing-a-template)
### Install a template from a file
### Apply a template from a file
To install templates stored on your local machine, use the `-f` or `--file` flag
to provide the **file path** of the template manifest.
```sh
# Syntax
influx pkg -o <org-name> -f <template-file-path>
influx apply -o <org-name> -f <template-file-path>
# Examples
# Install a single template
influx pkg -o example-org -f /path/to/template.yml
# Apply a single template
influx apply -o example-org -f /path/to/template.yml
# Install multiple templates
influx pkg -o example-org \
# Apply multiple templates
influx apply -o example-org \
-f /path/to/this/template.yml \
-f /path/to/that/template.yml
```
### Install all templates in a directory
To install all templates in a directory, use the `-f` or `--file` flag to provide
### Apply all templates in a directory
To apply all templates in a directory, use the `-f` or `--file` flag to provide
the **directory path** of the directory where template manifests are stored.
By default, this only installs templates stored in the specified directory.
To install all templates stored in the specified directory and its subdirectories,
include the `--recurse` flag.
By default, this only applies templates stored in the specified directory.
To apply all templates stored in the specified directory and its subdirectories,
include the `-R`, `--recurse` flag.
```sh
# Syntax
influx pkg -o <org-name> -f <template-directory-path>
influx apply -o <org-name> -f <template-directory-path>
# Examples
# Install all templates in a directory
influx pkg -o example-org -f /path/to/template/dir/
# Apply all templates in a directory
influx apply -o example-org -f /path/to/template/dir/
# Install all templates in a directory and its subdirectories
influx pkg -o example-org -f /path/to/template/dir/ --recurse
# Apply all templates in a directory and its subdirectories
influx apply -o example-org -f /path/to/template/dir/ -R
```
### Install a template from a URL
To install templates from a URL, use the `-u` or `--url` flag to provide the URL
### Apply a template from a URL
To apply templates from a URL, use the `-u` or `--template-url` flag to provide the URL
of the template manifest.
```sh
# Syntax
influx pkg -o <org-name> -u <template-url>
influx apply -o <org-name> -u <template-url>
# Examples
# Install a single template from a URL
influx pkg -o example-org -u https://example.com/templates/template.yml
# Apply a single template from a URL
influx apply -o example-org -u https://example.com/templates/template.yml
# Install multiple templates from URLs
influx pkg -o example-org \
# Apply multiple templates from URLs
influx apply -o example-org \
-u https://example.com/templates/template1.yml \
-u https://example.com/templates/template2.yml
```
### Install templates from both files and URLs
To install templates from both files and URLs in a single command, include multiple
### Apply templates from both files and URLs
To apply templates from both files and URLs in a single command, include multiple
file or directory paths and URLs, each with the appropriate `-f` or `-u` flag.
```sh
# Syntax
influx pkg -o <org-name> -u <template-url> -f <template-path>
influx apply -o <org-name> -u <template-url> -f <template-path>
# Example
influx pkg -o example-org \
influx apply -o example-org \
-u https://example.com/templates/template1.yml \
-u https://example.com/templates/template2.yml \
-f ~/templates/custom-template.yml \
@ -191,14 +193,14 @@ influx pkg -o example-org \
### Define environment references
Some templates include [environment references](/v2.0/influxdb-templates/create/#include-user-definable-resource-names) that let you provide custom resource names.
The `influx pkg` command prompts you to provide a value for each environment
The `influx apply` command prompts you to provide a value for each environment
reference in the template.
You can also provide values for environment references by including an `--env-ref`
flag with a key-value pair comprised of the environment reference key and the
value to replace it.
```sh
influx pkg -o example-org -f /path/to/template.yml \
influx apply -o example-org -f /path/to/template.yml \
--env-ref=bucket-name-1=myBucket
--env-ref=label-name-1=Label1 \
--env-ref=label-name-2=Label2
@ -212,18 +214,18 @@ with the secret key-value pair.
```sh
# Syntax
influx pkg -o <org-name> -f <template-file-path> \
influx apply -o <org-name> -f <template-file-path> \
--secret=<secret-key>=<secret-value>
# Examples
# Define a single secret when installing a template
influx pkg -o example-org -f /path/to/template.yml \
# Define a single secret when applying a template
influx apply -o example-org -f /path/to/template.yml \
--secret=FOO=BAR
# Define multiple secrets when installing a template
influx pkg -o example-org -f /path/to/template.yml \
# Define multiple secrets when applying a template
influx apply -o example-org -f /path/to/template.yml \
--secret=FOO=bar \
--secret=BAZ=quz
```
_To add a secret after installing a template, see [Add secrets](/v2.0/security/secrets/manage-secrets/add/)._
_To add a secret after applying a template, see [Add secrets](/v2.0/security/secrets/manage-secrets/add/)._

View File

@ -45,21 +45,24 @@ retrieving authentication tokens._
## Commands
| Command | Description |
|:------- |:----------- |
| [apply](/v2.0/reference/cli/influx/apply) | Apply an InfluxDB template |
| [auth](/v2.0/reference/cli/influx/auth) | Authorization management commands |
| [backup](/v2.0/reference/cli/influx/backup) | Back up data |
| [bucket](/v2.0/reference/cli/influx/bucket) | Bucket management commands |
| [completion](/v2.0/reference/cli/influx/completion) | Generate completion scripts |
| [config](/v2.0/reference/cli/influx/config) | Configuration management commands |
| [delete](/v2.0/reference/cli/influx/delete) | Delete points from InfluxDB |
| [export](/v2.0/reference/cli/influx/export) | Export resources as a template |
| [help](/v2.0/reference/cli/influx/help) | Help about any command |
| [org](/v2.0/reference/cli/influx/org) | Organization management commands |
| [ping](/v2.0/reference/cli/influx/ping) | Check the InfluxDB `/health` endpoint |
| [pkg](/v2.0/reference/cli/influx/pkg) | Manage InfluxDB packages |
| [query](/v2.0/reference/cli/influx/query) | Execute a Flux query |
| [repl](/v2.0/reference/cli/influx/repl) | Interactive REPL (read-eval-print-loop) |
| [secret](/v2.0/reference/cli/influx/secret) | Manage secrets |
| [setup](/v2.0/reference/cli/influx/setup) | Create default username, password, org, bucket, etc. |
| [stacks](/v2.0/reference/cli/influx/stacks) | Manage InfluxDB stacks |
| [task](/v2.0/reference/cli/influx/task) | Task management commands |
| [template](/v2.0/reference/cli/influx/template) | Summarize and validate an InfluxDB template |
| [transpile](/v2.0/reference/cli/influx/transpile) | Manually transpile an InfluxQL query to Flux |
| [user](/v2.0/reference/cli/influx/user) | User management commands |
| [write](/v2.0/reference/cli/influx/write) | Write points to InfluxDB |

View File

@ -0,0 +1,81 @@
---
title: influx apply
description: The 'influx apply' command applies InfluxDB templates.
menu:
v2_0_ref:
name: influx apply
parent: influx
weight: 101
aliases:
- /v2.0/reference/cli/influx/pkg/
v2.0/tags: [templates]
---
The `influx apply` command applies InfluxDB templates.
_For information about finding and using InfluxDB templates, see
[Use InfluxDB templates](/v2.0/influxdb-templates/use/)._
## Usage
```
influx apply [flags]
```
#### Aliases
`apply`, `pkg` _(deprecated)_
## Flags
| Flag | Description | Input Type | {{< cli/mapped >}} |
|:---- |:----------------------------- |:---------- |:------------------ |
| `-c`, `--disable-color` | Disable color in output | | |
| `--disable-table-borders` | Disable table borders | | |
| `-e`, `--encoding` | Encoding of the input stream | string | |
| `--env-ref` | Environment references to provide with the template (format: `--env-ref=REF_KEY=REF_VALUE`) | string | |
| `-f`, `--file` | Path to template file | string | |
| `--force` | Ignore warnings about destructive changes | | |
| `-h`, `--help` | Help for the `apply` command | | |
| `--json` | Output data as JSON | | `INFLUX_OUTPUT_JSON` |
| `-o`, `--org` | Organization name that owns the bucket | string | `INFLUX_ORG` |
| `--org-id` | Organization ID that owns the bucket | string | `INFLUX_ORG_ID` |
| `-q`, `--quiet` | Disable output printing | | |
| `-R`, `--recurse` | Recurse through files in the directory specified in `-f`, `--file` | | |
| `--secret` | Secrets to provide with the template (format: `--secret=SECRET_KEY=SECRET_VALUE`) | string | |
| `--stack-id` | Stack ID to associate when applying the template | string | |
| `-u`, `--template-url` | URL of template file | string | |
{{% cli/influx-global-flags %}}
## Examples
```sh
# Apply a template from a file.
influx apply -f path/to/template.json
# Apply a stack that has associated templates.
influx apply --stack-id $STACK_ID
# Apply a template associated with a stack.
# Stacks make template application idempotent.
influx apply -f path/to/template.json --stack-id $STACK_ID
# Apply multiple template files together.
influx apply \
-f path/to/template_1.json \
-f path/to/template_2.yml
# Apply a template from a URL.
influx apply -u https://raw.githubusercontent.com/influxdata/community-templates/master/docker/docker.yml
# Apply a template from STDIN.
cat template.json | influx apply --encoding json
# Apply all templates in a directory.
influx apply -f path/to/template_directory
# Recurse through a directory and its subdirectories and apply all templates.
influx apply -R -f path/to/template_directory
# Apply templates from multiple sources directory, file, and URL.
influx apply \
-f path/to/template.yml
-f path/to/templates_directory
-u https://example.com/template.json
```

View File

@ -1,28 +1,31 @@
---
title: influx pkg export
description: The 'influx pkg' command exports existing resources as an InfluxDB template.
title: influx export
description: The 'influx export' command exports existing resources as an InfluxDB template.
menu:
v2_0_ref:
parent: influx pkg
parent: influx
weight: 101
aliases:
- /v2.0/reference/cli/influx/pkg/export/
related:
- /v2.0/influxdb-templates/create/
---
The `influx pkg export` command exports existing resources as an InfluxDB template.
The `influx export` command exports existing resources as an InfluxDB template.
_For detailed examples of exporting InfluxDB templates, see
[Create an InfluxDB template](/v2.0/influxdb-templates/create/)._
## Usage
```
influx pkg export [flags]
influx pkg export [command]
influx export [flags]
influx export [command]
```
## Available subcommands
| Subcommand | Description |
|:---------- |:----------- |
| [all](/v2.0/reference/cli/influx/pkg/export/all/) | Export all resources in an organization as a template |
| Subcommand | Description |
|:---------- |:----------- |
| [all](/v2.0/reference/cli/influx/export/all/) | Export all resources in an organization as a template |
| [stack](/v2.0/reference/cli/influx/export/stack/) | Export all resources associated with a stack as a template |
## Flags
@ -42,3 +45,15 @@ influx pkg export [command]
| `--variables` | Comma-separated list of variable IDs | string |
{{% cli/influx-global-flags %}}
## Examples
```sh
# Export buckets by ID
influx export --buckets=$ID1,$ID2,$ID3
# Export buckets, labels, and dashboards by ID
influx export \
--buckets=$BID1,$BID2,$BID3 \
--labels=$LID1,$LID2,$LID3 \
--dashboards=$DID1,$DID2,$DID3
```

View File

@ -1,23 +1,25 @@
---
title: influx pkg export all
title: influx export all
description: >
The 'influx pkg' command exports all resources in an organization as an InfluxDB template.
The 'influx export all' command exports all resources in an organization as an InfluxDB template.
menu:
v2_0_ref:
parent: influx pkg export
parent: influx export
weight: 201
aliases:
- /v2.0/reference/cli/influx/pkg/export/all/
related:
- /v2.0/influxdb-templates/create/
---
The `influx pkg export all` command exports all resources in an
The `influx export all` command exports all resources in an
organization as an InfluxDB template.
_For detailed examples of exporting InfluxDB templates, see
[Create an InfluxDB template](/v2.0/influxdb-templates/create/)._
## Usage
```
influx pkg export all [flags]
influx export all [flags]
```
## Flags
@ -25,8 +27,35 @@ influx pkg export all [flags]
|:---- |:----------- |:---------- |:------------------ |
| `-f`, `--file` | Template output file. Defaults to stdout. Use `.yml` or `.json` file extensions. | string | |
| `--filter` | Specify resources to export by labelName or resourceKind (format: `--filter=labelName=example`) | list of strings |
| `-h`, `--help` | Help for the `export` command | | |
| `-h`, `--help` | Help for the `export all` command | | |
| `-o`, `--org` | Organization name that owns the resources | string | `INFLUX_ORG` |
| `--org-id` | Organization ID that owns the resources | string | `INFLUX_ORG_ID` |
{{% cli/influx-global-flags %}}
## Examples
```sh
# Export all resources in an organization as a template
influx export all --org $INFLUX_ORG
# Export all bucket resources as a template
influx export all --org $INFLUX_ORG --filter=resourceKind=Bucket
# Export all resources associated with label Foo
influx export all --org $INFLUX_ORG --filter=labelName=Foo
# Export all bucket resources and filter by label Foo
influx export all --org $INFLUX_ORG \
--filter=resourceKind=Bucket \
--filter=labelName=Foo
# Export all bucket or dashboard resources and filter by label Foo.
#
# Note: "like" filters are unioned and filter types are intersections.
# For example, the following will export a resource if it is a dashboard or
# bucket and has an associated label of Foo.
influx export all --org $INFLUX_ORG \
--filter=resourceKind=Bucket \
--filter=resourceKind=Dashboard \
--filter=labelName=Foo
``

View File

@ -0,0 +1,35 @@
---
title: influx export stack
description: >
The 'influx export stack' command exports all resources associated with a stack as an InfluxDB template.
menu:
v2_0_ref:
parent: influx export
weight: 201
aliases:
- /v2.0/reference/cli/influx/pkg/export/stack
---
The `influx export stack` command exports all resources associated with a stack as a template.
All `metadata.name` fields remain the same.
## Usage
```
influx export stack <stack_id> [flags]
```
## Flags
| Flag | Description | Input Type | {{< cli/mapped >}} |
|:---- |:----------- |:---------- |:------------------ |
| `-f`, `--file` | Template output file. Defaults to stdout. Use `.yml` or `.json` file extensions. | string | |
| `-h`, `--help` | Help for the `export stack` command | | |
| `-o`, `--org` | Organization name that owns the resources | string | `INFLUX_ORG` |
| `--org-id` | Organization ID that owns the resources | string | `INFLUX_ORG_ID` |
{{% cli/influx-global-flags %}}
## Examples
```sh
# Export a stack as a template
influx export stack $STACK_ID
```

View File

@ -1,50 +0,0 @@
---
title: influx pkg
description: The 'influx pkg' command and its subcommands manage InfluxDB templates.
menu:
v2_0_ref:
name: influx pkg
parent: influx
weight: 101
v2.0/tags: [templates]
related:
- /v2.0/influxdb-templates/use/
---
The `influx pkg` command manages InfluxDB templates.
_For information about finding and using InfluxDB templates, see
[Use InfluxDB templates](/v2.0/influxdb-templates/use/)._
## Usage
```
influx pkg [flags]
influx pkg [command]
```
## Subcommands
| Subcommand | Description |
|:------- |:----------- |
| [export](/v2.0/reference/cli/influx/pkg/export/) | Export resources as a template |
| [stack](/v2.0/reference/cli/influx/pkg/stack/) | Manage stacks |
| [summary](/v2.0/reference/cli/influx/pkg/summary/) | Summarize the specified template |
| [validate](/v2.0/reference/cli/influx/pkg/validate/) | Validate the specified template |
## Flags
| Flag | Description | Input Type | {{< cli/mapped >}} |
|:---- |:----------------------------- |:---------- |:------------------ |
| `-c`, `--disable-color` | Disable color in output | | |
| `--disable-table-borders` | Disable table borders | | |
| `-e`, `--encoding` | Encoding of the input stream | string | |
| `--env-ref` | Environment references to provide with the template (format: `--env-ref=REF_KEY=REF_VALUE`) | string | |
| `-f`, `--file` | Path to template file | string | |
| `--force` | Ignore warnings about destructive changes | | |
| `-h`, `--help` | Help for the `pkg` command | | |
| `-o`, `--org` | Organization name that owns the bucket | string | `INFLUX_ORG` |
| `--org-id` | Organization ID that owns the bucket | string | `INFLUX_ORG_ID` |
| `-q`, `--quiet` | Disable output printing | | |
| `-R`, `--recurse` | Recurse through files in the directory specified in `-f`, `--file` | | |
| `--secret` | Secrets to provide with the template (format: `--secret=SECRET_KEY=SECRET_VALUE`) | string | |
| `-u`, `--url` | URL of template file | string | |
{{% cli/influx-global-flags %}}

View File

@ -1,32 +0,0 @@
---
title: influx pkg stack
description: The 'influx pkg stack' command and its subcommands manage InfluxDB stacks.
menu:
v2_0_ref:
name: influx pkg stack
parent: influx pkg
weight: 101
v2.0/tags: [templates]
---
The `influx pkg stack` command manages InfluxDB stacks.
## Usage
```
influx pkg stack [flags]
influx pkg stack [command]
```
## Subcommands
| Subcommand | Description |
|:------- |:----------- |
| [init](/v2.0/reference/cli/influx/pkg/stack/init/) | Initialize a stack |
| [list](/v2.0/reference/cli/influx/pkg/stack/list/) | List stacks |
| [remove](/v2.0/reference/cli/influx/pkg/stack/remove/) | Remove a stack |
## Flags
| Flag | Description |
|:---- |:----------- |
| `-h`, `--help` | Help for the `stack` command |
{{% cli/influx-global-flags %}}

View File

@ -1,31 +0,0 @@
---
title: influx pkg stack init
description: The 'influx pkg stack init' command initializes an InfluxDB stack.
menu:
v2_0_ref:
name: influx pkg stack init
parent: influx pkg stack
weight: 201
v2.0/tags: [templates]
---
The `influx pkg stack init` command initializes an InfluxDB stack.
## Usage
```
influx pkg stack init [flags]
```
## Flags
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------: |:------------------ |
| `-h`, `--help` | Help for the `init` command | | |
| `--hide-headers` | Hide table headers (default `false`) | | `INFLUX_HIDE_HEADERS` |
| `--json` | Output data as JSON (default `false`) | | `INFLUX_OUTPUT_JSON` |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-u`, `--package-url` | Package URLs to associate stack | list of strings | |
| `-d`, `--stack-description` | Stack description | string | |
| `-n`, `--stack-name` | Stack name | string | |
{{% cli/influx-global-flags %}}

View File

@ -1,29 +0,0 @@
---
title: influx pkg validate
description: >
The 'influx pkg validate' command validates the provided InfluxDB template.
menu:
v2_0_ref:
parent: influx pkg
weight: 101
---
The `influx pkg validate` command validates the provided InfluxDB template.
## Usage
```
influx pkg validate [flags]
```
## Flags
| Flag | Description | Input Type | {{< cli/mapped >}} |
|:---- |:----------- |:---------- |:------------------ |
| `-e`, `--encoding` | Encoding of the input stream | string | |
| `-f`, `--file` | Package file to validate | string | |
| `-h`, `--help` | Help for the `validate` command | | |
| `--json` | Output data as JSON (default `false`) | | `INFLUX_OUTPUT_JSON` |
| `-R`, `--recurse` | Recurse through files in the directory specified in `-f`, `--file` | | |
| `-u`, `--url` | URL of template file to validate | string | |
{{% cli/influx-global-flags %}}

View File

@ -1,29 +1,37 @@
---
title: influx pkg stack list
title: influx stacks
description: >
The 'influx pkg stack list' command lists InfluxDB stacks and associated resources.
The 'influx stacks' command and its subcommands list and manage InfluxDB stacks
and associated resources.
menu:
v2_0_ref:
name: influx pkg stack list
parent: influx pkg stack
weight: 201
name: influx stacks
parent: influx
weight: 101
aliases:
- /v2.0/reference/cli/influx/pkg/stack/list/
v2.0/tags: [templates]
---
The `influx pkg stack list` command lists InfluxDB stacks and associated resources.
The `influx stacks` command and its subcommands list and manage InfluxDB stacks
and associated resources.
## Usage
```
influx pkg stack list [flags]
influx stacks [flags]
influx stacks [command]
```
#### Aliases
`list`, `ls`
## Subcommands
| Subcommand | Description |
|:------- |:----------- |
| [init](/v2.0/reference/cli/influx/stacks/init/) | Initialize a stack |
| [remove](/v2.0/reference/cli/influx/stacks/remove/) | Remove a stack |
## Flags
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------: |:------------------ |
| `-h`, `--help` | Help for the `list` command | | |
| `-h`, `--help` | Help for the `stacks` command | | |
| `--hide-headers` | Hide table headers (default `false`) | | `INFLUX_HIDE_HEADERS` |
| `--json` | Output data as JSON (default `false`) | | `INFLUX_OUTPUT_JSON` |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |

View File

@ -0,0 +1,42 @@
---
title: influx stacks init
description: The 'influx stacks init' command initializes an InfluxDB stack.
menu:
v2_0_ref:
name: influx stacks init
parent: influx stacks
weight: 201
aliases:
- /v2.0/reference/cli/influx/pkg/stack/init/
v2.0/tags: [templates]
---
The `influx stacks init` command initializes an InfluxDB stack.
## Usage
```
influx stacks init [flags]
```
## Flags
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------: |:------------------ |
| `-h`, `--help` | Help for the `init` command | | |
| `--hide-headers` | Hide table headers (default `false`) | | `INFLUX_HIDE_HEADERS` |
| `--json` | Output data as JSON (default `false`) | | `INFLUX_OUTPUT_JSON` |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-d`, `--stack-description` | Stack description | string | |
| `-n`, `--stack-name` | Stack name | string | |
| `-u`, `--template-url` | Template URLs to associate with a stack | list of strings | |
{{% cli/influx-global-flags %}}
## Examples
```sh
# Initialize a stack with a name and description
influx stack init -n $STACK_NAME -d $STACK_DESCRIPTION
# Initialize a stack with a name and urls to associate with stack.
influx stack init -n $STACK_NAME -u $PATH_TO_TEMPLATE
```

View File

@ -1,19 +1,21 @@
---
title: influx pkg stack remove
description: The 'influx pkg stack remove' command removes an InfluxDB stack.
title: influx stacks remove
description: The 'influx stacks remove' command removes an InfluxDB stack and all associated resources.
menu:
v2_0_ref:
name: influx pkg stack remove
parent: influx pkg stack
name: influx stacks remove
parent: influx stacks
weight: 201
aliases:
- /v2.0/reference/cli/influx/pkg/stack/remove/
v2.0/tags: [templates]
---
The `influx pkg stack remove` command removes an InfluxDB stack.
The `influx stacks remove` command removes an InfluxDB stack and all associated resources.
## Usage
```
influx pkg stack remove [flags]
influx stacks remove [flags]
```
#### Aliases

View File

@ -1,32 +1,39 @@
---
title: influx pkg summary
description: >
The 'influx pkg summary' command summarizes the provided InfluxDB template.
title: influx template
description: The 'influx template' command summarizes the specified InfluxDB template.
menu:
v2_0_ref:
parent: influx pkg
name: influx template
parent: influx
weight: 101
v2.0/tags: [templates]
aliases:
- /v2.0/reference/cli/influx/pkg/summary/
---
The `influx pkg summary` command summarizes the provided InfluxDB template.
The `influx template` command summarizes the specified InfluxDB template.
## Usage
```
influx pkg summary [flags]
influx template [flags]
influx template [command]
```
## Flags
## Subcommands
| Subcommand | Description |
|:---------- |:----------- |
| [validate](/v2.0/reference/cli/influx/template/validate) | Validate a template |
## Flags
| Flag | Description | Input Type | {{< cli/mapped >}} |
|:---- |:----------- |:---------- |:------------------ |
| `-c`, `--disable-color` | Disable color in output | | |
| `--disable-table-borders` | Disable table borders | | |
| `-e`, `--encoding` | Encoding of the input stream | string | |
| `-f`, `--file` | Package file to summarize | string | |
| `-h`, `--help` | Help for the `summary` command | | |
| `-f`, `--file` | Template file to summarize | string | |
| `-h`, `--help` | Help for the `template` command | | |
| `--json` | Output data as JSON (default `false`) | | `INFLUX_OUTPUT_JSON` |
| `-R`, `--recurse` | Recurse through files in the directory specified in `-f`, `--file` | | |
| `-u`, `--url` | URL of template file to summarize | string | |
| `-u`, `--template-url` | URL of template file to summarize | string | |
{{% cli/influx-global-flags %}}

View File

@ -0,0 +1,30 @@
---
title: influx template validate
description: >
The 'influx template validate' command validates the provided InfluxDB template.
menu:
v2_0_ref:
parent: influx template
weight: 201
aliases:
- /v2.0/reference/cli/influx/pkg/validate/
---
The `influx template validate` command validates the provided InfluxDB template.
## Usage
```
influx template validate [flags]
```
## Flags
| Flag | | Description | Input Type |
|:---- | --- |:----------- |:---------- |
| `-e` | `--encoding` | Encoding of the input stream | string |
| `-f` | `--file` | Template file to validate | string |
| `-h` | `--help` | Help for the `validate` command | |
| `-R` | `--recurse` | Recurse through files in the directory specified in `-f`, `--file` | |
| `-u` | `--template-url` | URL of template file to validate | string |
{{% cli/influx-global-flags %}}

View File

@ -9,6 +9,9 @@ menu:
parent: influx
weight: 101
v2.0/tags: [write]
related:
- /v2.0/write-data/
- /v2.0/write-data/csv/
---
The `influx write` command writes data to InfluxDB via stdin or from a specified file.
@ -27,15 +30,21 @@ influx write [command]
| [dryrun](/v2.0/reference/cli/influx/write/dryrun) | Write to stdout instead of InfluxDB |
## Flags
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------:|:------------------ |
| `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` |
| `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` |
| `-f`, `--file` | File to import | string | |
| `--format` | Input format (`lp` or `csv`, default `lp`) | string | |
| `-h`, `--help` | Help for the `dryrun` command | | |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` |
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------:|:------------------ |
| `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` |
| `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` |
| `--debug` | Output errors to stderr | | |
| `--encoding` | Character encoding of input (default `UTF-8`) | string | |
| `-f`, `--file` | File to import | string | |
| `--format` | Input format (`lp` or `csv`, default `lp`) | string | |
| `--header` | Prepend header line to CSV input data | string | |
| `-h`, `--help` | Help for the `dryrun` command | | |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` |
| `--skipHeader` | Skip first n rows of input data | integer | |
| `--skipRowOnError` | Output CSV errors to stderr, but continue processing | | |
| `-u`, `--url` | URL to import data from | string | |
{{% cli/influx-global-flags %}}

View File

@ -24,15 +24,21 @@ influx write dryrun [flags]
```
## Flags
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------:|:------------------ |
| `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` |
| `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` |
| `-f`, `--file` | File to import | string | |
| `--format` | Input format (`lp` or `csv`, defaults `lp`) | string | |
| `-h`, `--help` | Help for the `dryrun` command | | |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` |
| Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------:|:------------------ |
| `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` |
| `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` |
| `--debug` | Output errors to stderr | | |
| `--encoding` | Character encoding of input (default `UTF-8`) | string | |
| `-f`, `--file` | File to import | string | |
| `--format` | Input format (`lp` or `csv`, default `lp`) | string | |
| `--header` | Prepend header line to CSV input data | string | |
| `-h`, `--help` | Help for the `dryrun` command | | |
| `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` |
| `--skipHeader` | Skip first n rows of input data | integer | |
| `--skipRowOnError` | Output CSV errors to stderr, but continue processing | | |
| `-u`, `--url` | URL to import data from | string | |
{{% cli/influx-global-flags %}}

View File

@ -86,24 +86,12 @@ identity: {sum: 0.0, count: 0.0}
## Important notes
#### Preserve columns
#### Dropped columns
By default, `reduce()` drops any columns that:
1. Are not part of the input table's group key.
1. Are not part of the input table's [group key](/v2.0/reference/glossary/#group-key).
2. Are not explicitly mapped in the `reduce()` function.
This often results in the `_time` column being dropped.
To preserve the `_time` column and other columns that do not meet the criteria above,
use the `with` operator to map values in the `r` object.
The `with` operator updates a column if it already exists,
creates a new column if it doesn't exist, and includes all existing columns in
the output table.
```js
reduce(fn: (r) => ({ r with newColumn: r._value * 2 }))
```
## Examples
##### Compute the sum of the value column
@ -157,14 +145,13 @@ from(bucket:"example-bucket")
)
```
##### Calculate the average and preserve existing columns
##### Calculate the average
```js
from(bucket: "example-bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent")
|> window(every: 5m)
|> reduce(fn: (r, accumulator) => ({
r with
count: accumulator.count + 1,
total: accumulator.total + r._value,
avg: (accumulator.total + r._value) / float(v: accumulator.count)

View File

@ -0,0 +1,16 @@
---
title: Flux user-contributed functions
list_title: User-contributed functions
description: >
User-contributed packages and functions are contributed and maintained by members of the InfluxDB and Flux communities.
menu:
v2_0_ref:
name: User-contributed
parent: Flux standard library
weight: 202
v2.0/tags: [contributed, functions, package]
---
User-contributed packages and functions are contributed and maintained by members of the InfluxDB and Flux communities.
{{< children >}}

View File

@ -0,0 +1,28 @@
---
title: Flux Discord package
list_title: Discord package
description: >
The Flux Discord package provides functions for sending data to Discord.
Import the `contrib/chobbs/discord` package.
menu:
v2_0_ref:
name: Discord
parent: User-contributed
weight: 202
v2.0/tags: [functions, discord, package]
---
The Flux Discord package provides functions for sending data to Discord.
Import the `contrib/chobbs/discord` package:
```js
import "contrib/chobbs/discord"
```
{{< children type="functions" show="pages" >}}
{{% note %}}
#### Package author and maintainer
**Github:** [@chobbs](https://github.com/chobbs)
**InfluxDB Slack:** [@craig](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,86 @@
---
title: discord.send() function
description: >
The `discord.send()` function sends a single message to a Discord channel using
a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&amp?page=3).
menu:
v2_0_ref:
name: discord.send
parent: Discord
weight: 202
---
The `discord.send()` function sends a single message to a Discord channel using
a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&amp?page=3).
_**Function type:** Output_
```js
import "contrib/chobbs/discord"
discord.send(
webhookToken: "mySuPerSecRetTokEn",
webhookID: "123456789",
username: "username",
content: "This is an example message",
avatar_url: "https://example.com/avatar_pic.jpg"
)
```
## Parameters
### webhookToken
Discord [webhook token](https://discord.com/developers/docs/resources/webhook).
_**Data type:** String_
### webhookID
Discord [webhook ID](https://discord.com/developers/docs/resources/webhook).
_**Data type:** String_
### username
Override the Discord webhook's default username.
_**Data type:** String_
### content
Message to send to Discord (2000 character limit).
_**Data type:** String_
### avatar_url
Override the Discord webhook's default avatar.
_**Data type:** String_
## Examples
##### Send the last reported status to Discord
```js
import "contrib/chobbs/discord"
import "influxdata/influxdb/secrets"
token = secrets.get(key: "DISCORD_TOKEN")
lastReported =
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses")
|> last()
|> findRecord(fn: (key) => true, idx: 0)
discord.send(
webhookToken:token,
webhookID: "1234567890",
username: "chobbs",
content: "The current status is \"${lastReported.status}\".",
avatar_url: "https://staff-photos.net/pic.jpg"
)
```
{{% note %}}
#### Package author and maintainer
**Github:** [@chobbs](https://github.com/chobbs)
**InfluxDB Slack:** [@craig](https://influxdata.com/slack)
{{% /note %}}

View File

@ -0,0 +1,23 @@
---
title: Flux Experimental JSON package
list_title: JSON package
description: >
The Flux experimental JSON package provides functions for working with JSON.
Import the `experimental/json` package.
menu:
v2_0_ref:
name: JSON
identifier: JSON-exp
parent: Experimental
weight: 301
v2.0/tags: [functions, json, package]
---
Flux experimental JSON functions provide tools for working with JSON.
Import the `experimental/json` package:
```js
import "experimental/json"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,52 @@
---
title: json.parse() function
description: >
The `json.parse()` function takes JSON data as bytes and returns a value.
menu:
v2_0_ref:
name: json.parse
parent: JSON-exp
weight: 401
---
The `json.parse()` function takes JSON data as bytes and returns a value.
The function can return lists, objects, strings, booleans, and float values.
All numeric values are returned as floats.
_**Function type:** Type conversion_
```js
import "experimental/json"
json.parse(
data: bytes(v: "{\"\"a\"\":1,\"\"b\"\":2,\"\"c\"\":3}")
)
```
## Parameters
### data
JSON data to parse.
_**Data type:** Bytes_
## Examples
##### Parse and use JSON data to restructure a table
```js
import "experimental/json"
data
|> map(fn: (r) => {
jsonData = json.parse(data: bytes(v: r._value))
return {
_time: r._time,
_field: r._field,
a: jsonData.a,
b: jsonData.b,
c: jsonData.c,
}
})
```

View File

@ -19,7 +19,7 @@ _**Output data type:** Boolean_
```js
import "strings"
strings.hasPrefix(v: "go gopher", t: "go")
strings.hasPrefix(v: "go gopher", prefix: "go")
// returns true
```
@ -31,7 +31,7 @@ The string value to search.
_**Data type:** String_
### t
### prefix
The prefix to search for.
_**Data type:** String_
@ -41,5 +41,5 @@ _**Data type:** String_
import "strings"
data
|> filter(fn:(r) => strings.hasPrefix(v: r.metric, t: "int_" ))
|> filter(fn:(r) => strings.hasPrefix(v: r.metric, prefix: "int_" ))
```

View File

@ -19,7 +19,7 @@ _**Output data type:** Boolean_
```js
import "strings"
strings.hasSuffix(v: "go gopher", t: "go")
strings.hasSuffix(v: "go gopher", suffix: "go")
// returns false
```
@ -31,7 +31,7 @@ The string value to search.
_**Data type:** String_
### t
### suffix
The suffix to search for.
_**Data type:** String_
@ -41,5 +41,5 @@ _**Data type:** String_
import "strings"
data
|> filter(fn:(r) => strings.hasSuffix(v: r.metric, t: "_count" ))
|> filter(fn:(r) => strings.hasSuffix(v: r.metric, suffix: "_count" ))
```

View File

@ -90,6 +90,8 @@ Related entries: [implicit block](#implicit-block), [explicit block](#explicit-b
A data type with two possible values: true or false.
By convention, you can express `true` as the integer `1` and false as the integer `0` (zero).
In [annotated CSV](/v2.0/reference/syntax/annotated-csv/), columns that contain
boolean values are annotated with the `boolean` datatype.
### bucket
@ -337,8 +339,10 @@ Related entries: [block](#block)
### float
A float represents real numbers and is written with a decimal point dividing the integer and fractional parts.
For example, 1.0, 3.14.
A real number written with a decimal point dividing the integer and fractional parts (`1.0`, `3.14`, `-20.1`).
InfluxDB supports 64-bit float values.
In [annotated CSV](/v2.0/reference/syntax/annotated-csv/), columns that contain
float values are annotated with the `double` datatype.
### flush interval
@ -466,9 +470,14 @@ Related entries: [aggregator plugin](#aggregator-plugin), [collection interval](
An entity comprising data on a server (or virtual server in cloud computing).
<!-- An instance in an InfluxDB Enterprise cluster may scale across multiple servers or nodes in a network. -->
### int (data type)
### integer
A data type that represents an integer, a whole number that's positive, negative, or zero.
A whole number that is positive, negative, or zero (`0`, `-5`, `143`).
InfluxDB supports 64-bit integers (minimum: `-9223372036854775808`, maximum: `9223372036854775807`).
In [annotated CSV](/v2.0/reference/syntax/annotated-csv/), columns that contain
integers are annotated with the `long` datatype.
Related entries: [unsigned integer](#unsigned-integer)
## J
@ -945,6 +954,8 @@ A stream includes a series of tables over a sequence of time intervals.
### string
A data type used to represent text.
In [annotated CSV](/v2.0/reference/syntax/annotated-csv/), columns that contain
string values are annotated with the `string` datatype.
## T
@ -1094,6 +1105,14 @@ InfluxDB supports the following unix timestamp precisions:
Related entries: [timestamp](#timestamp), [RFC3339 timestamp](#rfc3339-timestamp)
### unsigned integer
A whole number that is positive or zero (`0`, `143`). Also known as a "uinteger."
InfluxDB supports 64-bit unsigned integers (minimum: `0`, maximum: `18446744073709551615`).
In [annotated CSV](/v2.0/reference/syntax/annotated-csv/), columns that contain
integers are annotated with the `unisgnedLong` datatype.
Related entries: [integer](#integer)
### user
InfluxDB users are granted permission to access to InfluxDB.

View File

@ -16,6 +16,32 @@ Though newer versions of Flux may be available, they will not be included with
InfluxDB until the next InfluxDB v2.0 release._
{{% /note %}}
## v0.69.2 [2020-06-10]
### Bug fixes
- Include a hash of sources for `libflux`.
---
## v0.69.1 [2020-06-09]
### Bug fixes
- Fix experimental `json.parse()` test.
---
## v0.69.0 [2020-06-08]
### Features
- Add [Discord package](/v2.0/reference/flux/stdlib/contrib/discord/)
_(contributed by [@chobbs](https://github.com/chobbs))_.
- Add [`json.parse()` function](/v2.0/reference/flux/stdlib/experimental/json/parse/).
### Bug fixes
- Adjust error handling in Flux `date` package.
---
## v0.68.0 [2020-05-28]
This version of Flux introduces an updated type inference system that improves
performance, error messaging, and usability of the

View File

@ -8,6 +8,28 @@ menu:
weight: 101
---
## v2.0.0-beta.11 [2020-05-27]
{{% warn %}}
The beta 11 version was **not released**. Changes below are included in the beta 12 release.
{{% /warn %}}
### Features
- Ability to set UTC time for a custom time range query.
- Ability to set a minimum or maximum value for the y-axis visualization setting (rather than requiring both).
- New `csv2lp` library for converting CSV (comma separated values) to InfluxDB line protocol.
- Add influxdb version to the InfluxDB v2 API `/health` endpoint.
### Bug Fixes
- Automatically adjust the drop-down list width to ensure the longest item in a list is visible.
- Fix bug in Graph + Single Stat visualizations to ensure `timeFormat` persists.
- Authorizer now exposes the full permission set. This adds the ability to derive which organizations the Authorizer has access to read or write to without using a User Request Management (URM) service.
- Fix issue causing variable selections to hydrate all variable values, decreasing the impact on network requests.
- Resolve scrollbar issues to ensure datasets are visible and scrollable.
- Check status now displays a warning if loading a large amount.
## v2.0.0-beta.10 [2020-05-07]
### Features

View File

@ -1,6 +1,5 @@
---
title: Annotated CSV syntax
list_title: Annotated CSV
title: Annotated CSV
description: >
InfluxDB and Flux return query results in annotated CSV format.
You can also read annotated CSV directly from Flux with the `csv.from()` function
@ -9,10 +8,12 @@ weight: 103
menu:
v2_0_ref:
parent: Syntax
name: Annotated CSV
v2.0/tags: [csv, syntax]
aliases:
- /v2.0/reference/annotated-csv/
related:
- /v2.0/reference/flux/stdlib/csv/from/
- /v2.0/reference/syntax/annotated-csv/extended/
---
InfluxDB and Flux return query results in annotated CSV format.

View File

@ -0,0 +1,366 @@
---
title: Extended annotated CSV
description: >
Extended annotated CSV provides additional annotations and options that specify
how CSV data should be converted to [line protocol](/v2.0/reference/syntax/line-protocol/)
and written to InfluxDB.
menu:
v2_0_ref:
name: Extended annotated CSV
parent: Annotated CSV
weight: 201
v2.0/tags: [csv, syntax, write]
related:
- /v2.0/write-data/csv/
- /v2.0/reference/cli/influx/write/
- /v2.0/reference/syntax/line-protocol/
- /v2.0/reference/syntax/annotated-csv/
---
**Extended annotated CSV** provides additional annotations and options that specify
how CSV data should be converted to [line protocol](/v2.0/reference/syntax/line-protocol/)
and written to InfluxDB.
InfluxDB uses the [`csv2lp` library](https://github.com/influxdata/influxdb/tree/master/pkg/csv2lp)
to convert CSV into line protocol.
Extended annotated CSV supports all [Annotated CSV](/v2.0/reference/syntax/annotated-csv/)
annotations.
{{% warn %}}
The Flux [`csv.from` function](/v2.0/reference/flux/stdlib/csv/from/) only supports
**annotated CSV**, not **extended annotated CSV**.
{{% /warn %}}
To write data to InfluxDB, line protocol must include the following:
- [measurement](/v2.0/reference/syntax/line-protocol/#measurement)
- [field set](/v2.0/reference/syntax/line-protocol/#field-set)
- [timestamp](/v2.0/reference/syntax/line-protocol/#timestamp) _(Optional but recommended)_
- [tag set](/v2.0/reference/syntax/line-protocol/#tag-set) _(Optional)_
Extended CSV annotations identify the element of line protocol a column represents.
## CSV Annotations
Extended annotated CSV extends and adds the following annotations:
- [datatype](#datatype)
- [constant](#constant)
- [timezone](#timezone)
### datatype
Use the `#datatype` annotation to specify the [line protocol element](/v2.0/reference/syntax/line-protocol/#elements-of-line-protocol)
a column represents.
To explicitly define a column as a **field** of a specific data type, use the field
type in the annotation (for example: `string`, `double`, `long`, etc.).
| Data type | Resulting line protocol |
|:---------- |:----------------------- |
| [measurement](#measurement) | Column is the **measurement** |
| [tag](#tag) | Column is a **tag** |
| [dateTime](#datetime) | Column is the **timestamp** |
| [field](#field) | Column is a **field** |
| [ignored](#ignored) | Column is ignored |
| [string](#string) | Column is a **string field** |
| [double](#double) | Column is a **float field** |
| [long](#long) | Column is an **integer field** |
| [unsignedLong](#unsignedlong) | Column is an **unsigned integer field** |
| [boolean](#boolean) | Column is a **boolean field** |
#### measurement
Indicates the column is the **measurement**.
#### tag
Indicates the column is a **tag**.
The **column label** is the **tag key**.
The **column value** is the **tag value**.
#### dateTime
Indicates the column is the **timestamp**.
`time` is an alias for `dateTime`.
If the [timestamp format](#supported-timestamp-formats) includes a time zone,
the parsed timestamp includes the time zone offset.
By default, all timestamps are UTC.
You can also use the [`#timezone` annotation](#timezone) to adjust timestamps to
a specific time zone.
{{% note %}}
There can only be **one** `dateTime` column.
{{% /note %}}
The `influx write` command converts timestamps to [Unix timestamps](/v2.0/reference/glossary/#unix-timestamp).
Append the timestamp format to the `dateTime` datatype with (`:`).
```csv
#datatype dateTime:RFC3339
#datatype dateTime:RFC3339Nano
#datatype dateTime:number
#datatype dateTime:2006-01-02
```
##### Supported timestamp formats
| Timestamp format | Description | Example |
|:---------------- |:----------- |:------- |
| **RFC3339** | RFC3339 timestamp | `2020-01-01T00:00:00Z` |
| **RFC3339Nano** | RFC3339 timestamp | `2020-01-01T00:00:00.000000000Z` |
| **number** | Unix timestamp | `1577836800000000000` |
{{% note %}}
If using the `number` timestamp format and timestamps are **not in nanoseconds**,
use the [`influx write --precision` flag](/v2.0/reference/cli/influx/write/#flags)
to specify the [timestamp precision](/v2.0/reference/glossary/#precision).
{{% /note %}}
##### Custom timestamp formats
To specify a custom timestamp format, use timestamp formats as described in the
[Go time package](https://golang.org/pkg/time).
For example: `2020-01-02`.
#### field
Indicates the column is a **field**.
The **column label** is the **field key**.
The **column value** is the **field value**.
{{% note %}}
With the `field` datatype, field values are copies **as-is** to line protocol.
For information about line protocol values and how they are written to InfluxDB,
see [Line protocol data types and formats](/v2.0/reference/syntax/line-protocol/#data-types-and-format).
We generally recommend specifying the [field type](#field-types) in annotations.
{{% /note %}}
#### ignored
The column is ignored and not written to InfluxDB.
#### Field types
The column is a **field** of a specified type.
The **column label** is the **field key**.
The **column value** is the **field value**.
- [string](#string)
- [double](#double)
- [long](#long)
- [unsignedLong](#unsignedlong)
- [boolean](#boolean)
##### string
Column is a **[string](/v2.0/reference/glossary/#string) field**.
##### double
Column is a **[float](/v2.0/reference/glossary/#float) field**.
By default, InfluxDB expects float values that use a period (`.`) to separate the
fraction from the whole number.
If column values include or use other separators, such as commas (`,`) to visually
separate large numbers into groups, specify the following **float separators**:
- **fraction separator**: Separates the fraction from the whole number.
- **ignored separator**: Visually separates the whole number into groups but ignores
the separator when parsing the float value.
Use the following syntax to specify **float separators**:
```sh
# Syntax
<fraction-separator><ignored-separator>
# Example
.,
# With the float separators above
# 1,200,000.15 => 1200000.15
```
Append **float separators** to the `double` datatype annotation with a colon (`:`).
For example:
```
#datatype "double:.,"
```
{{% note %}}
If your **float separators** include a comma (`,`), wrap the column annotation in double
quotes (`""`) to prevent the comma from being parsed as a column separator or delimiter.
You can also [define a custom column separator](#define-custom-column-separator).
{{% /note %}}
##### long
Column is an **[integer](/v2.0/reference/glossary/#integer) field**.
If column values contain separators such as periods (`.`) or commas (`,`), specify
the following **integer separators**:
- **fraction separator**: Separates the fraction from the whole number.
_**Integer values are truncated at the fraction separator when converted to line protocol.**_
- **ignored separator**: Visually separates the whole number into groups but ignores
the separator when parsing the integer value.
Use the following syntax to specify **integer separators**:
```sh
# Syntax
<fraction-separator><ignored-separator>
# Example
.,
# With the integer separators above
# 1,200,000.00 => 1200000i
```
Append **integer separators** to the `long` datatype annotation with a colon (`:`).
For example:
```
#datatype "long:.,"
```
{{% note %}}
If your **integer separators** include a comma (`,`), wrap the column annotation in double
quotes (`""`) to prevent the comma from being parsed as a column separator or delimiter.
You can also [define a custom column separator](#define-custom-column-separator).
{{% /note %}}
##### unsignedLong
Column is an **[unsigned integer (uinteger)](/v2.0/reference/glossary/#unsigned-integer) field**.
If column values contain separators such as periods (`.`) or commas (`,`), specify
the following **uinteger separators**:
- **fraction separator**: Separates the fraction from the whole number.
_**Uinteger values are truncated at the fraction separator when converted to line protocol.**_
- **ignored separator**: Visually separates the whole number into groups but ignores
the separator when parsing the uinteger value.
Use the following syntax to specify **uinteger separators**:
```sh
# Syntax
<fraction-separator><ignored-separator>
# Example
.,
# With the uinteger separators above
# 1,200,000.00 => 1200000u
```
Append **uinteger separators** to the `long` datatype annotation with a colon (`:`).
For example:
```
#datatype "usignedLong:.,"
```
{{% note %}}
If your **uinteger separators** include a comma (`,`), wrap the column annotation in double
quotes (`""`) to prevent the comma from being parsed as a column separator or delimiter.
You can also [define a custom column separator](#define-custom-column-separator).
{{% /note %}}
##### boolean
Column is a **[boolean](/v2.0/reference/glossary/#boolean) field**.
If column values are not [supported boolean values](/v2.0/reference/syntax/line-protocol/#boolean),
specify the **boolean format** with the following syntax:
```sh
# Syntax
<true-values>:<false-values>
# Example
y,Y,1:n,N,0
# With the boolean format above
# y => true, Y => true, 1 => true
# n => false, N => false, 0 => false
```
Append the **boolean format** to the `boolean` datatype annotation with a colon (`:`).
For example:
```
#datatype "boolean:y,Y:n,N"
```
{{% note %}}
If your **boolean format** contains commas (`,`), wrap the column annotation in double
quotes (`""`) to prevent the comma from being parsed as a column separator or delimiter.
You can also [define a custom column separator](#define-custom-column-separator).
{{% /note %}}
### constant
Use the `#constant` annotation to define a constant column label and value for each row.
The `#constant` annotation provides a way to supply
[line protocol elements](/v2.0/reference/syntax/line-protocol/#elements-of-line-protocol)
that don't exist in the CSV data.
Use the following syntax to define constants:
```
#constant <datatype>,<column-label>,<column-value>
```
To provide multiple constants, include each `#constant` annotations on a separate line.
```
#constant measurement,m
#constant tag,dataSource,csv
```
{{% note %}}
For constants with `measurement` and `dateTime` datatypes, the second value in
the constant definition is the **column-value**.
{{% /note %}}
### timezone
Use the `#timezone` annotation to update timestamps to a specific timezone.
By default, timestamps are parsed as UTC.
Use the `±HHmm` format to specify the timezone offset relative to UTC.
##### Timezone examples
| Timezone | Offset |
|:-------- | ------: |
| US Mountain Daylight Time | `-0600` |
| Central European Summer Time | `+0200` |
| Australia Eastern Standard Time | `+1000` |
| Apia Daylight Time | `+1400` |
##### Timezone annotation example
```
#timezone -0600
```
## Define custom column separator
If columns are delimited using a character other than a comma, use the `sep`
keyword to define a custom separator **in the first line of your CSV file**.
```
sep=;
```
## Annotation shorthand
Extended annotated CSV supports **annotation shorthand**.
Include the column label, datatype, and _(optional)_ default value in each column
header row using the following syntax:
```
<column-label>|<column-datatype>|<column-default-value>
```
##### Example annotation shorthand
```
m|measurement,location|tag|Hong Kong,temp|double,pm|long|0,time|dateTime:RFC3339
weather,San Francisco,51.9,38,2020-01-01T00:00:00Z
weather,New York,18.2,,2020-01-01T00:00:00Z
weather,,53.6,171,2020-01-01T00:00:00Z
```
##### The shorthand explained
- The `m` column represents the **measurement** and has no default value.
- The `location` column is a **tag** with the default value, `Hong Kong`.
- The `temp` column is a **field** with **float** (`double`) values and no default value.
- The `pm` column is a **field** with **integer** (`long`) values and a default of `0`.
- The `time` column represents the **timestamp**, uses the **RFC3339** timestamp format,
and has no default value.
##### Resulting line protocol
```
weather,location=San\ Francisco temp=51.9,pm=38i 1577836800000000000
weather,location=New\ York temp=18.2,pm=0i 1577836800000000000
weather,location=Hong\ Kong temp=53.6,pm=171i 1577836800000000000
```

View File

@ -47,11 +47,13 @@ Click the refresh button (**{{< icon "refresh" >}}**) to manually refresh the da
1. Select from the time range options in the dropdown menu.
{{< img-hd src="/img/2-0-controls-time-range.png" alt="Select time range" />}}
{{< img-hd src="/img/2-0-controls-time-range.png" alt="Select time range" />}}
2. Select **Custom Time Range** to enter a custom time range with precision up to nanoseconds.
The default time range is 5 minutes.
> The custom time range uses the selected timezone (local time or UTC).
### Add variables
Click **Variables** to display variables available for your dashboard. For details, see [Use and manage variables](/v2.0/visualize-data/variables/)

View File

@ -46,11 +46,9 @@ See [Get started with Flux](/v2.0/query-data/get-started) to learn more about Fl
## Visualize your query
Select from available [visualization types](/v2.0/visualize-data/visualization-types/) or enable the **View Raw Data** option to view all of your query's results.
- Select an available [visualization types](/v2.0/visualize-data/visualization-types/) from the dropdown menu in the upper-left:
Select a visualization type from the dropdown menu in the upper-left.
{{< img-hd src="/img/2-0-visualization-dropdown.png" title="Visualization dropdown" />}}
{{< img-hd src="/img/2-0-visualizations-dropdown.png" title="Visualization dropdown" />}}
## Control your dashboard cell
@ -86,6 +84,8 @@ Click the refresh button ({{< icon "refresh" >}}) to manually refresh the dashbo
2. Select **Custom Time Range** to enter a custom time range with precision up to nanoseconds.
The default time range is 5m.
> The custom time range uses the selected timezone (local time or UTC).
### Query Builder or Script Editor
Click **Query Builder** to use the builder to create a Flux query. Click **Script Editor** to manually edit the query.

View File

@ -55,7 +55,7 @@ the visualization dropdown.
- **Y Tick Suffix**: Suffix to be added to y-value.
- **Y Axis Domain**: The y-axis value range.
- **Auto**: Automatically determine the value range based on values in the data set.
- **Custom**: Manually specify the value range of the y-axis.
- **Custom**: Manually specify the minimum y-axis value, maximum y-axis value, or range by including both.
- **Min**: Minimum y-axis value.
- **Max**: Maximum y-axis value.
- **Positioning**:

View File

@ -48,7 +48,7 @@ the visualization dropdown.
- **Y Tick Suffix**: Suffix to be added to y-value.
- **Y Axis Domain**: The y-axis value range.
- **Auto**: Automatically determine the value range based on values in the data set.
- **Custom**: Manually specify the value range of the y-axis.
- **Custom**: Manually specify the minimum y-axis value, maximum y-axis value, or range by including both.
- **Min**: Minimum y-axis value.
- **Max**: Maximum y-axis value.
- **Positioning**:

View File

@ -46,7 +46,7 @@ the visualization dropdown.
- **X Tick Suffix**: Suffix to be added to x-value.
- **X Axis Domain**: The x-axis value range.
- **Auto**: Automatically determine the value range based on values in the data set.
- **Custom**: Manually specify the value range of the x-axis.
- **Custom**: Manually specify the minimum y-axis value, maximum y-axis value, or range by including both.
- **Min**: Minimum x-axis value.
- **Max**: Maximum x-axis value.
@ -56,7 +56,7 @@ the visualization dropdown.
- **Y Tick Suffix**: Suffix to be added to y-value.
- **Y Axis Domain**: The y-axis value range.
- **Auto**: Automatically determine the value range based on values in the data set.
- **Custom**: Manually specify the value range of the y-axis.
- **Custom**: Manually specify the minimum y-axis value, maximum y-axis value, or range by including both.
- **Min**: Minimum y-axis value.
- **Max**: Maximum y-axis value.

View File

@ -48,7 +48,7 @@ the visualization dropdown.
- **Y Tick Suffix**: Suffix to be added to y-value.
- **Y Axis Domain**: The y-axis value range.
- **Auto**: Automatically determine the value range based on values in the data set.
- **Custom**: Manually specify the value range of the y-axis.
- **Custom**: Manually specify the minimum y-axis value, maximum y-axis value, or range by including both.
- **Min**: Minimum y-axis value.
- **Max**: Maximum y-axis value.

View File

@ -0,0 +1,493 @@
---
title: Write CSV data to InfluxDB
description: >
Use the [`influx write` command](/v2.0/reference/cli/influx/write/) to write CSV data
to InfluxDB. Include annotations with the CSV data to determine how the data translates
into [line protocol](/v2.0/reference/syntax/line-protocol/).
menu:
v2_0:
name: Write CSV data
parent: Write data
weight: 104
related:
- /v2.0/reference/syntax/line-protocol/
- /v2.0/reference/syntax/annotated-csv/
- /v2.0/reference/cli/influx/write/
---
Use the [`influx write` command](/v2.0/reference/cli/influx/write/) to write CSV data
to InfluxDB. Include [Extended annotated CSV](/v2.0/reference/syntax/annotated-csv/extended/)
annotations to specify how the data translates into [line protocol](/v2.0/reference/syntax/line-protocol/).
Include annotations in the CSV file or inject them using the `--header` flag of
the `influx write` command.
##### On this page
- [CSV Annotations](#csv-annotations)
- [Inject annotation headers](#inject-annotation-headers)
- [Skip annotation headers](#skip-annotation-headers)
- [Process input as CSV](#process-input-as-csv)
- [Specify CSV character encoding](#specify-csv-character-encoding)
- [Skip rows with errors](#skip-rows-with-errors)
- [Advanced examples](#advanced-examples)
##### Example write command
```sh
influx write -b example-bucket -f path/to/example.csv
```
##### example.csv
```
#datatype measurement,tag,float,dateTime:RFC3339
m,host,used_percent,time
mem,host1,64.23,2020-01-01T00:00:00Z
mem,host2,72.01,2020-01-01T00:00:00Z
mem,host1,62.61,2020-01-01T00:00:10Z
mem,host2,72.98,2020-01-01T00:00:10Z
mem,host1,63.40,2020-01-01T00:00:20Z
mem,host2,73.77,2020-01-01T00:00:20Z
```
##### Resulting line protocol
```
mem,host=host1 used_percent=64.23 1577836800000000000
mem,host=host2 used_percent=72.01 1577836800000000000
mem,host=host1 used_percent=62.61 1577836810000000000
mem,host=host2 used_percent=72.98 1577836810000000000
mem,host=host1 used_percent=63.40 1577836820000000000
mem,host=host2 used_percent=73.77 1577836820000000000
```
{{% note %}}
To test the CSV to line protocol conversion process, use the `influx write dryrun`
command to print the resulting line protocol to stdout rather than write to InfluxDB.
{{% /note %}}
## CSV Annotations
Use **CSV annotations** to specify which element of line protocol each CSV column
represents and how to format the data. CSV annotations are rows at the beginning
of a CSV file that describe column properties.
The `influx write` command supports [Extended annotated CSV](/v2.0/reference/syntax/annotated-csv/extended)
which provides options for specifying how CSV data should be converted into line
protocol and how data is formatted.
To write data to InfluxDB, data must include the following:
- [measurement](/v2.0/reference/syntax/line-protocol/#measurement)
- [field set](/v2.0/reference/syntax/line-protocol/#field-set)
- [timestamp](/v2.0/reference/syntax/line-protocol/#timestamp) _(Optional but recommended)_
- [tag set](/v2.0/reference/syntax/line-protocol/#tag-set) _(Optional)_
Use CSV annotations to specify which of these elements each column represents.
## Write raw query results back to InfluxDB
Flux returns query results in [Annotated CSV](/v2.0/reference/syntax/annotated-csv/).
These results include all annotations necessary to write the data back to InfluxDB.
## Inject annotation headers
If the CSV data you want to write to InfluxDB does not contain the annotations
required to properly convert the data to line protocol, use the `--header` flag
to inject annotation rows into the CSV data.
```sh
influx write -b example-bucket \
-f path/to/example.csv \
--header "#constant measurement,birds" \
--header "#datatype dataTime:2006-01-02,long,tag"
```
{{< flex >}}
{{% flex-content %}}
##### example.csv
```
date,sighted,loc
2020-01-01,12,Boise
2020-06-01,78,Boise
2020-01-01,54,Seattle
2020-06-01,112,Seattle
2020-01-01,9,Detroit
2020-06-01,135,Detroit
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
birds,loc=Boise sighted=12 1577836800000000000
birds,loc=Boise sighted=78 1590969600000000000
birds,loc=Seattle sighted=54 1577836800000000000
birds,loc=Seattle sighted=112 1590969600000000000
birds,loc=Detroit sighted=9 1577836800000000000
birds,loc=Detroit sighted=135 1590969600000000000
```
{{% /flex-content %}}
{{< /flex >}}
#### Use files to inject headers
The `influx write` command supports importing multiple files in a single command.
Include annotations and header rows in their own file and import them with the write command.
Files are read in the order in which they're provided.
```sh
influx write -b example-bucket \
-f path/to/headers.csv \
-f path/to/example.csv
```
{{< flex >}}
{{% flex-content %}}
##### headers.csv
```
#constant measurement,birds
#datatype dataTime:2006-01-02,long,tag
```
{{% /flex-content %}}
{{% flex-content %}}
##### example.csv
```
date,sighted,loc
2020-01-01,12,Boise
2020-06-01,78,Boise
2020-01-01,54,Seattle
2020-06-01,112,Seattle
2020-01-01,9,Detroit
2020-06-01,135,Detroit
```
{{% /flex-content %}}
{{< /flex >}}
##### Resulting line protocol
```
birds,loc=Boise sighted=12 1577836800000000000
birds,loc=Boise sighted=78 1590969600000000000
birds,loc=Seattle sighted=54 1577836800000000000
birds,loc=Seattle sighted=112 1590969600000000000
birds,loc=Detroit sighted=9 1577836800000000000
birds,loc=Detroit sighted=135 1590969600000000000
```
## Skip annotation headers
Some CSV data may include header rows that conflict with or lack the annotations
necessary to write CSV data to InfluxDB.
Use the `--skipHeader` flag to specify the **number of rows to skip** at the
beginning of the CSV data.
```sh
influx write -b example-bucket \
-f path/to/example.csv \
--skipHeader=2
```
You can then [inject new header rows](#inject-annotation-headers) to rename columns
and provide the necessary annotations.
## Process input as CSV
The `influx write` command automatically processes files with the `.csv` extension as CSV files.
If your CSV file uses a different extension, use the `--format` flat to explicitly
declare the format of the input file.
```sh
influx write -b example-bucket \
-f path/to/example.txt \
--format csv
```
{{% note %}}
The `influx write` command assumes all input files are line protocol unless they
include the `.csv` extension or you declare the `csv`.
{{% /note %}}
## Specify CSV character encoding
The `influx write` command assumes CSV files contain UTF-8 encoded characters.
If your CSV data uses different character encoding, specify the encoding
with the `--encoding`.
```sh
influx write -b example-bucket \
-f path/to/example.csv \
--encoding "UTF-16"
```
## Skip rows with errors
If a row in your CSV data is missing an
[element required to write to InfluxDB](/v2.0/reference/syntax/line-protocol/#elements-of-line-protocol)
or data is incorrectly formatted, when processing the row, the `influx write` command
returns an error and cancels the write request.
To skip rows with errors, use the `--skipRowOnError` flag.
```sh
influx write -b example-bucket \
-f path/to/example.csv \
--skipRowOnError
```
{{% warn %}}
Skipped rows are ignored and are not written to InfluxDB.
{{% /warn %}}
## Advanced examples
- [Define constants](#define-constants)
- [Annotation shorthand](#annotation-shorthand)
- [Use alternate numeric formats](#use-alternate-numeric-formats)
- [Use alternate boolean format](#use-alternate-boolean-format)
- [Use different timestamp formats](#use-different-timestamp-formats)
---
### Define constants
Use the Extended annotated CSV [`#constant` annotation](/v2.0/reference/syntax/annotated-csv/extended/#constant)
to add a column and value to each row in the CSV data.
{{< flex >}}
{{% flex-content %}}
##### CSV with constants
```
#constant measurement,example
#constant tag,source,csv
#datatype long,dateTime:RFC3339
count,time
1,2020-01-01T00:00:00Z
4,2020-01-02T00:00:00Z
9,2020-01-03T00:00:00Z
18,2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example,source=csv count=1 1577836800000000000
example,source=csv count=4 1577923200000000000
example,source=csv count=9 1578009600000000000
example,source=csv count=18 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
---
### Annotation shorthand
Extended annotated CSV supports [annotation shorthand](/v2.0/reference/syntax/annotated-csv/extended/#annotation-shorthand),
which lets you define the **column label**, **datatype**, and **default value** in the column header.
{{< flex >}}
{{% flex-content %}}
##### CSV with annotation shorthand
```
m|measurement,count|long|0,time|dateTime:RFC3339
example,1,2020-01-01T00:00:00Z
example,4,2020-01-02T00:00:00Z
example,,2020-01-03T00:00:00Z
example,18,2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example count=1 1577836800000000000
example count=4 1577923200000000000
example count=0 1578009600000000000
example count=18 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
#### Replace column header with annotation shorthand
It's possible to replace the column header row in a CSV file with annotation
shorthand without modifying the CSV file.
This lets you define column data types and default values while writing to InfluxDB.
To replace an existing column header row with annotation shorthand:
1. Use the `--skipHeader` flag to ignore the existing column header row.
2. Use the `--header` flag to inject a new column header row that uses annotation shorthand.
{{% note %}}
`--skipHeader` is the same as `--skipHeader=1`.
{{% /note %}}
```sh
influx write -b example-bucket \
-f example.csv \
--skipHeader
--header="m|measurement,count|long|0,time|dateTime:RFC3339"
```
{{< flex >}}
{{% flex-content %}}
##### Unmodified example.csv
```
m,count,time
example,1,2020-01-01T00:00:00Z
example,4,2020-01-02T00:00:00Z
example,,2020-01-03T00:00:00Z
example,18,2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example count=1 1577836800000000000
example count=4 1577923200000000000
example count=0 1578009600000000000
example count=18 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
---
### Use alternate numeric formats
If your CSV data contains numeric values that use a non-default fraction separator (`.`)
or contain group separators, [define your numeric format](/v2.0/reference/syntax/annotated-csv/extended/#double)
in the `double`, `long`, and `unsignedLong` datatype annotations.
{{% note %}}
If your **numeric format separators** include a comma (`,`), wrap the column annotation in double
quotes (`""`) to prevent the comma from being parsed as a column separator or delimiter.
You can also [define a custom column separator](##################).
{{% /note %}}
{{< tabs-wrapper >}}
{{% tabs %}}
[Floats](#)
[Integers](#)
[Uintegers](#)
{{% /tabs %}}
{{% tab-content %}}
{{< flex >}}
{{% flex-content %}}
##### CSV with non-default float values
```
#datatype measurement,"double:.,",dateTime:RFC3339
m,lbs,time
example,"1,280.7",2020-01-01T00:00:00Z
example,"1,352.5",2020-01-02T00:00:00Z
example,"1,862.8",2020-01-03T00:00:00Z
example,"2,014.9",2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example lbs=1280.7 1577836800000000000
example lbs=1352.5 1577923200000000000
example lbs=1862.8 1578009600000000000
example lbs=2014.9 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
{{% /tab-content %}}
{{% tab-content %}}
{{< flex >}}
{{% flex-content %}}
##### CSV with non-default integer values
```
#datatype measurement,"long:.,",dateTime:RFC3339
m,lbs,time
example,"1,280.0",2020-01-01T00:00:00Z
example,"1,352.0",2020-01-02T00:00:00Z
example,"1,862.0",2020-01-03T00:00:00Z
example,"2,014.9",2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example lbs=1280i 1577836800000000000
example lbs=1352i 1577923200000000000
example lbs=1862i 1578009600000000000
example lbs=2014i 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
{{% /tab-content %}}
{{% tab-content %}}
{{< flex >}}
{{% flex-content %}}
##### CSV with non-default uinteger values
```
#datatype measurement,"unsignedLong:.,",dateTime:RFC3339
m,lbs,time
example,"1,280.0",2020-01-01T00:00:00Z
example,"1,352.0",2020-01-02T00:00:00Z
example,"1,862.0",2020-01-03T00:00:00Z
example,"2,014.9",2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example lbs=1280u 1577836800000000000
example lbs=1352u 1577923200000000000
example lbs=1862u 1578009600000000000
example lbs=2014u 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
{{% /tab-content %}}
{{< /tabs-wrapper >}}
---
### Use alternate boolean format
Line protocol supports only [specific boolean values](/v2.0/reference/syntax/line-protocol/#boolean).
If your CSV data contains boolean values that line protocol does not support,
[define your boolean format](/v2.0/reference/syntax/annotated-csv/extended/#boolean)
in the `boolean` datatype annotation.
{{< flex >}}
{{% flex-content %}}
##### CSV with non-default boolean values
```
sep=;
#datatype measurement,"boolean:y,Y,1:n,N,0",dateTime:RFC3339
m,verified,time
example,y,2020-01-01T00:00:00Z
example,n,2020-01-02T00:00:00Z
example,1,2020-01-03T00:00:00Z
example,N,2020-01-04T00:00:00Z
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example verified=true 1577836800000000000
example verified=false 1577923200000000000
example verified=true 1578009600000000000
example verified=false 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}
---
### Use different timestamp formats
The `influx write` command automatically detects **RFC3339** and **number** formatted
timestamps when converting CSV to line protocol.
If using a different timestamp format, [define your timestamp format](/v2.0/reference/syntax/annotated-csv/extended/#datetime)
in the `dateTime` datatype annotation.
{{< flex >}}
{{% flex-content %}}
##### CSV with non-default timestamps
```
#datatype measurement,dateTime:2006-01-02,field
m,time,lbs
example,2020-01-01,1280.7
example,2020-01-02,1352.5
example,2020-01-03,1862.8
example,2020-01-04,2014.9
```
{{% /flex-content %}}
{{% flex-content %}}
##### Resulting line protocol
```
example lbs=1280.7 1577836800000000000
example lbs=1352.5 1577923200000000000
example lbs=1862.8 1578009600000000000
example lbs=2014.9 1578096000000000000
```
{{% /flex-content %}}
{{< /flex >}}

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB