Skip to content

Commit

Permalink
#17 branch to reproduce the code in the demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Oct 20, 2018
1 parent 0baa1e2 commit bd4ef5f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
89 changes: 43 additions & 46 deletions src/demo/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <influxdb_raw_db_utf8.h>
#include <influxdb_simple_api.h>
#include <influxdb_line.h>
Expand All @@ -8,50 +6,49 @@
#include <iostream>
#include <thread>
#include <chrono>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>

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;
}

0 comments on commit bd4ef5f

Please sign in to comment.