diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-12-12 11:29:33 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-12-15 09:45:30 +0100 |
| commit | ad74ce8412eea2c554b048e379b9ca145d9694c6 (patch) | |
| tree | 2f988b93929741d6c77207596a5747945a769b06 /statsd/stats.cpp | |
| parent | 7568c9073143edfb3bc6c0bf4263be704cb96cb5 (diff) | |
| download | cmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.tar.gz cmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.tar.bz2 cmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.zip | |
Adds the StatsDaemon to the run script and made it output to file.
Diffstat (limited to 'statsd/stats.cpp')
| -rw-r--r-- | statsd/stats.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/statsd/stats.cpp b/statsd/stats.cpp index 9eeb140..cd66193 100644 --- a/statsd/stats.cpp +++ b/statsd/stats.cpp @@ -1,9 +1,14 @@ #include "stats.hpp" +#include <fstream> + 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); + if(connections.empty()) { + server.close(); + } }); it->async_receive([it, this](cmix_proto::CMixMessage const& message) { handle_message(it, message); @@ -47,3 +52,28 @@ Stats::Stats(ListenSettings lsettings) void Stats::run() { io_service.run(); } + +//Very inefficient... but easy. +void Stats::output(std::string file) +{ + for(auto table : data) { + std::ofstream ofs(file + "_" + table.first); + for(auto it = table.second.begin(); it != table.second.end(); ++it) { + if(it != table.second.begin()) { + ofs << ", "; + } + ofs << it->first; + } + ofs << std::endl; + for(int i = 0; i < table.second.begin()->second.size(); ++i) { + for(auto it = table.second.begin(); it != table.second.end(); ++it) { + if(it != table.second.begin()) { + ofs << ", "; + } + ofs << it->second[i]; + } + ofs << std::endl; + } + + } +} |
