Giter Club home page Giter Club logo

influxdb-cxx's Introduction

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}

influxdb-cxx's People

Contributors

awegrzyn avatar fmoessbauer avatar francisconroy avatar jmsanchezff avatar kingkili avatar linwanxiaoyehua avatar matwey avatar offa avatar rpatelski avatar rstephan avatar simonaldrich avatar steinerthomas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

influxdb-cxx's Issues

Use Catch for unit tests?

While the current test suites provide integration tests mostly, there's a lack of real unit tests.

At this point I think about using Catch (and Trompeloeil) for writing those.

Buffering totally broken

Hi,

when buffering is enabled, unfortunately the buffer queue is never flushed after conversion to the transmission format.
By that, the queue grows to infinity and the same data is send again and again...
Probably the bug was introduced in 61e15e1

I think, a mLineProtocolBatch.clear(); here would solve the problem.

But nonetheless, there are definitely tests missing to discover these kinds of bugs.
Also it makes me a bit skeptic about the overall quality of this project, as it seems like there slipped some bad PRs into the code.

Compilation warning on latest boost version

Latest Boost v1.74 warns on compile:

»#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.«
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~

According to an upstream issue v1.73 is affected too.

Related upstream issue: awegrzyn/influxdb-cxx#83

Remove Codecov

Codecov is not supported in this fork yet.

This probably gets rid of the coverage options in the cmake file too.

Redesign tests

Unit Tests

  • No preconditions
  • No database / external service access
  • #63 Fix Conan CMake generator conflict
  • Add InfluxDB::query() tests (requires Boost)
  • Target to execute unit tests only

Integration / System Tests

  • Proper cleanup of databases
  • #47 (comment)
  • Port to Catch
  • Make optional

Deployment tests

  • Conan (test package step)
  • Make install (related #56) — Later release
  • Subproject (related #56) — Later release

Misc

  • Improve test output on CI builds
  • Execute unit tests on MSVC ❓
  • Execute unit tests on OS X
  • Targets to execute unit and system tests separately

Crash when getTags are called but with empty tags

Consider revising the following, Otherwise we may get out of arrange error

std::string Point::getTags() const
{
  return mTags.substr(1, mTags.size());
}

to

std::string Point::getTags() const
{
     if(mTags.size()==){
        return "";
     }
  return mTags.substr(1, mTags.size());
}

Update Travis CI image

Update to latest Travis CI image. This obsoletes some packages necessary, as newer version are already shipped by the image.

Codecov upload broken

The codecov upload fails with:

/home/travis/.travis/functions: line 109: /home/travis/build/offa/influxdb-cxx/script/travis_post_codecov.sh: No such file or directory

Include the Conan wrapper into the main CMakeLists.txt?

Does it make sense to include the Conan wrapper cmake code into the main CMakeLists.txt?

The relevant part consists only of two lines, but the wrapper complicates the build unnecessarily.

Another possible approach: Test whether conanbuildinfo.cmake exists; if so, include it and call conan_basic_setup().

Benefit:

It simplifies the Conan build and it remains fully optional.

Drawback:

It introduces Conan related code – it's still optional though.

CC @steinerthomas

Certificate authenticity is not checked in HTTPS transport

In the HTTPS backend, checking the peers origin is explicitly disabled. While this allows to use self-signed-certificates, it also allows man-in-the-middle attacks.

I was able to connect against a local, self-signed influxdb via HTTPs, without getting even a notice on the certificate.

As the project is still in a 0.x version, I don't think we need a CVE here.

A fix can be found in #41.

Test against latest boost

Test against the latest version of boost. Since the latest CI image doesn't ship it, a conan build can be used instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.