added information about writing csv, updated influx write doc, resolves #858

pull/871/head
Scott Anderson 2020-03-26 12:05:31 -06:00
parent 63b610b309
commit 15197e6dac
4 changed files with 92 additions and 20 deletions

View File

@ -1,8 +1,8 @@
--- ---
title: influx write title: influx write
description: > description: >
The 'influx write' command writes line protocol to InfluxDB either via a single The `influx write` command writes data to InfluxDB via stdin or from a specified file.
line of line protocol, or a via a file containing line protocol. Write data using line protocol or annotated CSV.
menu: menu:
v2_0_ref: v2_0_ref:
name: influx write name: influx write
@ -11,20 +11,29 @@ weight: 101
v2.0/tags: [write] v2.0/tags: [write]
--- ---
The `influx write` writes a single line of line protocol to InfluxDB, The `influx write` command writes data to InfluxDB via stdin or from a specified file.
or adds an entire file specified with an `@` prefix. Write data using [line protocol](/v2.0/reference/syntax/line-protocol) or
[annotated CSV](/v2.0/reference/syntax/annotated-csv).
## Usage ## Usage
``` ```
influx write [line protocol or @/path/to/points.txt] [flags] influx write [flags]
influx write [command]
``` ```
## Subcommands
| Subcommand | Description |
|:---------- |:----------- |
| [dryrun](/v2.0/reference/cli/influx/write/dryrun) | Write to stdout instead of InfluxDB |
## Flags ## Flags
| Flag | Description | Input type | {{< cli/mapped >}} | | Flag | Description | Input type | {{< cli/mapped >}} |
|:---- |:----------- |:----------:|:------------------ | |:---- |:----------- |:----------:|:------------------ |
| `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` | | `-b`, `--bucket` | Bucket name | string | `INFLUX_BUCKET_NAME` |
| `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` | | `--bucket-id` | Bucket ID | string | `INFLUX_BUCKET_ID` |
| `-h`, `--help` | Help for the `write` command | | | | `-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` | | `-o`, `--org` | Organization name | string | `INFLUX_ORG` |
| `--org-id` | Organization ID | string | `INFLUX_ORG_ID` | | `--org-id` | Organization ID | string | `INFLUX_ORG_ID` |
| `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` | | `-p`, `--precision` | Precision of the timestamps (default `ns`) | string | `INFLUX_PRECISION` |

View File

@ -0,0 +1,38 @@
---
title: influx write dryrun
description: >
The 'influx write dryrun' command prints write output to stdout instead of writing
to InfluxDB. Use this command to test writing data.
menu:
v2_0_ref:
name: influx write dryrun
parent: influx write
weight: 101
v2.0/tags: [write]
---
The `influx write dryrun` command prints write output to stdout instead of writing
to InfluxDB. Use this command to test writing data.
Supports [line protocol](/v2.0/reference/syntax/line-protocol) and
[annotated CSV](/v2.0/reference/syntax/annotated-csv).
Output is always **line protocol**.
## Usage
```
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` |
{{% cli/influx-global-flags %}}

View File

@ -9,6 +9,12 @@ menu:
v2_0: v2_0:
name: Write data name: Write data
v2.0/tags: [write, line protocol] v2.0/tags: [write, line protocol]
related:
- /v2.0/write-data/use-telegraf/
- /v2.0/api/#tag/Write, InfluxDB API /write endpoint
- /v2.0/reference/syntax/line-protocol
- /v2.0/reference/syntax/annotated-csv
- /v2.0/reference/cli/influx/write
--- ---
Collect and write time series data to InfluxDB using [line protocol](/v2.0/reference/syntax/line-protocol), Collect and write time series data to InfluxDB using [line protocol](/v2.0/reference/syntax/line-protocol),
@ -133,26 +139,45 @@ To scrape metrics, see [Create a scraper](/v2.0/write-data/scrape-data/manage-sc
From the command line, use the [`influx write` command](/v2.0/reference/cli/influx/write/) to write data to InfluxDB. From the command line, use the [`influx write` command](/v2.0/reference/cli/influx/write/) to write data to InfluxDB.
Include the following in your command: Include the following in your command:
| Requirement | Include by | | Requirement | Include by |
|:----------- |:---------- | |:----------- |:---------- |
| Organization | Use the `-o`,`--org`, or `--org-id` flags. | | Organization | Use the `-o`,`--org`, or `--org-id` flags. |
| Bucket | Use the `-b`, `--bucket`, or `--bucket-id` flags. | | Bucket | Use the `-b`, `--bucket`, or `--bucket-id` flags. |
| Precision | Use the `-p`, `--precision` flag. | | Precision | Use the `-p`, `--precision` flag. |
| Authentication token | Set the `INFLUX_TOKEN` environment variable or use the `t`, `--token` flag. | | Authentication token | Set the `INFLUX_TOKEN` environment variable or use the `t`, `--token` flag. |
| Line protocol | Write a single line as a string or pass a file path prefixed with `@`. | | Data | Write data using **line protocol** or **annotated CSV**. Pass a file with the `-f`, `--file` flag. |
##### Example influx write commands _See [Line protocol](/v2.0/reference/syntax/line-protocol/) and [Annotated CSV](/v2.0/reference/syntax/annotated-csv)_
To write a single data point, for example, run #### Example influx write commands
##### Write a single line of line protocol
```sh ```sh
influx write -b bucketName -o orgName -p s 'myMeasurement,host=myHost testField="testData" 1556896326' influx write \
-b bucketName \
-o orgName \
-p s \
'myMeasurement,host=myHost testField="testData" 1556896326'
``` ```
To write data in line protocol from a file, try ##### Write line protocol from a file
```sh
influx write \
-b bucketName \
-o orgName \
-p s \
--format=lp
-f /path/to/line-protocol.txt
``` ```
influx write -b bucketName -o orgName -p s @/path/to/line-protocol.txt
##### Write annotated CSV from a file
```sh
influx write \
-b bucketName \
-o orgName \
-p s \
--format=csv
-f /path/to/data.csv
``` ```
### InfluxDB API ### InfluxDB API

View File

@ -3,7 +3,7 @@
<h4 id="related-articles">Related articles</h4> <h4 id="related-articles">Related articles</h4>
<ul> <ul>
{{ range .Params.related }} {{ range .Params.related }}
{{ if in . "http" }} {{ if or (in . "http") (in . "/v2.0/api") }}
{{ $link := replaceRE `\,\s(.*)$` "" . }} {{ $link := replaceRE `\,\s(.*)$` "" . }}
{{ $title := replaceRE `^(\S*\,\s)` "" . }} {{ $title := replaceRE `^(\S*\,\s)` "" . }}
<li><a href="{{ $link }}" target="_blank">{{ $title }}</a></li> <li><a href="{{ $link }}" target="_blank">{{ $title }}</a></li>