InfluxDB is a time series database (TSDB) designed to handle large amounts of time series data with high efficiency.
It is ideal for applications that require storing and analyzing data that changes over time, such as performance metrics, sensor data, and event logs.
Some of the key features of InfluxDB include:
- Optimization for Time Series: Specifically designed to handle timestamped data.
- High-Speed Queries: Capable of performing complex queries on large volumes of data efficiently.
- Data Retention: Allows defining retention policies to manage historical data.
- Integration with Visualization Tools: Compatible with tools like Grafana for data visualization.
InfluxDB is widely used in infrastructure monitoring applications, IoT data analysis, and event log analysis, making it a great fit for Raspberry Pi.
How to Install InfluxDB on Raspberry Pi
Set Up the Repository
First, we ensure that our Raspberry Pi is up to date. We run the following commands to update the packages and the operating system:
sudo apt update
sudo apt upgrade
Next, to install InfluxData, which is not included in the standard Raspberry Pi OS repositories, we need to add the appropriate repository.
# Install the necessary dependencies
sudo apt install -y gnupg
# Download and install the public key for the InfluxDB repository
wget -qO - https://repos.influxdata.com/influxdb.key | sudo apt-key add -
# Create a list file for InfluxData
echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
Note: The buster
distribution is for Debian 10, which is compatible with Debian-based Raspberry Pi OS. Adjust if you are using a different version.
Install InfluxDB
With the repository added, we install InfluxDB. First, we update the package list:
sudo apt update
Finally, we install InfluxDB:
sudo apt install influxdb2
After completing the installation, we need to configure and enable InfluxDB to run as a service.
# Ensure influxdb config is picked up
sudo systemctl daemon-reload
# Tell systemd to run influxdb on reboot
sudo systemctl unmask influxdb
sudo systemctl enable influxdb
# Start up influxdb
sudo systemctl start influxdb
Finally, we check the service status to confirm that MongoDB is running correctly with:
sudo systemctl status influxdb
We should see output indicating that the service is active and running.
HTTP Service Configuration
By default, InfluxDB v2 should have the HTTP interface enabled. But it doesn’t hurt to make sure. For this, we do:
sudo nano /etc/influxdb/influxdb.conf
And we ensure that in the [http]
section, enabled
is set to true
. If not, we set it, save, and exit the file.
Now from the browser, we can access the address localhost:8086
and we will see the InfluxDB configuration window.
Using InfluxDB
Once installed and running, you can start using InfluxDB to manage your time series data.
Using InfluxDB
Once we have installed and set up InfluxDB, we can start managing it for our time series data.
The process is very straightforward. InfluxDB includes clients for major platforms and programming languages.
For example, if we want to use it with Python, we have to install the Influx client:
pip3 install influxdb-client
InfluxDB will provide us with a Token that we need to export as a system variable:
export INFLUXDB_TOKEN=your_very_long_token
Finally, we can connect with a script like this:
import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
token = os.environ.get("INFLUXDB_TOKEN")
org = "home"
url = "http://localhost:8086"
write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)