Ingest data to InfluxDB
InfluxDB has a number of ways to ingest data.
Telegraf
Telegraf is the most common way to ingest data into InfluxDB. Telegraf is a plugin-driven server agent for collecting and reporting metrics for all kinds of data from databases, systems, and IoT devices. Telegraf has plugins to source a variety of metrics directly from the system itβs running on, pull metrics from third-party APIs, or even listen for metrics via a StatsD and Kafka consumer services. It also has output plugins to send metrics to a variety of other datastores, services, and message queues, including InfluxDB, Timescale (Postgress) and QuestDB.
Telegraf is written in Go and compiles into a single binary with no external dependencies, and requires a very minimal memory footprint. It is designed to be plugin-driven and has the concept of 4 distinct plugin types:
- Input Plugins collect metrics from the system, services, or 3rd party APIs
- Processor Plugins transform, decorate, and/or filter metrics
- Aggregator Plugins create aggregate metrics (e.g. mean, min, max, quantiles, etc.)
- Output Plugins write metrics to various destinations
Telegraf is designed to be modular and extensible. The complete list of plugins can be found in the Telegraf plugin list.
How to collect data with Telegraf
Install Telegraf
Telegraf is available for a variety of operating systems and architectures. See the Telegraf installation instructions for more information.
Configure Telegraf
Telegraf is configured via a single configuration file. The default location for the configuration file is /etc/telegraf/telegraf.conf
. See the Telegraf configuration documentation for more information.
An example configuration file for InfluxDB v1.8.10 (influxdbv1
) is shown below:
[global_tags]
dc = "denver-1"
[agent]
interval = "10s"
# OUTPUTS
[[outputs.influxdb]]
url = "https://https://5c9f5b5c.customers.exy.io:8086" # required.
database = "telegraf" # required.
precision = "s"
username = "admin"
password = "changeme"
# INPUTS
[[inputs.cpu]]
percpu = true
totalcpu = true
In this example we're collecting metrics from the CPU plugin and writing them to InfluxDB. The [[outputs.influxdb]]
section configures the InfluxDB output plugin. The [[inputs.cpu]]
section configures the CPU input plugin.
Start Telegraf
Start Telegraf using the following command:
telegraf --config /etc/telegraf/telegraf.conf
Verify data is being written to InfluxDB
Use the InfluxDB CLI to query the data that Telegraf is writing to InfluxDB:
influx -host https://5c9f5b5c.customers.exy.io -username admin -password changeme -database telegraf
> SELECT * FROM cpu
name: cpu
time cpu host usage_guest usage_guest_nice usage_idle usage_iowait usage_irq usage_nice usage_softirq usage_steal usage_system usage_user
---- --- ---- ----------- ---------------- ---------- ------------ --------- ---------- -------------- ----------- ------------
1623686400000000000 0 influxdb-1 0 0 99.99999 0 0 0 0 0 0 0
1623686400000000000 0 influxdb-2 0 0 99.99999 0 0 0 0 0 0 0
InfluxDB Client Libraries
The InfluxDB Client Libraries are a collection of libraries that provide a low-level API for interacting with InfluxDB. Use the InfluxDB Client Libraries to create a custom data ingestion application or integrate InfluxDB into your existing processes.
For more information about clients for InfluxDB v1.8.10 (influxdbv1
), see the InfluxDB Client Libraries documentation.
For more information about clients for InfluxDB v2.0.7 (influxdbv2
), see the InfluxDB Client Libraries documentation.
InfluxDB v1 and v2 Client Libraries for Python (influxdbv1
and influxdbv2
)
An example of using the Python client library to write data to InfluxDB is shown below:
pip install influxdb-client
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
bucket = "<my-bucket>"
org = "<my-org>"
token = "<my-token>"
# Store the URL of your InfluxDB instance
url="https://5c9f5b5c.customers.exy.io:8086"
client = influxdb_client.InfluxDBClient(
url=url,
token=token,
org=org
)
# Write script
write_api = client.write_api(write_options=SYNCHRONOUS)
p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
write_api.write(bucket=bucket, org=org, record=p)
InfluxDB API
The InfluxDB API provides a programmatic interface for interactions with InfluxDB. Use the InfluxDB API to create a custom data ingestion application or integrate InfluxDB into your existing processes.
For more information about the InfluxDB API for InfluxDB v1.8.10 (influxdbv1
), see the InfluxDB API documentation.
For more information about the InfluxDB API for InfluxDB v2.0.7 (influxdbv2
), see the InfluxDB API documentation.
InfluxDB v1 API
An example of using the InfluxDB API to write data to InfluxDB is shown below:
curl -i -XPOST "https://5c9f5b5c.customers.exy.io:8086/write?db=mydb/u=admin&p=changeme" --data-binary 'mymeas,mytag=1 myfield=90 1463683075000000000'
InfluxDB v2 API
An example of using the InfluxDB API to write data to InfluxDB is shown below:
curl -XPOST "https://5c9f5b5c.customers.exy.io:8086/api/v2/write?bucket=db/rp&precision=s/" \
-H 'Authorization: Token your-token' \
--data-raw "mem,host=host1 used_percent=23.43234543 1556896326"
Ingest some data π
You're ready to start ingesting data into InfluxDB!, if you need some help getting started in the ExyData platform check out our Getting Started Guide or contact us for more information.