InfluxDB: Difference between revisions
Created page with "InfluxDB is a time series database written in Go. This page contains notes relating to InfluxDB 2.x. My older notes on InfluxDB 1.x has been moved. == Introd..." |
No edit summary |
||
| Line 1: | Line 1: | ||
InfluxDB is a time series database written in Go. This page contains notes relating to InfluxDB 2.x. My older notes on [[InfluxDB 1.x|InfluxDB 1.x has been moved]]. | InfluxDB is a time series database written in Go. This page contains notes relating to InfluxDB 2.x. My older notes on [[InfluxDB 1.x|InfluxDB 1.x has been moved]]. | ||
== Introduction == | ==Introduction== | ||
InfluxDB 2.x integrates the TICK stack (Telegraf, InfluxDB, Chronograf, Kapacitor) into one binary. | InfluxDB 2.x integrates the TICK stack (Telegraf, InfluxDB, Chronograf, Kapacitor) into one binary. | ||
=== Installation and migration from InfluxDB 1.x === | === Migration considerations === | ||
Before you mgirate to InfluxDB 2.x, be aware of a few things: | |||
# You can't run InfluxQL. All your existing dashboards based on InfluxQL will need to be rewritten | |||
# InfluxQL is nice and might make more sense than the SQL-based language, but it's completely different. You should probably learn flux before you do the migration. | |||
# Your telegraf configs will need some tweaking. The database defaults to collectd and requires a token | |||
# Everything requires a token or authentication. If you use the line protocol with a shell script somewhere, you will need to update these scripts. | |||
===Installation and migration from InfluxDB 1.x=== | |||
I had an existing InfluxDB 1.x dataset which I want to migrate to InfluxDB 2.x. The upgrade is automatically triggered by the official docker image if it detects 1.x data but no 2.x data. You must also mount <code>/var/lib/influxdb2</code> as that will be where the migrated data as well as any new data will be written to. | I had an existing InfluxDB 1.x dataset which I want to migrate to InfluxDB 2.x. The upgrade is automatically triggered by the official docker image if it detects 1.x data but no 2.x data. You must also mount <code>/var/lib/influxdb2</code> as that will be where the migrated data as well as any new data will be written to. | ||
| Line 34: | Line 42: | ||
Once the migration is complete, you can remove the INIT environment variables and the old influxdb volume. | Once the migration is complete, you can remove the INIT environment variables and the old influxdb volume. | ||
== Tasks == | ==Tasks== | ||
=== Importing data from one bucket to another === | ===Importing data from one bucket to another=== | ||
I had Telegraf data written to a Telegraf | I had Telegraf data written to a Telegraf database. However, InfluxDB 2.x uses the collectd bucket. To import old Telegraf data to the new bucket, you can use the following flux query. | ||
{{Highlight | {{Highlight | ||
| code = from(bucket: "telegraf/autogen") | | code = from(bucket: "telegraf/autogen") | ||
|> range(start: -30d) | |> range(start: -30d) | ||
|> to(bucket: "collectd/autogen") | |> to(bucket: "collectd/autogen") | ||
|| lang = text | |||
}}However, I ran into this error: input field "free" on measurement "disk" is type integer, already exists as type float dropped. As a workaround, I made a filter which converted values to floats for this particular measurement: | |||
{{Highlight | |||
| code = from(bucket: "telegraf/autogen") | |||
|> range(start: v.timeRangeStart, stop: v.timeRangeStop) | |||
|> filter(fn: (r) => r["_measurement"] == "disk") | |||
|> map(fn:(r) => ({ r with x: float(v: r.x) })) | |||
|> to(bucket: "collectd/autogen") | |||
| lang = terminal | |||
}} | |||
=== Create a new variable === | |||
Unlike in Grafana where variables are part of a dashboard, in InfluxDB, variables are its own entity which needs to be created separately. To do so, go to settings -> variables. A variable can be defined as a query, csv, or key-pair map. Some common variables from queries can be found at https://docs.influxdata.com/influxdb/v2.0/visualize-data/variables/common-variables/. | |||
To create a new 'hosts' variable which contains all Telegraf hosts pushing metrics to InfluxDB, use this query: | |||
{{Highlight | |||
| code = import "influxdata/influxdb/schema" | |||
schema.tagValues(bucket: "collectd/autogen", tag: "host") | |||
| lang = text | | lang = text | ||
}} | }} | ||
When creating a dashboard, you can inject this hosts variable in the query editor or reference it from the '<code>v</code>' key. That is, <code>v.hosts</code>. | |||
Revision as of 22:53, 1 August 2021
InfluxDB is a time series database written in Go. This page contains notes relating to InfluxDB 2.x. My older notes on InfluxDB 1.x has been moved.
Introduction
InfluxDB 2.x integrates the TICK stack (Telegraf, InfluxDB, Chronograf, Kapacitor) into one binary.
Migration considerations
Before you mgirate to InfluxDB 2.x, be aware of a few things:
- You can't run InfluxQL. All your existing dashboards based on InfluxQL will need to be rewritten
- InfluxQL is nice and might make more sense than the SQL-based language, but it's completely different. You should probably learn flux before you do the migration.
- Your telegraf configs will need some tweaking. The database defaults to collectd and requires a token
- Everything requires a token or authentication. If you use the line protocol with a shell script somewhere, you will need to update these scripts.
Installation and migration from InfluxDB 1.x
I had an existing InfluxDB 1.x dataset which I want to migrate to InfluxDB 2.x. The upgrade is automatically triggered by the official docker image if it detects 1.x data but no 2.x data. You must also mount /var/lib/influxdb2 as that will be where the migrated data as well as any new data will be written to.
I used the following docker-compose when I first did the migration.
services:
influxdb:
image: influxdb:2.0.7
hostname: influxdb
networks:
- influxnet
- traefik
expose:
- "8086"
restart: always
volumes:
- /var/volumes/influx/influxdb:/var/lib/influxdb
- /var/volumes/influx/influxdb2:/var/lib/influxdb2
- /var/volumes/influx/config/influxdb.conf:/etc/influxdb/influxdb.conf
- /var/volumes/influx/types.db:/usr/share/collectd/types.db
environment:
DOCKER_INFLUXDB_INIT_USERNAME: admin
DOCKER_INFLUXDB_INIT_PASSWORD: AdminPassword1
DOCKER_INFLUXDB_INIT_ORG: home
DOCKER_INFLUXDB_INIT_BUCKET: initial
DOCKER_INFLUXDB_INIT_MODE: upgrade
Once the migration is complete, you can remove the INIT environment variables and the old influxdb volume.
Tasks
Importing data from one bucket to another
I had Telegraf data written to a Telegraf database. However, InfluxDB 2.x uses the collectd bucket. To import old Telegraf data to the new bucket, you can use the following flux query.
from(bucket: "telegraf/autogen")
However, I ran into this error: input field "free" on measurement "disk" is type integer, already exists as type float dropped. As a workaround, I made a filter which converted values to floats for this particular measurement:
from(bucket: "telegraf/autogen")
Create a new variable
Unlike in Grafana where variables are part of a dashboard, in InfluxDB, variables are its own entity which needs to be created separately. To do so, go to settings -> variables. A variable can be defined as a query, csv, or key-pair map. Some common variables from queries can be found at https://docs.influxdata.com/influxdb/v2.0/visualize-data/variables/common-variables/.
To create a new 'hosts' variable which contains all Telegraf hosts pushing metrics to InfluxDB, use this query:
import "influxdata/influxdb/schema"
schema.tagValues(bucket: "collectd/autogen", tag: "host")
When creating a dashboard, you can inject this hosts variable in the query editor or reference it from the 'v' key. That is, v.hosts.