diff --git a/src/statsd_client.cpp b/src/statsd_client.cpp index d04c71c13c3283..748584a3d3c66d 100644 --- a/src/statsd_client.cpp +++ b/src/statsd_client.cpp @@ -61,8 +61,8 @@ bool StatsdClient::ShouldSend(float sample_rate) return sample_rate > std::uniform_real_distribution(0.f, 1.f)(insecure_rand); } -StatsdClient::StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns, - bool enabled) +StatsdClient::StatsdClient(const std::string& host, const std::string& nodename, const uint16_t port, + const std::string& ns, const bool enabled) : m_port{port}, m_host{host}, m_nodename{nodename}, m_ns{ns} { if (!enabled) { @@ -106,37 +106,37 @@ void StatsdClient::cleanup(std::string& key) } } -bool StatsdClient::dec(const std::string& key, float sample_rate) +bool StatsdClient::dec(const std::string& key, const float sample_rate) { return count(key, -1, sample_rate); } -bool StatsdClient::inc(const std::string& key, float sample_rate) +bool StatsdClient::inc(const std::string& key, const float sample_rate) { return count(key, 1, sample_rate); } -bool StatsdClient::count(const std::string& key, int32_t value, float sample_rate) +bool StatsdClient::count(const std::string& key, const int32_t value, const float sample_rate) { return send(key, value, "c", sample_rate); } -bool StatsdClient::gauge(const std::string& key, int32_t value, float sample_rate) +bool StatsdClient::gauge(const std::string& key, const int32_t value, const float sample_rate) { return send(key, value, "g", sample_rate); } -bool StatsdClient::gaugeDouble(const std::string& key, double value, float sample_rate) +bool StatsdClient::gaugeDouble(const std::string& key, const double value, const float sample_rate) { return sendDouble(key, value, "g", sample_rate); } -bool StatsdClient::timing(const std::string& key, int32_t ms, float sample_rate) +bool StatsdClient::timing(const std::string& key, const int32_t ms, const float sample_rate) { return send(key, ms, "ms", sample_rate); } -bool StatsdClient::send(std::string key, int32_t value, const std::string& type, float sample_rate) +bool StatsdClient::send(std::string key, const int32_t value, const std::string& type, const float sample_rate) { if (!m_sock) { return false; @@ -161,7 +161,7 @@ bool StatsdClient::send(std::string key, int32_t value, const std::string& type, return send(buf); } -bool StatsdClient::sendDouble(std::string key, double value, const std::string& type, float sample_rate) +bool StatsdClient::sendDouble(std::string key, const double value, const std::string& type, const float sample_rate) { if (!m_sock) { return false; diff --git a/src/statsd_client.h b/src/statsd_client.h index 4f2008b2d8d898..17119426529402 100644 --- a/src/statsd_client.h +++ b/src/statsd_client.h @@ -13,36 +13,36 @@ #include #include -static const bool DEFAULT_STATSD_ENABLE = false; -static const uint16_t DEFAULT_STATSD_PORT = 8125; -static const std::string DEFAULT_STATSD_HOST = "127.0.0.1"; -static const std::string DEFAULT_STATSD_HOSTNAME = ""; -static const std::string DEFAULT_STATSD_NAMESPACE = ""; +static constexpr bool DEFAULT_STATSD_ENABLE{false}; +static constexpr uint16_t DEFAULT_STATSD_PORT{8125}; +static const std::string DEFAULT_STATSD_HOST{"127.0.0.1"}; +static const std::string DEFAULT_STATSD_HOSTNAME{""}; +static const std::string DEFAULT_STATSD_NAMESPACE{""}; // schedule periodic measurements, in seconds: default - 1 minute, min - 5 sec, max - 1h. -static const int DEFAULT_STATSD_PERIOD = 60; -static const int MIN_STATSD_PERIOD = 5; -static const int MAX_STATSD_PERIOD = 60 * 60; +static constexpr int DEFAULT_STATSD_PERIOD{60}; +static constexpr int MIN_STATSD_PERIOD{5}; +static constexpr int MAX_STATSD_PERIOD{60*60}; namespace statsd { class StatsdClient { public: - explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns, - bool enabled); + explicit StatsdClient(const std::string& host, const std::string& nodename, const uint16_t port, + const std::string& ns, const bool enabled); public: - bool inc(const std::string& key, float sample_rate = 1.f); - bool dec(const std::string& key, float sample_rate = 1.f); - bool count(const std::string& key, int32_t value, float sample_rate = 1.f); - bool gauge(const std::string& key, int32_t value, float sample_rate = 1.f); - bool gaugeDouble(const std::string& key, double value, float sample_rate = 1.f); - bool timing(const std::string& key, int32_t ms, float sample_rate = 1.f); + bool inc(const std::string& key, const float sample_rate = 1.f); + bool dec(const std::string& key, const float sample_rate = 1.f); + bool count(const std::string& key, const int32_t value, const float sample_rate = 1.f); + bool gauge(const std::string& key, const int32_t value, const float sample_rate = 1.f); + bool gaugeDouble(const std::string& key, const double value, const float sample_rate = 1.f); + bool timing(const std::string& key, const int32_t ms, const float sample_rate = 1.f); /* (Low Level Api) manually send a message * type = "c", "g" or "ms" */ - bool send(std::string key, int32_t value, const std::string& type, float sample_rate); - bool sendDouble(std::string key, double value, const std::string& type, float sample_rate); + bool send(std::string key, const int32_t value, const std::string& type, const float sample_rate); + bool sendDouble(std::string key, const double value, const std::string& type, const float sample_rate); private: /**