diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..fb93c98 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "macFrameworkPath": [ + "/System/Library/Frameworks", + "/Library/Frameworks" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/src/demo/main.cpp b/src/demo/main.cpp index 713b665..41ec552 100644 --- a/src/demo/main.cpp +++ b/src/demo/main.cpp @@ -1,5 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include #include #include @@ -8,50 +6,49 @@ #include #include #include +#include +#include +#include using namespace influxdb::api; - -int main(int argc, char* argv[]) -{ - try - { - const char* url = "http://localhost:8086"; - influxdb::raw::db_utf8 db(url, "demo"); - influxdb::api::simple_db api(url, "demo"); - influxdb::async_api::simple_db async_api(url, "demo"); - - api.drop(); - api.create(); - - // {"results":[{"series":[{"columns":["name"],"name":"databases","values":[["_internal"],["mydb"]]}]}]} - std::cout << db.get("show databases") << std::endl; - - async_api.insert(line("test", key_value_pairs(), key_value_pairs("value", 41))); - api.insert(line("test", key_value_pairs(), key_value_pairs("value", 42))); - - std::this_thread::sleep_for(std::chrono::milliseconds(101)); - - // {"results":[{"series":[{"columns":["time","value"],"name":"test","values":[["2016-10-28T22:11:22.8110348Z",42]]}]}]} - std::cout << db.get("select * from demo..test") << std::endl; - - // or if the async call passes through: - // {"results":[{"series":[{"name":"test","columns":["time","value"], - // "values":[["2016-12-09T20:24:18.8239801Z",42],["2016-12-09T20:24:18.9026688Z",41]]}]}]} - - api.drop(); - - // multiple lines formatted for one synchronous call: - // multiple,v1=1i - // multiple,v2=2i - std::cout << line - ("multiple", key_value_pairs("v1", 1), key_value_pairs()) - ("multiple", key_value_pairs("v2", 2), key_value_pairs()) - .get() << std::endl; - } - catch (std::exception const& e) - { - std::cerr << e.what() << std::endl; - } - - return 0; +using namespace std; + +int main(int argc, char *argv[]) { + try { + int keyNum = 0; + + influxdb::async_api::simple_db async_api("http://localhost:8086", "bluewhale"); + + struct timeval begin; + gettimeofday(&begin, NULL); + + while (1) { + struct timeval tv,td; + gettimeofday(&tv, NULL); + long time = (long long) (tv.tv_sec) * 1000000000 + tv.tv_usec * 1000; + + influxdb::api::key_value_pairs tags; + influxdb::api::key_value_pairs fields; + string g_app_name = "test"; + string rankID = "1"; + std::cout << "key num: " << keyNum << std::endl; + tags.add("appName", g_app_name); + tags.add("svrID", rankID); + fields.add("value", keyNum); + async_api.insert(line("t_lr_key", tags, fields)); + + gettimeofday(&td, NULL); + std::cout << "cost time " << (td.tv_sec - tv.tv_sec) * 1000000 + (td.tv_usec - tv.tv_usec) << std::endl; + + std::cout << "current time " << (td.tv_sec - begin.tv_sec) / 60 << std::endl << std::endl; + keyNum++; + sleep(1); + } + + } + catch (std::exception const &e) { + std::cerr << e.what() << std::endl; + } + + return 0; }