Giter Club home page Giter Club logo

influxdb-cxx's Introduction

influxdb-cxx

Build Status codecov

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 compliler

Dependencies

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

Generic

git clone https://github.com/awegrzyn/influxdb-cxx.git
cd influxdb-cxx; mkdir build
cd build
cmake ..
sudo make install

macOS

brew install awegrzyn/influxdata/influxdb-cxx

Quick start

Basic write

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

Batch write

// Provide complete URI
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=test");
// Write batches of 100 points
influxdb->batchOf(100);

for (;;) {
  influxdb->write(Point{"test"}.addField("value", 10));
}

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<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 cURL http/https http://localhost:8086/?db=<db>
UDP boost udp udp://localhost:8094
Unix socket boost unix unix:///tmp/telegraf.sock

influxdb-cxx's People

Contributors

awegrzyn avatar fmoessbauer avatar francisconroy avatar jmsanchezff avatar rstephan 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

Watchers

 avatar  avatar  avatar  avatar  avatar

influxdb-cxx's Issues

UDS (Unix Socket Domain) issue

Hi,

I am new to C++. I have tried this API. It works good and code is maintained very well. I have tried both HTTP and UDP, it works fine. But I am getting error with UDS. I am not sure, can you please help me to understand and how to fix?

My URL is
std::string url = "unix:///tmp/influxdb.sock";

And the error is

terminate called after throwing an instance of boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >
what(): send_to: Protocol wrong type for socket

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Thanks in advance.

Got C4996 problem when using it into my project

Hi,
The example could be run correctly along in a project. But when I include this code into my project, the error came out.

c4996 'inet_addr':Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings

I had followed the solution in the stackoverflow, included the "Ws2tcpip.h" and changed the line 127 and line 205 in the influxdb.hpp as follows, then the program returned -3.

// For line 127
InetPton(AF_INET, (PCWSTR)(host.c_str()), &addr.sin_addr.s_addr);
if (addr.sin_addr.s_addr == INADDR_NONE) return -1;
// For line 205
InetPton(AF_INET, (PCWSTR)(si.host_.c_str()), &addr.sin_addr.s_addr);
if (addr.sin_addr.s_addr == INADDR_NONE) return -1;

Support for c++11

Hi, are you planning any version that can be built in c++11?
Thanks,
Roger.

Boost 1.73.0 build error

I was able to build the library with Boost completely removed from my system, but the build fails when I reinstall Boost 1.73.0 (Boost folder is located at /usr/local/include). I've tried earlier versions of Boost, but none seem to work. I thought that there could be a problem with my Boost installation, but other libraries seems to compile just fine.

I'm on Ubuntu 16.04, CMake 3.17.3, GNU 9.3.0, and Boost 1.73.0.

Scanning dependencies of target InfluxDB
[  5%] Building CXX object CMakeFiles/InfluxDB.dir/src/InfluxDB.cxx.o
In file included from /usr/local/include/boost/bind.hpp:30,
                 from /usr/local/include/boost/property_tree/json_parser/detail/parser.hpp:7,
                 from /usr/local/include/boost/property_tree/json_parser/detail/read.hpp:13,
                 from /usr/local/include/boost/property_tree/json_parser.hpp:16,
                 from /home/dave/influxdb-cxx/src/InfluxDB.cxx:15:
/usr/local/include/boost/bind.hpp:36:1: note: #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(
      | ^~~~~~~~~~~~~~~~~~~~
