13 KiB
title | list_title | description | weight | menu | v2.0/tags | related | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Write data to InfluxDB | Write data | Collect and write time series data to InfluxDB using line protocol, Telegraf, data scrapers, the InfluxDB v2 API, `influx` CLI, the InfluxDB UI, client libraries, and third-party technologies. | 2 |
|
|
|
Collect and write time series data to InfluxDB using line protocol,
Telegraf, data scrapers, the InfluxDB v2 API, influx
command line interface (CLI),
the InfluxDB user interface (UI), client libraries, and third-party technologies.
What you'll need
To write data into InfluxDB, you need the following:
- organization – See View organizations for instructions on viewing your organization ID.
- bucket – See View buckets for instructions on viewing your bucket ID.
- authentication token – See View tokens for instructions on viewing your authentication token.
The InfluxDB setup process creates each of these.
Use line protocol format to write data into InfluxDB. Each line represents a data point. Each point requires a measurement and field set and may also include a tag set and a timestamp.
Line protocol data looks like this:
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
Timestamp precision
When writing data to InfluxDB, we recommend including a timestamp with each point. 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.
The default precision for timestamps is in nanoseconds.
If the precision of the timestamps is anything other than nanoseconds (ns
),
you must specify the precision in your write request.
InfluxDB accepts the following precisions:
ns
- Nanosecondsus
- Microsecondsms
- Millisecondss
- Seconds
For more details about line protocol, see the Line protocol reference and Best practices for writing data.
Ways to write data into InfluxDB
To write data into InfluxDB, use one of the following methods:
User Interface
To quickly start writing data, use the provided user interface.
-
Do one of the following:
- InfluxDB 2.0 OSS:
In your terminal, run
influxd
and then in your browser, go to the location where you're hosting the UI (by default, localhost:9999). - InfluxDB 2.0 Cloud: In your browser, go to https://cloud2.influxdata.com/.
- InfluxDB 2.0 OSS:
In your terminal, run
-
In the navigation menu on the left, select Data (Load Data) > Buckets.
-
Under the bucket you want to write data to, click {{< icon "plus" >}} Add Data.
-
Select from the following options:
Configure Telegraf Agent
To configure a Telegraf agent, see Automatically create a Telegraf configuration.
Line Protocol
- 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.
- Click Write Data. A message indicates whether data is successfully written to InfluxDB.
- To add more data or correct line protocol, click Previous.
- Click Finish.
Scrape Metrics
To scrape metrics, see Create a scraper.
{{% cloud %}}{{< cloud-name >}} does not support scrapers. {{% /cloud %}}
influx CLI
From the command line, use the influx write
command to write data to InfluxDB.
Include the following in your command:
Requirement | Include by |
---|---|
Organization | Use the -o ,--org , or --org-id flags. |
Bucket | Use the -b , --bucket , or --bucket-id flags. |
Precision | Use the -p , --precision flag. |
Authentication token | Set the INFLUX_TOKEN environment variable or use the t , --token flag. |
Data | Write data using line protocol or annotated CSV. Pass a file with the -f , --file flag. |
See Line protocol and Annotated CSV
Example influx write commands
Write a single line of line protocol
influx write \
-b bucketName \
-o orgName \
-p s \
'myMeasurement,host=myHost testField="testData" 1556896326'
Write line protocol from a file
influx write \
-b bucketName \
-o orgName \
-p s \
--format=lp
-f /path/to/line-protocol.txt
Write annotated CSV from a file
influx write \
-b bucketName \
-o orgName \
-p s \
--format=csv
-f /path/to/data.csv
InfluxDB API
Write data to InfluxDB using an HTTP request to the InfluxDB API /write
endpoint.
Use the POST
request method and include the following in your request:
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. |
Example API write request
Below is an example API write request using curl
.
The URL depends on the version and location of your InfluxDB 2.0 instance (see InfluxDB URLs).
To compress data when writing to InfluxDB, set the Content-Encoding
header to gzip
.
Compressing write requests reduces network bandwidth, but increases server-side load.
{{< code-tabs-wrapper >}} {{% code-tabs %}} Uncompressed Compressed {{% /code-tabs %}} {{% code-tab-content %}}
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
mem,host=host2 used_percent=26.81522361 1556896326
mem,host=host1 used_percent=22.52984738 1556896336
mem,host=host2 used_percent=27.18294630 1556896336
"
{{% /code-tab-content %}} {{% code-tab-content %}}
curl -XPOST "http://localhost:9999/api/v2/write?org=YOUR_ORG&bucket=YOUR_BUCKET&precision=s" \
--header "Authorization: Token YOURAUTHTOKEN" \
--header "Content-Encoding: gzip" \
--data-raw "
mem,host=host1 used_percent=23.43234543 1556896326
mem,host=host2 used_percent=26.81522361 1556896326
mem,host=host1 used_percent=22.52984738 1556896336
mem,host=host2 used_percent=27.18294630 1556896336
"
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
For information about InfluxDB API response codes, see InfluxDB API Write documentation.
Third-party technologies
A number of third-party technologies can be configured to send line protocol directly to InfluxDB.
If you're using any of the following technologies, check out the handy links below to configure these technologies to write data to InfluxDB (no additional software to download or install):
-
(Write metrics only) Vector 0.9 or later
Configure Vector
- On the Vector.dev docs site, see the InfluxDB Metrics Sink page.
- Under Configuration, click v2 to view configuration settings.
- Scroll down to How It Works for more detail.
Configure Apache NiFi
See the InfluxDB Processors for Apache NiFi Readme for details.
Configure OpenHAB
See the InfluxDB Persistence Readme for details.
Configure Apache JMeter
To configure Apache JMeter, complete the following steps in InfluxDB and JMeter.
In InfluxDB
- Find the name of your organization (needed to create a bucket and token).
- Create a bucket using the influx CLI and name it
jmeter
. - Create a token.
In JMeter
- Create a Backend Listener using the InfluxDBBackendListenerClient implementation.
- In the Backend Listener implementation field, enter org.apache.jmeter.visualizers.backend.influxdb.influxdbBackendListenerClient
- Under Parameters, specify the following:
- influxdbMetricsSender: org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
- influxdbUrl: http://localhost:9999/api/v2/write?org=my-org&bucket=jmeter (include the bucket and org you created in InfluxDB)
- application: InfluxDB2
- influxdbToken: my-token (include the token you created in InfluxDB)
- Include additional parameters as needed.
- Click Add to add the InfluxDBBackendListenerClient implementation.
Configure FluentD
See the influxdb-plugin-fluent Readme for details.
Other ways to write data
{{< children >}}
InfluxDB client libraries
Use language-specific client libraries to integrate with the InfluxDB v2 API. See Client libraries reference for more information.
Next steps
With your data in InfluxDB, you're ready to do one or more of the following:
Query and explore your data
Query data using Flux, the UI, and the influx
command line interface.
See Query data.
Process your data
Use InfluxDB tasks to process and downsample data. See Process data.
Visualize your data
Build custom dashboards to visualize your data. See Visualize data.
Monitor your data and send alerts
Monitor your data and sends alerts based on specified logic. See Monitor and alert.