vthiery / cpp-statsd-client Goto Github PK
View Code? Open in Web Editor NEWA header-only StatsD client implemented in C++
License: MIT License
A header-only StatsD client implemented in C++
License: MIT License
Hi, thanks for the rare cpp statsd client!
We'd like to use the client but my concern is about if the client is thread safe?
if not do you have some suggestions to use the client in multi-threads web services?
At the moment we have 2 modes for StatsdClient
:
I propose to make this interface a little more customizable by allowing each of these pieces to be configured individually. The specific pieces I'm talking about are:
Basically I'm hoping to refactor the configuration to allow more control by the end application on how and when the bytes get shipped over the socket.
In my specific case I have an application which does a bunch of heavy processing in a tight loop, when its done it returns the result to a client who requested it and then does some cleanup. This cleanup is done outside of the request loop, ie it returns the result before it blocks on cleaning up so that the requester isnt waiting on cleanup. This cleanup makes an idea spot for me to fire off any stats i've collected during the processing of that request. I could make use of the batchign as-is but i dont want:
For this reason it would be really useful to add a mode in which I can set a batch size to whatever maximum makes sense on my network. Have a queue to which my hot loop adds stats as it runs. And then have a method on the StatsdClient
that allows me to flush that queue in my cleanup after my algorithm has run.
It probably goes without saying but I'm happy to implement this feature so please feel free to assign me to it unless it sounds like something you'd rather not have in the library.
Currently CI does not check for properly linted code. We use clang-format here with the checked in style but we dont validate it on CI which makes for a bunch of work for any reviewer to sift through. To save some work, lets have the computers do it for us and run lint and fail the build if doing so shows any differences with what is checked in.
Also differences in versions of clang-format will do different things with your style file. Should we pin the version to avoid that problem?
Recently we added github actions to the repo which build and run a test application that publishes stats a few different ways. At the moment all it does is test that the code compiles and doesn't complain when you run it. This is simply not thorough enough. For proper testing we need to:
There may be some interesting (ie more difficult) stuff to test here regarding randomness and the frequency of collection, but I'm sure we can figure something out!
@vthiery i suppose you cannot assign this task to me but suffice it to say i will PR this work
does a cpp-statsd-server exist? thanks
At the moment the API requires you to specify your metric prefix with the trailing .
OR to specify your metrix key with a leading .
to separate the two in the outgoing metric. We should do this convenience for people and document that it is being done. More info here: #19 (comment)
Would it be much work to add this lib to the public conan repo?
This issue is based on the review comment here: #19 (comment)
The idea here is that we'd like to make it impossible for the client to send messages with bogus formatting but the current API allows users to send metrics manually by specifying the metric type as a string. This opens the door for users to pass a string that is not valid and would force us to validate it and set an error message if invalid. With a small (but breaking) API change we can side step the whole issue by:
send
method private
set
and histogram
are missing)To follow with semver we will need to increment the major revision though.
@vthiery In general do you think this is a worthwhile thing to do?
We were wondering if tags are supported by this client library and how they should be used.
We are looking something similar to python statsd client metrics tagging feature
import statsd
c = statsd.StatsClient('localhost', 8125, prefix='foo')
c.incr('bar', tags = {"key1": "value1", "key2":"value2"})
As discussed here https://stackoverflow.com/questions/49852654/sending-statsd-metrics-with-tags-from-python-client
I have tried to use this lib in an existing CMake proejct.
Canoot get it to work.
Have tried both add_subdirectory and find_package approach.
Going down the find_package route:
No matter what I do it seems the top-level project can't find the installed headers. It seems that INTERFACE_INCLUDE_DIRECTORIES defined by the cpp-stasd-client in the generated /home/fpan/libdir/share/cpp-statsd-client/cmake/cpp-statsd-clientTargets.cmake.
I see this PR has seemingly adressed the issue: #25
Any tips or pointers?
At the moment the cmake setup we have works to build the test program but there are a couple of minor issues with it:
depend
on the library (because there is no library target) and so you can get in a situation where you make changes to the header and the test program isnt able to tell it needs to be rebuiltAt the moment the documentation about batching and frequency rates is very poor. It would be nice to:
Looking at the batching code I noticed m_mustExit
being a "plain" bool
, which means if I understand the C++ memory model correctly that the compiler/cpu are not required to provide visibility of the changes to other threads so the background batching thread may spin indefinitely.
suggestion: switch m_mustExit
to std::atomic_bool
and use memory_order_acq_rel
on load()/store()
[2]
[1] https://github.com/vthiery/cpp-statsd-client/blob/master/include/cpp-statsd-client/UDPSender.hpp#L76
[2] https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.