[ 10%] Building CXX object CMakeFiles/InfluxDB.dir/src/Point.cxx.o
[ 15%] Building CXX object CMakeFiles/InfluxDB.dir/src/InfluxDBFactory.cxx.o
[ 21%] Building CXX object CMakeFiles/InfluxDB.dir/src/UDP.cxx.o
[ 26%] Building CXX object CMakeFiles/InfluxDB.dir/src/UnixSocket.cxx.o
[ 31%] Building CXX object CMakeFiles/InfluxDB.dir/src/HTTP.cxx.o
[ 36%] Linking CXX shared library lib/libInfluxDB.so
[ 36%] Built target InfluxDB
Scanning dependencies of target testQuery
[ 42%] Building CXX object CMakeFiles/testQuery.dir/test/testQuery.cxx.o
[ 47%] Linking CXX executable bin/testQuery
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, char [1], char const (&) [1]>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, char const (&) [1])':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `bool boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, unsigned long, int>(boost::test_tools::tt_detail::equal_impl_frwd, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long const&, char const*, int const&, char const*)':
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const> const&>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const> const&)':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `influxdb::test::queryPerformance::test_method()':
/home/dave/influxdb-cxx/test/testQuery.cxx:48: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const> const&>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const> const&)':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `influxdb::test::queryPerformance::test_method()':
/home/dave/influxdb-cxx/test/testQuery.cxx:51: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, char [52], char const (&) [52]>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, char const (&) [52])':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `influxdb::test::failedQuery2::test_method()':
/home/dave/influxdb-cxx/test/testQuery.cxx:64: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, char [1], char const (&) [1]>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, char const (&) [1])':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `bool boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, unsigned long, int>(boost::test_tools::tt_detail::equal_impl_frwd, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long const&, char const*, int const&, char const*)':
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `bool boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char [5]>(boost::test_tools::tt_detail::equal_impl_frwd, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, char const (&) [5], char const*)':
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `bool boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char [9]>(boost::test_tools::tt_detail::equal_impl_frwd, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, char const (&) [9], char const*)':
/usr/local/include/boost/test/tools/old/impl.hpp:92: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o:/usr/local/include/boost/test/tools/old/impl.hpp:92: more undefined references to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' follow
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const> const&>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const> const&)':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `influxdb::test::timeStampVerify::test_method()':
/home/dave/influxdb-cxx/test/testQuery.cxx:40: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::lazy_ostream_impl<boost::unit_test::lazy_ostream, char [49], char const (&) [49]>::lazy_ostream_impl(boost::unit_test::lazy_ostream const&, char const (&) [49])':
/usr/local/include/boost/test/utils/lazy_ostream.hpp:61: undefined reference to `boost::unit_test::lazy_ostream::inst'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `influxdb::test::failedQuery2::test_method()':
/home/dave/influxdb-cxx/test/testQuery.cxx:64: undefined reference to `boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long)':
/usr/local/include/boost/test/tree/test_unit.hpp:265: undefined reference to `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::function<void ()> const&)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `__static_initialization_and_destruction_0(int, int) [clone .constprop.0]':
/usr/local/include/boost/test/unit_test_log.hpp:227: undefined reference to `boost::unit_test::unit_test_log_t::instance()'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `__static_initialization_and_destruction_0(int, int) [clone .constprop.0]':
/usr/local/include/boost/test/unit_test_suite.hpp:383: undefined reference to `boost::unit_test::framework::impl::master_test_suite_name_setter::master_test_suite_name_setter(boost::unit_test::basic_cstring<char const>)'
CMakeFiles/testQuery.dir/test/testQuery.cxx.o: In function `__static_initialization_and_destruction_0(int, int) [clone .constprop.0]':
/home/dave/influxdb-cxx/test/testQuery.cxx:12: undefined reference to `boost::unit_test::decorator::collector_t::instance()'
/home/dave/influxdb-cxx/test/testQuery.cxx:12: undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)'
/home/dave/influxdb-cxx/test/testQuery.cxx:28: undefined reference to `boost::unit_test::decorator::collector_t::instance()'
/home/dave/influxdb-cxx/test/testQuery.cxx:28: undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)'
/home/dave/influxdb-cxx/test/testQuery.cxx:43: undefined reference to `boost::unit_test::decorator::collector_t::instance()'
/home/dave/influxdb-cxx/test/testQuery.cxx:43: undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)'
/home/dave/influxdb-cxx/test/testQuery.cxx:54: undefined reference to `boost::unit_test::decorator::collector_t::instance()'
/home/dave/influxdb-cxx/test/testQuery.cxx:54: undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)'
/home/dave/influxdb-cxx/test/testQuery.cxx:61: undefined reference to `boost::unit_test::decorator::collector_t::instance()'
/home/dave/influxdb-cxx/test/testQuery.cxx:61: undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)'
collect2: error: ld returned 1 exit status
CMakeFiles/testQuery.dir/build.make:105: recipe for target 'bin/testQuery' failed
make[2]: *** [bin/testQuery] Error 1
CMakeFiles/Makefile2:107: recipe for target 'CMakeFiles/testQuery.dir/all' failed
make[1]: *** [CMakeFiles/testQuery.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

Incorrect format specifiers

ss >> std::get_time(&tm, "%FT%TZ");

I believe the format specifiers that are used with std::get_time are actually only valid with std::strftime. I'm unable to find concrete documentation to prove that strftime() and strptime() don't share all the specifiers in format string. However, I can illustrate the difference through an example:

$ cat sample.cpp
#include <sstream>
#include <iostream>
#include <chrono>
#include <ctime>
#include <iomanip>

int main(int argc, char** argv)
{
    std::stringstream ss("2020-03-18T09:11:25Z");

    std::cout << ss.str() << "\n";
    std::tm tm = {};

    #ifdef __FIX__
    ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
    #else
    ss >> std::get_time(&tm, "%FT%TZ");
    #endif

    tm.tm_isdst = -1;
    auto tstamp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
    auto t = std::chrono::system_clock::to_time_t(tstamp);
    std::cout << "Timestamp: " << std::ctime(&t) << "\n";

    return 0;
}

$ g++8 -g -std=c++17 sample.cpp -o sample
$ ./sample
2020-03-18T09:11:25Z
Timestamp: Wed Dec 31 18:59:59 1969

$ g++8 -g -std=c++17 -D __FIX__ sample.cpp -o sample
$ ./sample
2020-03-18T09:11:25Z
Timestamp: Wed Mar 18 09:11:25 2020

$ uname -a
FreeBSD ftlvssarkFreeBSD 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017     [email protected]:/usr/obj/usr/src/sys/GENERIC  amd64

Another issue here is that std::get_time doesn't set tm::is_dst, so I think we need to set it explicitly to -1, otherwise it remains at 0 and then std::mktime interprets that as if DST is in effect.

Add Travis CI

For the moment Ubuntu and macOS builds.
Would be nice to have Codecov, clang-format and Doxygen.

Compile Error

Hello,

I am trying to use the library in my application, using the first example in the README file:
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=test"); influxdb->write(Point{"test"} .addField("value", 10) .addTag("host", "localhost") );
When I am compiling my application I have the following errors occuring.
Any help would be appreciated

In file included from /usr/local/include/InfluxDB.h:15:0, from myapp.cpp:62: /usr/local/include/Point.h:27:13: error: expected ‘;’ at end of member declaration Point&& addTag(std::string_view key, std::string_view value); ^~~~~~ /usr/local/include/Point.h:27:37: error: expected ‘)’ before ‘key’ Point&& addTag(std::string_view key, std::string_view value); ^~~ /usr/local/include/Point.h:30:13: error: expected ‘;’ at end of member declaration Point&& addField(std::string_view name, std::variant<int, long long int, std::string, double> value); ^~~~~~~~ /usr/local/include/Point.h:30:39: error: expected ‘)’ before ‘name’ Point&& addField(std::string_view name, std::variant<int, long long int, std::string, double> value); ^~~~ /usr/local/include/Point.h:52:10: error: ‘variant’ in namespace ‘std’ does not name a template type std::variant<long long int, std::string, double> mValue; ^~~~~~~ In file included from myapp.cpp:62:0: /usr/local/include/InfluxDB.h:52:28: error: ‘std::string_view’ has not been declared void addGlobalTag(std::string_view name, std::string_view value); ^~~~~~~~~~~ /usr/local/include/InfluxDB.h:52:51: error: ‘std::string_view’ has not been declared void addGlobalTag(std::string_view name, std::string_view value);

and

error: ‘Point’ was not declared in this scope influxdb->write(Point{"test"}.addField("value", 10).addTag("host", "localhost"));

make install error

after "cmake --build build "
when use "make install"
get a error :
make: *** No rule to make target 'install'. Stop.
then i:
cd build
make install
new error get:
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Up-to-date: /usr/local/lib/libInfluxDB.so
CMake Error at cmake_install.cmake:60 (file):
file INSTALL cannot find "/home/windos/influxdb-cxx/include/InfluxDB".

make: *** [Makefile:86: install] Error 1

A coredump problem

Program terminated with signal 6, Aborted.
#0  0x00007f1cd458e1f7 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007f1cd458e1f7 in raise () from /lib64/libc.so.6
#1  0x00007f1cd458f8e8 in abort () from /lib64/libc.so.6
#2  0x00007f1cd4e959d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007f1cd4e93946 in ?? () from /lib64/libstdc++.so.6
#4  0x00007f1cd4e92909 in ?? () from /lib64/libstdc++.so.6
#5  0x00007f1cd4e93574 in __gxx_personality_v0 () from /lib64/libstdc++.so.6
#6  0x00007f1cd492c903 in ?? () from /lib64/libgcc_s.so.1
#7  0x00007f1cd492ce37 in _Unwind_Resume () from /lib64/libgcc_s.so.1
#8  0x00007f1cd09525c9 in _M_dispose (__a=..., this=<optimized out>) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:3234
#9  ~basic_string (this=<optimized out>, __in_chrg=<optimized out>) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:3621
#10 influxdb::InfluxDB::flushBuffer (this=0x7f1cc4002ab0) at /tmp/influxdb-cxx-master/src/InfluxDB.cxx:28
#11 0x00007f1cd09526cd in influxdb::InfluxDB::~InfluxDB (this=0x7f1cc4002ab0, __in_chrg=<optimized out>)
    at /tmp/influxdb-cxx-master/src/InfluxDB.cxx:47
#12 0x00007f1cd0e7b3a9 in operator() (this=<optimized out>, __ptr=0x7f1cc4002ab0) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/unique_ptr.h:78
#13 ~unique_ptr (this=<synthetic pointer>, __in_chrg=<optimized out>) at /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/unique_ptr.h:268
#14 foo (systemName="xx", base=base@entry=0x196b090) at statistics/statistics.cpp:41
#15 0x00007f1cd0e7b8e7 in crontab (ptr=0x196b090) at statistics/statistics.cpp:79
#16 0x00007f1cd5bebe25 in start_thread () from /lib64/libpthread.so.0
#17 0x00007f1cd465135d in clone () from /lib64/libc.so.6

I change InfluxDB.cxx:
InfluxDB::InfluxDB(std::unique_ptr transport) :
mTransport(std::move(transport))
{
// add this 4 lines
mBuffering = false;
mBuffer.clear();
mBufferSize = 0;
mGlobalTags = "";
}
And it's fixed

==============================
Reason:
Batch write will call flushBuffer() which may throw exception in the destructor.
If you use batch write, please call flushBuffer() manually and catch the exception.(In the old version, mBuffering is uninited, which may be a random value)

@awegrzyn Exception shouldn't be thrown in destructor. Can you change it?
Another problem, if we use batch write(mBuffering=true), but there is nothing in mBuffer, flushBuffer() will still transmit an empty string. I think it's not necessary.
You can change it like this:
void InfluxDB::flushBuffer() {
if (!mBuffering) {
return;
}
std::string stringBuffer;
for (const auto &i : mBuffer) {
stringBuffer+= i + "\n";
}
mBuffer.clear();
// no need to send an empty string
if (!stringBuffer.empty()) {
transmit(std::move(stringBuffer));
}
}

Avoid rounding of double fields

Adding a Point with a double field which has more than 6 digits results in the value being rounded, due to the default rounding precision, see here.
This behavior might lead to field type conflicts in the InfluxDb. These happen if the rounded value was the first one inserted into the measurement. In this case the database decides that the type for the specific value is integer, and inserting doubles into that field is not possible anymore, the following error shows up:

write failed: field type conflict: input field "value" on measurement "temp" is type float, already exists as type integer

Windows support?

Hi, this looks interesting but do you also plan to support Windows anytime soon?

About query and creat databases

thank you for your c++ api,but there is not function for querying and creating databases;
I'm new to network programming, so I don't know how to use the libcurl implementation to create and query a database,If you can tell me what to learn, maybe I can help implement these two functions

make build error

https://github.com/awegrzyn/influxdb-cxx/issues/16
OS:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"

Compiler version:
g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

boost version:1.7

cmake version 3.14.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).

http transport query failure

The http transport example in the readme does not work:

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

The trailing slash behind the port is not needed. The HTTP::initCurlRead(const std::string& url) (see src/HTTP.cxx) function does look for ? and adds the /query-path, which obviously results on http://localhost:8086//query?db=test (note the double //before query).

The workaround is simple, just omit the /. Maybe the library should be resilient for this kind of errors.

Issue Compiling with Intel Compiler

`[root@4d9621cf6ce5 build]# cmake ..
-- The CXX compiler identification is Intel 19.1.0.20200306
-- Check for working CXX compiler: /opt/intel/sw_dev_tools/compilers_and_libraries_2020.1.219/linux/bin/intel64/icpc
-- Check for working CXX compiler: /opt/intel/sw_dev_tools/compilers_and_libraries_2020.1.219/linux/bin/intel64/icpc - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/local/boost/include (found version "1.69.0") found components: unit_test_framework system program_options
-- Found CURL: /usr/local/lib64/libcurl.so (found version "7.70.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /root/Installation/influxdb-cxx-master/build
[root@4d9621cf6ce5 build]# make
Scanning dependencies of target InfluxDB
[ 14%] Building CXX object CMakeFiles/InfluxDB.dir/src/InfluxDB.cxx.o
/root/Installation/influxdb-cxx-master/src/InfluxDB.cxx(112): error: no suitable constructor exists to convert from "double" to "std::variant<int, long long, std::string, double>"
try { point.addField(column, boost::lexical_cast(value)); }
^

compilation aborted for /root/Installation/influxdb-cxx-master/src/InfluxDB.cxx (code 2)
make[2]: *** [CMakeFiles/InfluxDB.dir/src/InfluxDB.cxx.o] Error 2
make[1]: *** [CMakeFiles/InfluxDB.dir/all] Error 2
make: *** [all] Error 2

`

make build error

after "cmake -H. -Bbuild"
when use "cmake --build build"
get a error :
/usr/local/include/boost/test/unit_test.hpp:63: undefined reference to `boost::unit_test::unit_test_main(bool (*)(), int, char**)'
collect2: error: ld returned 1 exit status
CMakeFiles/testFactory.dir/build.make:85: recipe for target 'bin/testFactory' failed
make[2]: *** [bin/testFactory] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/testFactory.dir/all' failed
make[1]: *** [CMakeFiles/testFactory.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
I did followed the requirements

Help needed for building and deploying.

OS: Manjaro Linux
Using GCC as well as MinGW-w64 (from AUR).

  1. I want to build this library in a way that's statically linked to necessary components, so I can build this library as well as my project which uses it on my machine and deploy the resulted binaries directly on the target machine without having to build them there (as depending on the target machine's distribution and environment, building on the target machine may or may not be possible).

  2. Is it possible to build this library against MinGW-w64, as currently my project targets Windows and Linux, and is built using g++ on both platforms. If possible, what else might be needed for building this library (it'd be even better if I can cross-compile from Linux as I also have the cross-compiler installed here).

I'm still new to some C++ aspects... so correct me if I'm wrong. :-)

write func

write() return void?
I want to know what influxdb return, such as some err message.

query perfomance and points writing order

Hello,
I am writing 2 points with every "for" iteration and query for points database using time start of write and time start of stop write.
Everything works fine but the query response is realy slow compared to writing.
For instance:
tstart
For ( 1 < 10000 ) {
write -> point { A }
write -> point { B }
}
tstop
then i query all points in time interval -> SELECT * FROM /.*/ WHERE TIME >= (tstart) + " AND TIME < (tstop)

I manage to write (HTTP), 20000 points in total ( A and B ) in 200ms and manage to retrieve them in 1.7s which is almost 10 times slower. This ratio stays no matter how many points.
How can i improve this query time ?
And second:
I write 10000 points of A and 10000 points of B one by one but when using influx command line and select all, the result is sequential, first 10000 (A) points followed by 10000 (B) points with mixed database timestamp.

It should be timeseries:
timestamp1 - A
timestamp2 - B
timestamp3 - A
timestamp4 - B

Why is that?

forward slash in example

Hello In the example given:

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

The http query for write is formatted by

writeUrl.insert(url.find("?"), "/write");

and the final curl query would be

http://localhost:8086//write?db=test

Notice the two forward slashes before the write post "//write"
With libcurl/standalone curl 7.64.0 and influx 1.7.9-1 on ubuntu this double slash query will fail.
I can show an example with ping:

curl -v "http://localhost:8086//ping"

  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • Expire in 150000 ms for 3 (transfer 0x5555555c75c0)
  • Expire in 200 ms for 4 (transfer 0x5555555c75c0)
  • Connected to localhost (127.0.0.1) port 8086 (#0)

GET //ping HTTP/1.1
Host: localhost:8086
User-Agent: curl/7.64.0
Accept: /

< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< X-Influxdb-Build: OSS
< X-Influxdb-Version: 1.7.9
< Date: Wed, 13 Nov 2019 21:07:25 GMT
< Content-Length: 19

Whereas single slash is fine:

curl -v "http://localhost:8086/ping"

  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • Expire in 149999 ms for 3 (transfer 0x5555555c75c0)
  • Expire in 200 ms for 4 (transfer 0x5555555c75c0)
  • Connected to localhost (127.0.0.1) port 8086 (#0)

GET /ping HTTP/1.1
Host: localhost:8086
User-Agent: curl/7.64.0
Accept: /

< HTTP/1.1 204 No Content
< Content-Type: application/json
< Request-Id: b9a1d82a-0659-11ea-8016-0242c0a8b002
< X-Influxdb-Build: OSS
< X-Influxdb-Version: 1.7.9
< X-Request-Id: b9a1d82a-0659-11ea-8016-0242c0a8b002
< Date: Wed, 13 Nov 2019 21:08:22 GMT

So could you let me know what version of influx you are using for the example?
In my case I can get around this problem easy enough. But maybe something like

std::string writeUrl = url;
auto url_bslash = writeUrl.find("/?");
if (url_bslash != std::string::npos) {
writeUrl.replace(url_bslash, 2, "/write?");
} else {
writeUrl.insert(url.find("?"), "/write");
}

For the future?

thanks,

-mp

Better diagnostics/exception handling

Hi, The current api does not have any diagnostics in terms of failure to connect. For example if the db name is wrong etc. I have prototyped at least a connect method that can create a DB if it doesn't exist and plan to add several other exception handlers. But I am not sure if you have plans to address this and/or how you will do so.

I didnt want to get too far in a fork without at least asking if you have said plans/and or if you would accept PRs. For the connect method at least I had to touch Transport/HTTP as well as InfluxDB.

If you would let me know if you have interest in this please let me know.

Much appreciated.

-mp

Header install is installing in odd path

Hello, This statement:

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

installs in an odd location.

-- Installing: /usr/local/include/include
-- Installing: /usr/local/include/include/InfluxDB.h
-- Installing: /usr/local/include/include/InfluxDBFactory.h
-- Installing: /usr/local/include/include/Point.h
-- Installing: /usr/local/include/include/Transport.h

There is an extra include there. The recommended approach seems to be:

file(GLOB PHEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
set_target_properties(InfluxDB PROPERTIES PUBLIC_HEADER "${PHEADERS}")

Install library

install(TARGETS InfluxDB
EXPORT InfluxDBTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
This installs here:
-- Up-to-date: /usr/local/include/InfluxDB.h
-- Up-to-date: /usr/local/include/InfluxDBFactory.h
-- Up-to-date: /usr/local/include/Point.h
-- Up-to-date: /usr/local/include/Transport.h

Would you consider making the above change?

Thanks,

-mp

An error occurred when I query the database

My Code:

auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=test");
std::vector<influxdb::Point> points = influxdb->query("SELECT * FROM test");
cout << points.size() << endl;

And this is the structure of measurement "test":

select *from test
name: test
time                host      value
----                ----      -----
1583938657323591874 localhost 10
1583938681385599260 localhost 10

Error message:

g++ QueryTest.cc -o QueryTest -std=c++17 -lInfluxDB
./QueryTest 

terminate called after throwing an instance of ' 
boost::wrapexcept<boost::property_tree::json_parser::json_parser_error>' what():  <unspecified file>(1): garbage after data
Aborted (core dumped)

This is my environment:

gcc 7.3
boost 1.72.0
curl 7.69.1

What should I do to solve this problem, thanks.

Error 404 when querying a database.

My code:

auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=gmr_db/");
std::vector<Point> points;
points = influxdb->query("SELECT * FROM test");

for(unsigned int i = 0; i < points.size(); i++)
{
    cout << points[i].getName() << points[i].getTags() << points[i].getFields() << endl;
}

The issue:
When i try to query the database, an exception is thrown with this message:

terminate called after throwing an instance of 'influxdb::InfluxDBException'
what(): influx-cxx [HTTP::query]: Status code: 404

I don't know how to fix this since i'm fairly new to InfluxDB.
Also, if I try to curl the same endpoint, I also get a similar error from that command:

$ curl -i 'http://localhost:8086/ping/'
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.0
Date: Fri, 17 Apr 2020 15:18:53 GMT
Content-Length: 19
404 page not found

I also tried to run the tools provided with the library and this is the results I got from them.

Benchmark:

$ ./benchmark --url "http://localhost:8086/?db=gmr_db"
Written 1 points to http://localhost:8086/?db=gmr_db

testHttp:

$ ./testHttp
Running 2 test cases...
unknown location(0): fatal error: in "write1": influxdb::InfluxDBException: influx-cxx [HTTP::send]: Response code: 404
/home/xxxx/influxdb-cxx/test/testHttp.cxx(11): last checkpoint: "write1" test entry

*** 1 failure is detected in the test module "Test InfluxDB HTTP"

testQuery:

$ ./testQuery
Running 5 test cases...
/home/xxxx/influxdb-cxx/test/testQuery.cxx(16): error: in "query1": check points.size() == 3 has failed [0 != 3]
unknown location(0): fatal error: in "query1": memory access violation at address: 0x00000030: no mapping at fault address
/home/xxxx/influxdb-cxx/test/testQuery.cxx(17): last checkpoint

*** 2 failures are detected in the test module "Test InfluxDB Query"

Bad performance of writing to InfluxDB

I'm experiencing a bad performance using the influxdb-cxx. Here is the simple program I am using to test performance. In this script I am trying to insert 54M of lines in batch of 15000 items.
https://gist.github.com/michalspondr/1635e968d1e50c0c10fabe238e11f6b3

The performance of this program is very low, it takes hours to insert 54 elements, InfluxDB-python script is much faster than that. I can not tell where is the problem. CPU is not loaded, InfluxDB process reaches 30% CPU peak.

Writing values with their own timestamps.

I'm going to write values with their own timestamps to the database. These may be current data values, or historical data values.

However, it seems the Point class has its timestamp hardcoded to current timestamp. As such, it doesn't appear to be possible to use the value's own timestamp at the moment.

Is it possible to remove this restriction and allow user to specify timestamp manually? After all, the static function used to get current timestamp is publicly accessible.

Write throws exception error 400

I'm attempting to use this with influx 1.7.10 on a raspberry pi 4. I'm attempting to add data but it fails consistently. If I write one data point per write call two succeed until failure. If I attempt to do all of the data in a single call nothing is written. Using http protocol.

#include <InfluxDBFactory.h>
#include <iostream>

using namespace influxdb;
int main() {

auto db = InfluxDBFactory::Get("http://localhost:8086/?db=LTZ1000");
db->write(Point{DB_Date}.addField("reading", 7.1));
db->write(Point{DB_Date}.addField("temp", 23));
}

That works, but any further writes will fail. If attempting to do even the two fields in a single write call also fails.

Losing precision when querying Points whenever nanoseconds in timestamps matter.

As the title said, I realised that when I query points the current system using std::chrono makes it that we lose the nanoseconds precision in the timestamp, making it possible to have to Points object with the same ID. I know that the nanoseconds are optional with InfluxDB, but I was wondering if it would be faisible to have it.

Help: Http::query error, Status code 404

I use the client to test write/query function of influxdb-cxx ,compiled with macro INFLUXDB_WITH_BOOST.
It wrote successfully, but when I query data from db, it throw an exception as follow:
influx-cxx [HTTP::query]: Status code: 404
I find the Http::query use GET to get the data, then I use command like this curl -i -XPOST 'http://localhost:8086/query?db=testDB' --data-urlencode "q=SELECT * FROM weather",it works.
Influxdb 1.8 doesn't support HTTP/GET??? Can anbody give me some help???
Code like this:

 auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=testDB");
    influxdb->write(influxdb::Point{"weather"}
        .addTag("altitude", "3000")
        .addTag("area", "North")
        .addField("temp", 100)
        .addField("humidity", 258)
    );

    printf("Query From influxDB ...\n");
    auto idb = influxdb::InfluxDBFactory::Get("http://localhost:8086/?db=testDB");
    try {
        idb->query("SELECT * FROM weather");
    } catch (influxdb::InfluxDBException &e) {
        std::cout << e.what() << std::endl;
    }

Possible to separate Point definition and db->write call ?

Could you please tell me if it is possible to separate the "Point" definition and the db->write() call:

I did not find it in the exemples and the following test code I wrote failed to compile:

 influxdb = influxdb::InfluxDBFactory::Get("http:/127.0.0.1/?db=dbtest");
 Point point = Point{"test"}.addField("value", 10);
 point.addField("value2", 20);
 influxdb->write(point);

decoder.cpp:89:18: error: ‘class std::unique_ptrinfluxdb::InfluxDB’ has no member named ‘write’
influxdb.write(point);
^~~~~

my compiler cann't compile code in Point.cxx:28

In point.cxx file, there are invalid operands。
image
the error log is followed
./src/Point.cxx:27: error: invalid operands to binary expression ('std::stringstream' (aka 'basic_stringstream<char, char_traits, allocator >') and 'std::string_view' (aka 'basic_string_view'))

After I used name.data() to handle it, the porgram throw a unhandled exception from ucrtbased.dll

image
I don't know if it's because I don't have a local database

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.