remove spaces in keys + verbose statsd

This commit is contained in:
Benjamin Sergeant
2020-06-04 14:57:36 -07:00
parent 7095367b93
commit 531bd624b5
5 changed files with 32 additions and 8 deletions

View File

@ -14,6 +14,19 @@
#include <sstream>
#include <vector>
namespace
{
std::string removeSpaces(const std::string& str)
{
std::string out(str);
out.erase(
std::remove_if(out.begin(), out.end(), [](unsigned char x) { return std::isspace(x); }),
out.end());
return out;
}
}
namespace ix
{
bool processPerfMetricsEvent(const Json::Value& msg,
@ -35,7 +48,7 @@ namespace ix
ss << msg["id"].asString() << "."
<< msg["device"]["game"].asString() << "."
<< msg["device"]["os_name"].asString() << "."
<< msg["data"]["Tag"].asString();
<< removeSpaces(msg["data"]["Tag"].asString());
std::string id = ss.str();

View File

@ -48,11 +48,15 @@
namespace ix
{
StatsdClient::StatsdClient(const std::string& host, int port, const std::string& prefix)
StatsdClient::StatsdClient(const std::string& host,
int port,
const std::string& prefix,
bool verbose)
: _host(host)
, _port(port)
, _prefix(prefix)
, _stop(false)
, _verbose(verbose)
{
_thread = std::thread([this] {
setThreadName("Statsd");
@ -119,9 +123,14 @@ namespace ix
cleanup(key);
std::stringstream ss;
ss << _prefix << "." << key << ":" << value << "|" << type << "\n";
ss << _prefix << "." << key << ":" << value << "|" << type;
enqueue(ss.str());
if (_verbose)
{
CoreLogger::info(ss.str());
}
enqueue(ss.str() + "\n");
return 0;
}

View File

@ -20,7 +20,8 @@ namespace ix
public:
StatsdClient(const std::string& host = "127.0.0.1",
int port = 8125,
const std::string& prefix = "");
const std::string& prefix = "",
bool verbose = false);
~StatsdClient();
bool init(std::string& errMsg);
@ -52,6 +53,7 @@ namespace ix
std::mutex _mutex; // for the queue
std::deque<std::string> _queue;
bool _verbose;
};
} // end namespace ix