Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 50 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,57 @@
language: cpp

compiler:
- gcc

before_script:
- mkdir build
- cd build
- cmake ..

install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi

script: make
sudo : false

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- cmake

matrix:
include:
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.9
- g++-4.9
env:
- CC_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
before_script:
- pip install --user cpp-coveralls
after_success:
- coveralls -E ".*gtest.*" -E ".*CMakeFiles.*" --exclude lib --exclude test
--exclude examples --gcov-options '\-lp'

- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-7
- g++-7
env:
- CC_EVAL="CC=gcc-7 && CXX=g++-7"

- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- clang-3.6
env:
- CC_EVAL="CC=clang-3.6 && CXX=clang++-3.6"

before_install:
- eval "${CC_EVAL}"
- cmake -DBUILD_TESTS=On .

script:
- make
- make test

11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ endif()

set (CMAKE_CXX_STANDARD 11)

if(CMAKE_BUILD_TYPE MATCHES Debug)
if(BUILD_TESTS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
elseif(CMAKE_BUILD_TYPE MATCHES Debug)
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4"
Expand Down Expand Up @@ -48,14 +50,18 @@ if(NOT CURL_FOUND)
set(CURL_FOUND TRUE)
set(CURL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/lib/curl/include)
set(CURL_LIBRARIES libcurl)

endif()

add_subdirectory(src)

if(BUILD_TESTS)
find_package(GTest)

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
endif()

include_directories(src)

if(NOT GTEST_FOUND)
message(STATUS
"Not using system gtest, using built-in googletest project instead.")
Expand All @@ -67,7 +73,6 @@ if(BUILD_TESTS)
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
set(GTEST_INCLUDE_DIRS ${gtest_SOURCE_DIR}/include)

# Group under the "tests/gtest" project folder in IDEs such as Visual Studio.
set_property(TARGET gtest PROPERTY FOLDER "tests/gtest")
Expand Down
9 changes: 6 additions & 3 deletions examples/ex_influx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
* SOFTWARE.
*/

#include <metricspp/httpconnector.hpp>
#include <metricspp/metricspp.hpp>

int main(int argc, char** argv) {
auto ms = metricspp::create_connection("http://127.0.0.1:8086/write?db=test",
metricspp::Tag{"server", "server01"},
metricspp::Tag{"region", "eu-east"});
auto ms =
metricspp::create_connection(std::make_shared<metricspp::HttpConnector>(
"http://127.0.0.1:8086/write?db=test"),
metricspp::Tag{"server", "server01"},
metricspp::Tag{"region", "eu-east"});

// Simple usage with different measurements
ms << "eth0" << 53;
Expand Down
55 changes: 43 additions & 12 deletions include/metricspp/_internal/d_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
#define L__INTERNAL_DATA_STREAM_H

#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <utility>

namespace metricspp {
class NetworkConnector;

namespace _internal {
class DataStreamPrivate;
namespace base {
class IConnector;
}

namespace _internal {
/** DataStream class
*
* Stream class object returns as the temporary object from
* \a MetricsConnector to keep input data for a measurement consistent.
*/
class DataStream {
public:
using value_storage = std::list<std::pair<std::string, std::string>>;

DataStream() = delete;

/** DataStream Constructor
Expand All @@ -30,7 +33,7 @@ class DataStream {
* @param connector Pointer on a valid \a NetworkConnector object
* @see NetworkConnector
*/
DataStream(const std::shared_ptr<NetworkConnector> &connector);
DataStream(const std::shared_ptr<base::IConnector> &connector);
~DataStream();

/** Set Measure name method
Expand All @@ -56,7 +59,7 @@ class DataStream {
void set_tags(const std::map<std::string, std::string> &tags);

/** Insertion operator
*

* Inserts name as a \a str for the next value which comes after the call.
*
* @param str Name of variable
Expand All @@ -65,6 +68,7 @@ class DataStream {
*/
DataStream &operator<<(const std::string &str);

DataStream &operator<<(const char *data);
/** Insertion operators(different types)
*
* Inserts numeric value for previous set variable name
Expand All @@ -75,19 +79,46 @@ class DataStream {
*/
DataStream &operator<<(bool value);
DataStream &operator<<(short value);
DataStream &operator<<(float value);
DataStream &operator<<(double value);
DataStream &operator<<(long double value);
DataStream &operator<<(int value);
DataStream &operator<<(long int value);
DataStream &operator<<(unsigned value);
DataStream &operator<<(long unsigned value);

DataStream(const DataStream &stream);
DataStream &operator=(const DataStream &in);

private:
const std::unique_ptr<DataStreamPrivate> m_data;
/** Set net variable
*
* Sets next variable field with serialized \a value
*
* @param value data as a string
*/
void set_next(const std::string &value);

/** Set record
*
* Set new record \a value by \a name or update it
* @param name Record name
* @param value Record value
*/
void set_record(const std::string &name, const std::string &value);

/** Format data method
*
* Forms a string for send from set of variables,tags and the measure name.
*
* @return Formatted string
*/
std::string form_data() const;

std::string m_previous; ///< Previusly set variable name
std::string m_measure; ///< Measure name
std::string m_tags; ///< Measure tags

value_storage m_values; ///< Measure values
value_storage::iterator m_pos; ///< Current position of values fill procedure

std::shared_ptr<base::IConnector> m_connector; ///< Network connector pointer
};
}
}
Expand Down
28 changes: 28 additions & 0 deletions include/metricspp/base/baseconnector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _BASE_BASECONNECTOR_
#define _BASE_BASECONNECTOR_

#include <string>

namespace metricspp {
namespace base {

/** IConnector interface class
*
* Represents a data interface for database. All custom connectors
* must be derived from this class.
*/
class IConnector {
public:
/** Post data method
*
* Sends \a data using post method
*
* @param data String of data for send
*
* @return \a true on sucess operation
*/
virtual bool post(const std::string &data) = 0;
};
}
}
#endif // ifndef _BASE_BASECONNECTOR_
64 changes: 64 additions & 0 deletions include/metricspp/httpconnector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef L_NETWORKCONNECTOR_H
#define L_NETWORKCONNECTOR_H

#include <string>

#include "base/baseconnector.hpp"

namespace metricspp {
/** HttpConnector class
*
* Network connector class objects communicate with a database
* and handle data streams
*/
class HttpConnector : public base::IConnector {
public:
HttpConnector();

/** HttpConnector constructor
*
* Constructor creates a new object with an \a addr to communicate
* with
*
* @param addr Database address
*/
HttpConnector(const std::string &addr);

virtual ~HttpConnector();

/** Post data method
*
* Reimplemented method.
*
* @param data
* @see base::IConnector::post
*
* @return \a true on sucess operation
*/
bool post(const std::string &data) override;

/** Set adress
*
* Set new database address
*
* @param addr Domain name or ip address as a string
*/
void set_address(const std::string &addr);

/** Get address
*
* Returns current usable address.
*
* @return Domain or ip address
*/
std::string address() const;

private:
std::string m_addr; ///< Usable address
std::string m_error; ///< Curl error buffer

void *m_handle; ///< Curl handler
};
}

#endif // L_NETWORKCONNECTOR_H
Loading