Skip to content

Fork of the https://github.com/offa/influxdb-cxx project. Created for experimenting and getting the source working in Windows environment and Microsoft VisualStudio.

License

Notifications You must be signed in to change notification settings

UgisL/influxdb-cxx

This branch is 213 commits behind offa/influxdb-cxx:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5971402 · Mar 17, 2022
Mar 4, 2022
May 6, 2021
Mar 20, 2021
Mar 17, 2022
Mar 4, 2022
Mar 17, 2022
Mar 17, 2022
Oct 30, 2020
Sep 11, 2020
Jun 11, 2020
Sep 10, 2021
Sep 9, 2020
Jan 3, 2022
Mar 5, 2021
Jan 14, 2022

Repository files navigation

influxdb-cxx

CI GitHub release License C++

InfluxDB C++ client library

  • Batch write
  • Data exploration
  • Supported transports
    • HTTP/HTTPS with Basic Auth
    • UDP
    • Unix datagram socket

Installation

Build requirements

  • CMake 3.12+
  • C++17 compiler

Dependencies

  • CURL (required)
  • boost 1.57+ (optional – see Transports)

Generic

mkdir build && cd build
cmake ..
sudo make install

Quick start

Include in CMake project

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)

Basic write

// Provide complete URI
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");
influxdb->write(influxdb::Point{"test"}
  .addField("value", 10)
  .addTag("host", "localhost")
);

Batch write

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));
}
Note:

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();

Query

// 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 = idb->query("SELECT * FROM test");

Transports

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.

About

Fork of the https://github.com/offa/influxdb-cxx project. Created for experimenting and getting the source working in Windows environment and Microsoft VisualStudio.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 89.4%
  • CMake 7.8%
  • Python 2.2%
  • Shell 0.6%