Commit b80114c6 authored by Axel Auweter's avatar Axel Auweter
Browse files

Fix for ticket #40: Quiet Mode for CollectAgent

parent b85f1a1c
......@@ -27,6 +27,7 @@
using namespace std;
int keepRunning;
bool statistics;
uint64_t msgCtr;
uint64_t pmsgCtr;
SensorDataStore *mySensorDataStore;
......@@ -124,14 +125,15 @@ void mqttCallback(SimpleMQTTMessage *msg)
* Print usage information
*/
void usage() {
printf("Usage: collectagent [-D] [-l <host>] [-h <host>] [-t <ttl>]\n");
printf("Usage: collectagent [-D] [-s] [-l <host>] [-h <host>] [-t <ttl>]\n");
printf("Collectagent will accept remote connections by listening to the\n");
printf("specified listen address (-l <host>) at port 1883 (default MQTT port).\n");
printf("It will also connect to cassandra to the specifiec addres (-h <host>).\n");
printf("The default <host> is localhost/127.0.0.1.\n");
printf("If the -t option is specified, data will be inserted with the specified\n");
printf("TTL in seconds.\n");
printf("If the -D option is specified, CollectAgent will run as daemon.\n\n");
printf("If the -D option is specified, CollectAgent will run as daemon.\n");
printf("With the -s option, CollectAgent will print message statistics.\n\n");
}
int main(int argc, char* const argv[]) {
......@@ -154,7 +156,8 @@ int main(int argc, char* const argv[]) {
listenHost="localhost";
cassandraHost="127.0.0.1";
ttl="0";
while ((ret=getopt(argc, argv, "h:l:t:D?"))!=-1) {
statistics = false;
while ((ret=getopt(argc, argv, "h:l:t:Ds?"))!=-1) {
switch(ret) {
case 'h':
cassandraHost = optarg;
......@@ -168,6 +171,9 @@ int main(int argc, char* const argv[]) {
case 'D':
dcdbdaemon();
break;
case 's':
statistics = true;
break;
case '?':
default:
usage();
......@@ -235,7 +241,9 @@ int main(int argc, char* const argv[]) {
elapsed = (end.tv_sec - start.tv_sec) * 1000.0;
elapsed += (end.tv_usec - start.tv_usec) / 1000.0;
float publish = msgCtr?(pmsgCtr*100.0)/msgCtr:0;
cout << "Message rate: " << (msgCtr/elapsed)*1000.0 << " messages/second (" << publish << "% PUBLISH)\n";
if (statistics) {
cout << "Message rate: " << (msgCtr/elapsed)*1000.0 << " messages/second (" << publish << "% PUBLISH)\n";
}
msgCtr = 0;
pmsgCtr = 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment