See how InfluxDB 3.0 lowers storage costs by 90% compared with InfluxDB Open Source. Get Benchmarks
InfluxDB.
It's About Time.
Real-time insights from any time series data with a single, purpose-built database. Run at any scale in any environment in the cloud, on-premises, or at the edge.
import {InfluxDBClient} from '@influxdata/influxdb3-client'
import {tableFromArrays} from 'apache-arrow';
const database = process.env.INFLUX_DATABASE;
const token = process.env.INFLUX_TOKEN;
const host = "https://us-east-1-1.aws.cloud2.influxdata.com";
async function main() {
const client = new InfluxDBClient({host, token})
const query = `
SELECT
room,
DATE_BIN(INTERVAL '1 day', time) AS _time,
AVG(temp) AS temp,
AVG(hum) AS hum,
AVG(co) AS co
FROM home
WHERE time >= now() - INTERVAL '90 days'
GROUP BY room, _time
ORDER BY _time
`
const result = await client.query(query, database)
const data = {room: [], day: [], temp: []}
for await (const row of result) {
data.day.push(new Date(row._time).toISOString())
data.room.push(row.room)
data.temp.push(row.temp)
}
console.table([...tableFromArrays(data)])
client.close()
}
main()
c
from influxdb_client_3 import InfluxDBClient3
import pandas
import os
database = os.getenv('INFLUX_DATABASE')
token = os.getenv('INFLUX_TOKEN')
host="https://us-east-1-1.aws.cloud2.influxdata.com"
def querySQL():
client = InfluxDBClient3(host, database=database, token=token)
table = client.query(
'''SELECT
room,
DATE_BIN(INTERVAL '1 day', time) AS _time,
AVG(temp) AS temp,
AVG(hum) AS hum,
AVG(co) AS co
FROM home
WHERE time >= now() - INTERVAL '90 days'
GROUP BY room, _time
ORDER BY _time'''
)
print(table.to_pandas().to_markdown())
client.close()
querySQL()
c
package influxdbv3
import (
"context"
"fmt"
"io"
"os"
"text/tabwriter"
"github.com/apache/arrow/go/v12/arrow"
"github.com/InfluxCommunity/influxdb3-go/influx"
)
func QuerySQL() error {
url := "https://us-east-1-1.aws.cloud2.influxdata.com"
token := os.Getenv("INFLUX_TOKEN")
database := os.Getenv("INFLUX_DATABASE")
client, err := influx.New(influx.Configs{
HostURL: url,
AuthToken: token,
})
defer func (client *influx.Client) {
err := client.Close()
if err != nil {
panic(err)
}
}(client)
query := `
SELECT
room,
DATE_BIN(INTERVAL '1 day', time) AS _time,
AVG(temp) AS temp,
AVG(hum) AS hum,
AVG(co) AS co
FROM home
WHERE time >= now() - INTERVAL '90 days'
GROUP BY room, _time
ORDER BY _time
`
iterator, err := client.Query(context.Background(), database, query)
if err != nil {
panic(err)
}
w := tabwriter.NewWriter(io.Discard, 4, 4, 1, ' ', 0)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintln(w, "day\troom\ttemp")
for iterator.Next() {
row := iterator.Value()
day := (row["_time"].(arrow.Timestamp)).ToTime(arrow.TimeUnit(arrow.Nanosecond))
fmt.Fprintf(w, "%s\t%s\t%.2f\n", day, row["room"], row["temp"])
}
w.Flush()
return nil
}
c
using System;
using System.Threading.Tasks;
using InfluxDB3.Client;
using InfluxDB3.Client.Query;
namespace InfluxDBv3;
public class Query
{
static async Task QuerySQL()
{
const string hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
string? database = System.Environment.GetEnvironmentVariable("INFLUX_DATABASE");
string? authToken = System.Environment.GetEnvironmentVariable("INFLUX_TOKEN");
using var client = new InfluxDBClient(hostUrl, authToken: authToken, database: database);
const string sql = @"
SELECT
room,
DATE_BIN(INTERVAL '1 day', time) AS _time,
AVG(temp) AS temp,
AVG(hum) AS hum,
AVG(co) AS co
FROM home
WHERE time >= now() - INTERVAL '90 days'
GROUP BY room, _time
ORDER BY _time
";
Console.WriteLine("{0,-30}{1,-15}{2,-15}", "day", "room", "temp");
await foreach (var row in client.Query(query: sql))
{
Console.WriteLine("{0,-30}{1,-15}{2,-15}", row[1], row[0], row[2]);
}
Console.WriteLine();
}
}
c
package com.influxdb3.examples;
import com.influxdb.v3.client.InfluxDBClient;
import java.util.stream.Stream;
public final class Query {
private Query() {
//not called
}
/**
* @throws Exception
*/
public static void main() throws Exception {
final String hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
final char[] authToken = (System.getenv("INFLUX_TOKEN")).toCharArray();
final String database = System.getenv("INFLUX_DATABASE");
try (InfluxDBClient client = InfluxDBClient.getInstance(hostUrl, authToken, database)) {
String sql = """
SELECT
room,
DATE_BIN(INTERVAL '1 day', time) AS _time,
AVG(temp) AS temp, AVG(hum) AS hum, AVG(co) AS co
FROM home
WHERE time >= now() - INTERVAL '90 days'
GROUP BY room, _time
ORDER BY _time""";
String layoutHeading = "| %-16s | %-12s | %-6s |%n";
System.out.printf("--------------------------------------------------------%n");
System.out.printf(layoutHeading, "day", "room", "temp");
System.out.printf("--------------------------------------------------------%n");
String layout = "| %-16s | %-12s | %.2f |%n";
try (Stream
c
Code in the languages you love
Tap into our custom client libraries, powerful APIs and tools, or build it yourself, line by line.
“InfluxDB is a high-speed read and write database. So think of it. The data is being written in real time, you can read in real time, and when you’re reading it, you can apply your machine learning model. So, in real time, you can forecast, and you can detect anomalies.”
Rajeev Tomer
Sr. Manager of Data Engineering, Capital One
“InfluxDB has become our go-to database choice. Often if we are using a different tool, we figure out how to get data out of the tool into InfluxDB. It’s easier to use, performs better, and is cheaper.”