aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-12-12 11:29:33 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-12-15 09:45:30 +0100
commitad74ce8412eea2c554b048e379b9ca145d9694c6 (patch)
tree2f988b93929741d6c77207596a5747945a769b06
parent7568c9073143edfb3bc6c0bf4263be704cb96cb5 (diff)
downloadcmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.tar.gz
cmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.tar.bz2
cmix-ad74ce8412eea2c554b048e379b9ca145d9694c6.zip
Adds the StatsDaemon to the run script and made it output to file.
-rwxr-xr-xrun.sh19
-rw-r--r--statsd/main.cpp5
-rw-r--r--statsd/stats.cpp30
-rw-r--r--statsd/stats.hpp1
4 files changed, 47 insertions, 8 deletions
diff --git a/run.sh b/run.sh
index 8c5852b..bf73f04 100755
--- a/run.sh
+++ b/run.sh
@@ -11,20 +11,22 @@ else
tool=""
fi
+
tmux new-session -s cmix -d
-tmux send-keys -t cmix:0 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -f -m 5 -n node2.local:9201 -c ../certs/cert1.pem -k ../certs/key1.pem -d ../certs/dh.pem --certdir ../certs/" Enter
-#tmux send-keys -t cmix:0 "r" Enter
+
+tmux send-keys -t cmix:0 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool statsd/statsd" Enter
tmux new-window -t cmix:1
-tmux send-keys -t cmix:1 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -p 9201 -n node3.local:9202 -c ../certs/cert2.pem -k ../certs/key2.pem -d ../certs/dh.pem --certdir ../certs/" Enter
-#tmux send-keys -t cmix:1 "r" Enter
+tmux send-keys -t cmix:1 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -f -m 5 -n node2.local:9201 -s localhost:9199 -a node1 -c ../certs/cert1.pem -k ../certs/key1.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+#tmux send-keys -t cmix:0 "r" Enter
tmux new-window -t cmix:2
-tmux send-keys -t cmix:2 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -l -p 9202 -n node1.local:9200 -c ../certs/cert3.pem -k ../certs/key3.pem -d ../certs/dh.pem --certdir ../certs/" Enter
-#tmux send-keys -t cmix:2 "r" Enter
+tmux send-keys -t cmix:2 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -p 9201 -n node3.local:9202 -s localhost:9199 -a node2 -c ../certs/cert2.pem -k ../certs/key2.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+#tmux send-keys -t cmix:1 "r" Enter
tmux new-window -t cmix:3
-tmux send-keys -t cmix:3 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:3 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -l -p 9202 -n node1.local:9200 -s localhost:9199 -a node3 -c ../certs/cert3.pem -k ../certs/key3.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+#tmux send-keys -t cmix:2 "r" Enter
tmux new-window -t cmix:4
tmux send-keys -t cmix:4 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
@@ -38,6 +40,9 @@ tmux send-keys -t cmix:6 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool
tmux new-window -t cmix:7
tmux send-keys -t cmix:7 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux new-window -t cmix:8
+tmux send-keys -t cmix:8 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+
tmux attach
tmux kill-session -t cmix
diff --git a/statsd/main.cpp b/statsd/main.cpp
index 436e8ad..d20abc3 100644
--- a/statsd/main.cpp
+++ b/statsd/main.cpp
@@ -15,11 +15,12 @@ int main(int argc, char* argv[]) {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message.")
- ("port,p", po::value<uint16_t>()->default_value(9200), "Set listening port.")
+ ("port,p", po::value<uint16_t>()->default_value(9199), "Set listening port.")
("enable_v4", po::value<bool>()->default_value(true), "Enable/disable ipv4 accept support.")
("interface4,4", po::value<std::string>()->default_value("0.0.0.0"), "Set the ipv4 address to listen on.")
("enable_v6", po::value<bool>()->default_value(true), "Enable/disable ipv6 accept support.")
("interface6,6", po::value<std::string>()->default_value("::"), "Set the ipv6 address to listen on.")
+ ("output,o", po::value<std::string>()->default_value("output.csv"), "Output file name")
;
po::variables_map vm;
@@ -42,4 +43,6 @@ int main(int argc, char* argv[]) {
stats.run();
+ stats.output(vm["output"].as<std::string>());
+
}
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;
+ }
+
+ }
+}
diff --git a/statsd/stats.hpp b/statsd/stats.hpp
index 673022e..b6e4bca 100644
--- a/statsd/stats.hpp
+++ b/statsd/stats.hpp
@@ -30,4 +30,5 @@ public:
Stats(ListenSettings lsettings);
void run();
+ void output(std::string file);
}; \ No newline at end of file