2019-05-03 14:49:35 +00:00
---
title: Write data to InfluxDB
2019-05-03 19:23:37 +00:00
list_title: Write data
2019-05-03 14:49:35 +00:00
description: >
2019-05-07 03:09:01 +00:00
Collect and write time series data to InfluxDB using line protocol, Telegraf, data scrapers,
the InfluxDB v2 API, `influx` CLI, the InfluxDB UI, and client libaries.
2019-05-03 19:43:28 +00:00
weight: 2
2019-05-03 14:49:35 +00:00
menu:
v2_0:
name: Write data
v2.0/tags: [write, line protocol]
---
2019-10-11 17:54:48 +00:00
- [What you'll need ](#what-you-ll-need )
- [Ways to write data into InfluxDB ](#ways-to-write-data-into-influxdb )
- [User Interface ](#user-interface )
- [influx CLI ](#influx-cli )
- [InfluxDB API ](#influxdb-api )
2019-05-03 19:43:28 +00:00
- [Other ways to write data to InfluxDB ](#other-ways-to-write-data-to-influxdb )
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
### What you'll need
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
#### The basics
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
To write data into InfluxDB, you need an **organization** , a **bucket** , and an **authentication token** .
(All InfluxDB write interactions require an [authentication token ](/v2.0/security/tokens/ ).)
If you've installed using the graphical UI, you should have been guided through creating all of these.
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
#### Data
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
Of course, you'll also need data.
Use _line protocol_ format to write data into InfluxDB.
Each line represents a data point.
Each point requires a [*measurement* ](/v2.0/reference/line-protocol/#measurement )
and [*field set* ](/v2.0/reference/line-protocol/#field-set ) and may also include
a [*tag set* ](/v2.0/reference/line-protocol/#tag-set ) and a [*timestamp* ](/v2.0/reference/line-protocol/#timestamp ).
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
Line protocol data looks like this:
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
```sh
mem,host=host1 used_percent=23.43234543 1556892576842902000
cpu,host=host1 usage_user=3.8234,usage_system=4.23874 1556892726597397000
mem,host=host1 used_percent=21.83599203 1556892777007291000
```
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
Timestamps are essential in InfluxDB.
If a data point does not include a timestamp when it is received by the database, InfluxDB uses the current system time (UTC) of its host machine.
2019-05-07 03:09:01 +00:00
2019-10-11 17:54:48 +00:00
The default precision for timestamps is in nanoseconds.
If the precision of the timestamps is anything other than nanoseconds (`ns`),
2019-05-07 03:09:01 +00:00
you must specify the precision in your write request.
2019-05-03 17:43:07 +00:00
InfluxDB accepts the following precisions:
- `ns` - Nanoseconds
- `us` - Microseconds
- `ms` - Milliseconds
- `s` - Seconds
2019-10-11 17:54:48 +00:00
_For more details about line protocol, see the [Line protocol reference ](/v2.0/reference/line-protocol )._
<!-- Link to line protocol best practices -->
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
## Ways to write data into InfluxDB
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
To write data into InfluxDB, use one of the following methods:
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
- [User Interface ](#user-interface )
- [influx CLI ](#influx-cli )
- [InfluxDB API ](#influxdb-api )
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
### User Interface
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
To quickly start writing data, use the provided user interface.
By default the UI is at http://localhost:9999.
Launch `influxdb` , and navigate to the interface using a web browser.
Then follow the instructions below.
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
1. Click **Load Your Data** in the navigation menu.
2. Select the **Buckets** tab.
3. Under the bucket you want to write data to, click ** {{< icon " plus " > }} Add Data**.
4. Select from the following options:
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
- [Configure Telegraf Agent ](#configure-telegraf-agent )
- [Line Protocol ](#line-protocol )
- [Scrape Metrics ](#scrape-metrics )
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
---
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
#### Configure Telegraf Agent
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
To configure a Telegraf agent, see [Automatically create a Telegraf configuration ](/v2.0/write-data/use-telegraf/auto-config/#create-a-telegraf-configuration ).
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
---
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
#### Line Protocol
1. Select **Upload File** or **Enter Manually** .
- **Upload File:**
Select the time precision of your data.
Drag and drop the line protocol file into the UI or click to select the
file from your file manager.
- **Enter Manually:**
Select the time precision of your data.
Manually enter line protocol.
2. Click **Continue** .
A message indicates whether data is successfully written to InfluxDB.
3. To add more data or correct line protocol, click **Previous** .
4. Click **Finish** .
---
#### Scrape Metrics
To scrape metrics, see [Create a scraper ](/v2.0/write-data/scrape-data/manage-scrapers/create-a-scraper/#create-a-scraper-in-the-influxdb-ui ).
{{% cloud-msg %}}{{< cloud-name > }} does not support scrapers.
{{% /cloud-msg %}}
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
### influx CLI
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
From the command line, use the [`influx write` command ](/v2.0/reference/cli/influx/write/ ) to write data to InfluxDB.
2019-05-07 03:09:01 +00:00
Include the following in your command:
2019-05-03 17:43:07 +00:00
2019-05-07 03:09:01 +00:00
| Requirement | Include by |
|:----------- |:---------- |
2019-05-03 17:43:07 +00:00
| Organization | Use the `-o` ,`--org`, or `--org-id` flags. |
| Bucket | Use the `-b` , `--bucket` , or `--bucket-id` flags. |
| Precision | Use the the `-p` , `--precision` 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 `@` . |
2019-05-03 14:49:35 +00:00
2019-10-11 17:54:48 +00:00
To write a single data point, for example, run
2019-10-08 21:07:49 +00:00
2019-05-03 14:49:35 +00:00
```sh
2019-05-03 17:43:07 +00:00
influx write -b bucketName -o orgName -p s 'myMeasurement,host=myHost testField="testData" 1556896326'
2019-10-11 17:54:48 +00:00
```
2019-05-03 17:43:07 +00:00
2019-10-11 17:54:48 +00:00
To write data in line protocol from a file, try
2019-10-02 23:37:44 +00:00
2019-10-11 17:54:48 +00:00
```
2019-05-03 17:43:07 +00:00
influx write -b bucketName -o orgName -p s @/path/to/line -protocol.txt
2019-05-03 14:49:35 +00:00
```
2019-10-11 17:54:48 +00:00
### InfluxDB API
2019-09-18 21:59:13 +00:00
2019-10-11 17:54:48 +00:00
You can also write to InfluxDB using raw http requests.
Use the InfluxDB API `/write` endpoint to write data to InfluxDB.
Include the following in your request:
2019-09-18 21:59:13 +00:00
2019-10-11 17:54:48 +00:00
| Requirement | Include by |
|:----------- |:---------- |
| Organization | Use the `org` query parameter in your request URL. |
| Bucket | Use the `bucket` query parameter in your request URL. |
| Precision | Use the `precision` query parameter in your request URL. |
| Authentication token | Use the `Authorization: Token` header. |
| Line protocol | Pass as plain text in your request body. |
2019-10-08 21:07:49 +00:00
2019-10-11 17:54:48 +00:00
Below is an example API write request using `curl` :
2019-09-18 21:59:13 +00:00
2019-10-11 17:54:48 +00:00
```sh
curl -XPOST "http://localhost:9999/api/v2/write?org=YOUR_ORG& bucket=YOUR_BUCKET& precision=s" \
--header "Authorization: Token YOURAUTHTOKEN" \
--data-raw "mem,host=host1 used_percent=23.43234543 1556896326"
```
< a name = "./#api-ex" > permalink< / a >
2019-05-03 19:43:28 +00:00
2019-10-11 17:54:48 +00:00
### Other ways to write data to InfluxDB
2019-05-03 19:43:28 +00:00
{{< children > }}
2019-05-03 19:53:18 +00:00
### InfluxDB client libraries
2019-10-08 21:07:49 +00:00
2019-05-07 03:09:01 +00:00
Use language-specific client libraries to integrate with the InfluxDB v2 API.
2019-05-03 19:53:18 +00:00
See [Client libraries reference ](/v2.0/reference/client-libraries/ ) for more information.