aboutsummaryrefslogtreecommitdiff
path: root/statsd/stats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'statsd/stats.cpp')
-rw-r--r--statsd/stats.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/statsd/stats.cpp b/statsd/stats.cpp
new file mode 100644
index 0000000..9eeb140
--- /dev/null
+++ b/statsd/stats.cpp
@@ -0,0 +1,49 @@
+#include "stats.hpp"
+
+void Stats::accept_connection(std::unique_ptr<boost::asio::ip::tcp::socket>&& socket) {
+ auto it = connections.emplace(connections.end(), std::move(socket));
+ it->on_done([this, it](){
+ connections.erase(it);
+ });
+ it->async_receive([it, this](cmix_proto::CMixMessage const& message) {
+ handle_message(it, message);
+ });
+}
+
+void Stats::handle_performance(std::list<Receiver>::iterator it, const cmix_proto::Performance& perf) {
+ data[perf.node()][perf.column() + "wall_time"].push_back(std::stol(perf.wall_time()));
+ data[perf.node()][perf.column() + "system_time"].push_back(std::stol(perf.system_time()));
+ data[perf.node()][perf.column() + "user_time"].push_back(std::stol(perf.user_time()));
+
+ it->async_receive([it, this](cmix_proto::CMixMessage const& message) {
+ handle_message(it, message);
+ });
+}
+
+void Stats::handle_message(std::list<Receiver>::iterator it, cmix_proto::CMixMessage message) {
+ switch(message.contents_case()) {
+ case cmix_proto::CMixMessage::ContentsCase::kPerformance: {
+ BOOST_LOG_TRIVIAL(trace) << "Handling performance";
+ handle_performance(it, message.performance());
+ break;
+ }
+ case cmix_proto::CMixMessage::ContentsCase::kBye: {
+ BOOST_LOG_TRIVIAL(trace) << "Handling Bye";
+
+ break;
+ }
+ default: {
+ BOOST_LOG_TRIVIAL(error) << "handle_message: CMixMessage contains unknown contents.";
+ connections.erase(it);
+ }
+ }
+}
+
+Stats::Stats(ListenSettings lsettings)
+: io_service()
+, server(io_service, lsettings, [this](std::unique_ptr<boost::asio::ip::tcp::socket>&& socket){accept_connection(std::move(socket));})
+{}
+
+void Stats::run() {
+ io_service.run();
+}