Skip to content

Commit

Permalink
Merge pull request #3 from voiceip/windows_support
Browse files Browse the repository at this point in the history
New Features: Windows support + Tags + TCP Support
  • Loading branch information
euskadi31 authored Aug 26, 2020
2 parents 75742d2 + 4aea787 commit 6a8e991
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 78 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build
.vagrant
Vagrantfile
include/version.hpp
Debug/
Release/
.vscode/
build*
67 changes: 46 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
language: cpp
compiler:
- clang
- gcc
before_install:
- sudo apt-get -qq install python-software-properties
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get -qq update
- sudo apt-get -qq install gcc-4.8 g++-4.8
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
- sudo apt-get -qq install valgrind
- sudo apt-get -qq install cppcheck
- $CXX --version
env:
- STATSD_COMPILE_MODE=Debug
- STATSD_COMPILE_MODE=Release
script: make test STATSD_COMPILE_MODE=$STATSD_COMPILE_MODE
after_script: make lint
os:
- linux
- osx
# - STATSD_COMPILE_MODE=Release
branches:
only:
- master
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-6
- g++-6
- cmake
# - valgrind
- cppcheck
- build-essential
before_install:
- |-
case $TRAVIS_OS_NAME in
windows)
choco install visualstudio2019buildtools --package-parameters "--includeRecommended --includeOptional"
choco install make cmake cppcheck tree visualstudio2017-workload-vctools mingw
;;
linux)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50
;;
esac
matrix:
allow_failures:
- os: osx
include:
- os: linux
dist: trusty
script: make test STATSD_COMPILE_MODE=$STATSD_COMPILE_MODE
after_script: make lint
- os: osx
osx_image: xcode10
script: make test STATSD_COMPILE_MODE=$STATSD_COMPILE_MODE
after_script: make lint
- os: windows
compiler: msvc19
script:
- mkdir build && cd build
- cmake -DCMAKE_BUILD_TYPE=$STATSD_COMPILE_MODE ..
- cmake --build .
- tree
- ./bin/$STATSD_COMPILE_MODE/statsd-test.exe
allow_failures:
- os: windows
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ add_executable(
test/statsd.cpp
)

target_link_libraries(statsd-test statsd pthread)
IF (WIN32)
target_link_libraries(statsd-test statsd_static Ws2_32)
ELSE()
target_link_libraries(statsd-test statsd pthread)
ENDIF()


enable_testing()

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
StatsD client cpp [![Build Status](https://travis-ci.org/euskadi31/statsd-cpp.png)](https://travis-ci.org/euskadi31/statsd-cpp)
=================

A cpp client for the Etsy StatsD server.
A cpp client for the StatsD server.

Supported on MacOS, Unix, Windows

Install
-------
Expand Down
43 changes: 33 additions & 10 deletions include/statsd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@
#pragma once

#include <string>
#include <netinet/in.h>

#ifdef DEBUG
#include <random>
# include <iostream>
# define statsd_error(message) \
std::cerr << "StatsD: " << message << std::endl;

#ifdef _WIN32
#include <Winsock2.h>
#else
# define statsd_error(message)
#include <netinet/in.h>
#endif

# define statsd_error(message) \
std::cerr << "StatsD: " << message << std::endl;

class statsd
{
public:

/**
* Open udp socket
* Open udp/tcp socket
*
* @param host The host of StatsD server
* @param port The port of StatsD server
*/
static void open(const std::string& host, int16_t port = 8125);
* @param port The port of StatsD server
* @param mode SOCK_DGRAM/SOCK_STREAM for UDP/TCP
* return int 0 for success.
*/
static int open(const std::string& host, int16_t port = 8125, int mode = SOCK_DGRAM);

/**
* Log timing information
Expand Down Expand Up @@ -83,6 +87,21 @@ class statsd
*/
static void set(const std::string& key, const int64_t value, const float sample_rate = 1.0);


/**
* setPrefix
*
* @param prefix The prefix to prepend
*/
static void setPrefix(const std::string& _prefix);

/**
* setGlobalTags
*
* @param global_tags The global tags
*/
static void setGlobalTags(std::vector<std::string> global_tags);

/**
* Close socket
*/
Expand All @@ -108,6 +127,7 @@ class statsd
static std::string prepare(
const std::string& key,
const int64_t value,
const std::vector<std::string> tags,
const float sample_rate,
const std::string& unit
);
Expand All @@ -125,9 +145,12 @@ class statsd
{
struct sockaddr_in server = {};
int sock = -1;
int type = SOCK_DGRAM;
};

static statsd_t info;
static std::string prefix;
static std::string global_tags_str;

/**
* Send
Expand Down
Loading

0 comments on commit 6a8e991

Please sign in to comment.