(statsd cobra bots) statsd improvement: prefix does not need a dot as a suffix, message size can be larger than 256 bytes, error handling was invalid, use core logger for logging instead of std::cerr
This commit is contained in:
		| @@ -1,6 +1,10 @@ | ||||
| # Changelog | ||||
| All changes to this project will be documented in this file. | ||||
|  | ||||
| ## [9.6.6] - 2020-06-04 | ||||
|  | ||||
| (statsd cobra bots) statsd improvement: prefix does not need a dot as a suffix, message size can be larger than 256 bytes, error handling was invalid, use core logger for logging instead of std::cerr | ||||
|  | ||||
| ## [9.6.5] - 2020-05-29 | ||||
|  | ||||
| (http server) support gzip compression | ||||
|   | ||||
| @@ -70,11 +70,17 @@ namespace ix | ||||
|                                                      std::atomic<bool>& fatalCobraError, | ||||
|                                                      std::atomic<uint64_t>& sentCount) -> void { | ||||
|                 std::string id; | ||||
|                 int idx = 0; | ||||
|                 for (auto&& attr : tokens) | ||||
|                 { | ||||
|                     id += "."; | ||||
|                     auto val = extractAttr(attr, msg); | ||||
|                     id += val.asString(); | ||||
|  | ||||
|                     // We add a dot separator unless we are processing the last token | ||||
|                     if (idx++ != tokens.size() - 1) | ||||
|                     { | ||||
|                         id += "."; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (gauge.empty() && timer.empty()) | ||||
|   | ||||
| @@ -39,9 +39,10 @@ | ||||
|  | ||||
| #include "IXStatsdClient.h" | ||||
|  | ||||
| #include <iostream> | ||||
| #include <ixwebsocket/IXNetSystem.h> | ||||
| #include <stdio.h> | ||||
| #include <ixwebsocket/IXSetThreadName.h> | ||||
| #include <ixcore/utils/IXCoreLogger.h> | ||||
| #include <sstream> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  | ||||
| @@ -54,6 +55,8 @@ namespace ix | ||||
|         , _stop(false) | ||||
|     { | ||||
|         _thread = std::thread([this] { | ||||
|             setThreadName("Statsd"); | ||||
|  | ||||
|             while (!_stop) | ||||
|             { | ||||
|                 flushQueue(); | ||||
| @@ -115,11 +118,10 @@ namespace ix | ||||
|     { | ||||
|         cleanup(key); | ||||
|  | ||||
|         char buf[256]; | ||||
|         snprintf( | ||||
|             buf, sizeof(buf), "%s%s:%zd|%s\n", _prefix.c_str(), key.c_str(), value, type.c_str()); | ||||
|         std::stringstream ss; | ||||
|         ss << _prefix << "." << key << ":" << value << "|" << type << "\n"; | ||||
|  | ||||
|         enqueue(buf); | ||||
|         enqueue(ss.str()); | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
| @@ -137,10 +139,13 @@ namespace ix | ||||
|         { | ||||
|             auto message = _queue.front(); | ||||
|             auto ret = _socket.sendto(message); | ||||
|             if (ret != 0) | ||||
|             if (ret == -1) | ||||
|             { | ||||
|                 std::cerr << "error: " << strerror(UdpSocket::getErrno()) << std::endl; | ||||
|                 CoreLogger::error(std::string("statsd error: ") + strerror(UdpSocket::getErrno())); | ||||
|             } | ||||
|  | ||||
|             // we always dequeue regardless of the ability to send the message | ||||
|             // so that we keep our queue size under control | ||||
|             _queue.pop_front(); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -6,4 +6,4 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #define IX_WEBSOCKET_VERSION "9.6.5" | ||||
| #define IX_WEBSOCKET_VERSION "9.6.6" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user