remove spaces in keys + verbose statsd
This commit is contained in:
parent
7095367b93
commit
531bd624b5
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define IX_WEBSOCKET_VERSION "9.6.6"
|
||||
#define IX_WEBSOCKET_VERSION "9.6.7"
|
||||
|
@ -563,7 +563,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
ix::StatsdClient statsdClient(hostname, statsdPort, prefix);
|
||||
ix::StatsdClient statsdClient(hostname, statsdPort, prefix, verbose);
|
||||
|
||||
std::string errMsg;
|
||||
bool initialized = statsdClient.init(errMsg);
|
||||
@ -581,7 +581,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (app.got_subcommand("cobra_metrics_to_statsd"))
|
||||
{
|
||||
ix::StatsdClient statsdClient(hostname, statsdPort, prefix);
|
||||
ix::StatsdClient statsdClient(hostname, statsdPort, prefix, verbose);
|
||||
|
||||
std::string errMsg;
|
||||
bool initialized = statsdClient.init(errMsg);
|
||||
|
Loading…
Reference in New Issue
Block a user