InfluxDB C++ client library
- Batch write
- Data exploration
- Supported transports
- HTTP/HTTPS with Basic Auth
- UDP
- Unix datagram socket
Build requirements
- CMake 3.12+
- C++17 compiler
Dependencies
- CURL (required)
- boost 1.57+ (optional – see Transports)
mkdir build && cd build
cmake ..
sudo make install
The InfluxDB library is exported as target InfluxData::InfluxDB
.
project(example)
find_package(InfluxDB)
add_executable(example-influx main.cpp)
target_link_libraries(example-influx PRIVATE InfluxData::InfluxDB)
This target is also provided when the project is included as a subdirectory.
project(example)
add_subdirectory(influxdb-cxx)
add_executable(example-influx main.cpp)
target_link_libraries(example-influx PRIVATE InfluxData::InfluxDB)
// Provide complete URI
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
influxdb->write(influxdb::Point{"test"}
.addField("value", 10)
.addTag("host", "localhost")
);
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
// Write batches of 100 points
influxdb->batchOf(100);
for (;;) {
influxdb->write(influxdb::Point{"test"}.addField("value", 10));
}
When batch write is enabled, call flushBatch()
to flush pending batches.
This is of particular importance to ensure all points are written prior to destruction.
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
influxdb->batchOf(3);
influxdb->write(influxdb::Point{"test"}.addField("value", 1));
influxdb->write(influxdb::Point{"test"}.addField("value", 2));
// Flush batches, both points are written
influxdb->flushBatch();
// Available over HTTP only
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
/// Pass an IFQL to get list of points
std::vector<influxdb::Point> points = influxdb->query("SELECT * FROM test");
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
// Execute a command and receive it's response
const auto response = influxdb->execute("SHOW DATABASES");
An underlying transport is fully configurable by passing an URI:
[protocol]://[username:password@]host:port[?db=database]
List of supported transport is following:
Name | Dependency | URI protocol | Sample URI |
---|---|---|---|
HTTP | cURLi) | http /https |
http://localhost:8086?db=<db> |
UDP | boost | udp |
udp://localhost:8094 |
Unix socket | boost | unix |
unix:///tmp/telegraf.sock |
i) boost is needed to support queries.
The support for InfluxDB v2.x is limited at the moment. It's possible to use the v1.x compatibility backend though.
Please visit InfluxDB 1.x compatibility API docs for more information.
To create a v1.x compatible user (as described here):
influx v1 auth create --read-bucket ${BUCKET_ID} --write-bucket ${BUCKET_ID} --username ${USERNAME} --password ${PASSWORD}