Skip to content
Closed
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
17 changes: 17 additions & 0 deletions include/cpp-statsd-client/StatsdClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ class StatsdClient {
float frequency = 1.0f,
const std::vector<std::string>& tags = {}) const noexcept;

//! Records a custom metric type for the key, with a given value, at a given frequency
template <typename T>
void custom(const std::string& key,
const T value,
const char* type,
float frequency = 1.0f,
const std::vector<std::string>& tags = {}) const noexcept;

//! Seed the RNG that controls sampling
void seed(unsigned int seed = std::random_device()()) noexcept;

Expand Down Expand Up @@ -248,6 +256,15 @@ inline void StatsdClient::set(const std::string& key,
send(key, sum, detail::METRIC_TYPE_SET, frequency, tags);
}

template <typename T>
inline void StatsdClient::custom(const std::string& key,
const T value,
const char* type,
const float frequency,
const std::vector<std::string>& tags) const noexcept {
send(key, value, type, frequency, tags);
}

template <typename T>
inline void StatsdClient::send(const std::string& key,
const T value,
Expand Down
5 changes: 5 additions & 0 deletions tests/testStatsdClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ void testSendRecv(uint64_t batchSize, uint64_t sendInterval) {
client.count("foo", -42, .9f, {"bar", "baz"});
throwOnError(client);
expected.emplace_back("sendRecv.foo:-42|c|@0.90|#bar,baz");

// Custom metric type should pass through all params
client.custom("custom_metric_type", 5678, "cust", .95f, {"tag1", "tag2"});
throwOnError(client);
expected.emplace_back("sendRecv.custom_metric_type:5678|cust|@0.95|#tag1,tag2");
}

// Signal the mock server we are done
Expand Down