• Stars
    star
    110
  • Rank 307,454 (Top 7 %)
  • Language
    C++
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

InfluxDB C++ client library.

influxdb-cxx

ci GitHub release License C++ Conan Center

InfluxDB C++ client library

  • Batch write
  • Data exploration
  • Supported transports
    • HTTP/HTTPS
    • UDP
    • Unix datagram socket
    • TCP

Fork of the unmaintained awegrzyn/influxdb-cxx project.

Installation

Build requirements

  • CMake 3.12+
  • C++20 compiler

Dependencies

i) cpr needs to provide CMake support; some systems need to call ldconfig after .so installation.

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

Execute cmd

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

Transports

Supported transports:

Name Dependency URI protocol Sample URI
HTTP cpri) http/https http://localhost:8086?db=<db>
TCP boost tcp tcp://localhost:8094
UDP boost udp udp://localhost:8094
Unix socket boost unix unix:///tmp/telegraf.sock

i) boost is needed to support queries.

Configuration by URI

An underlying transport is configurable by passing an URI. [protocol] determines the actual transport type:

auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");

URI Format:

[protocol]://[username:password@]host:port[?db=database]

# Auth token:
[protocol]://[token@]host:port[?db=database]

Additional transport configuration (HTTP only)

The HTTP transport supports additional configurations beyond the limited URI parameters:

auto influxdb = InfluxDBBuilder::http("http://localhost:8086?db=test")
                    .setTimeout(std::chrono::seconds{20})
                    .setAuthToken("<token>")
                    .connect();

InfluxDB v2.x compatibility

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}

More Repositories

1

android-foss

A list of Free and Open Source Software (FOSS) for Android โ€“ saving Freedom and Privacy.
Shell
5,027
star
2

scope-guard

Implementation of Scoped Guards and Unique Resource as proposed in P0052.
C++
44
star
3

plug

Software for Fender Mustang Amps.
C++
39
star
4

keygen

KeyGen is a generator for keys and passwords.
C
17
star
5

stm32-eth

Experimental C++ Ethernet driver for Stm32 boards using W5100.
C
16
star
6

NBCndUnit

NetBeans C/C++ unit testing plugin โ€“ supporting CppUTest, GoogleTest (gtest) / GoogleMock (gmock) and libunittest C++.
Java
13
star
7

cmake-ada

Ada language support for CMake.
12
star
8

NB-CMake-Completion

NetBeans plugin providing (code-)completion for CMake files.
Java
8
star
9

cpp-guards

C++ RAII template classes / scope guards.
C++
8
star
10

nvim-config

Neovim config using vim-plug.
Lua
7
star
11

midi-footswitch

An Aruduino based USB MIDI Controller.
C++
4
star
12

docker-images

Docker Images.
Dockerfile
4
star
13

conan-restclient-cpp

Conan recipe for restclient-cpp.
Python
3
star
14

matcher

C++11 Hamcrest like Matcher implementation.
C++
2
star
15

danek

A configuration library for C++.
C++
2
star
16

CPUnit

A fork of CPUnit (http://cpunit.sourceforge.net/). CPUnit is a unit test framework for C++ applications and programs.
C++
2
star
17

ElsockControllerJava

A controller library for Elsock-devices written in Java.
Java
2
star
18

jenkins-push-url-generator

Generates Git Push Notification URLs for Jenkins.
Python
2
star
19

maven-action

GitHub Action to build Maven projects with different Java JDK versions.
Java
2
star
20

trackpack

Packaging of audio files / stems.
Python
2
star
21

git-update-script

Script to update all local git repositories from their remotes.
Shell
2
star
22

ElsockControllerCpp

A controller application / library for Elsock-devices written in C++ / Qt 5.
C++
2
star
23

release-tool

Tool to create project releases.
Python
2
star
24

docker-images-ci

Docker Images for CI.
Shell
1
star
25

cet

Simple test execution, mostly for container environments.
C++
1
star
26

ci-playground

Playground for CI testing.
1
star
27

misc-tools

Collection of scripts and other tools.
Shell
1
star