Commit abf6af19 authored by Alessio Netti's avatar Alessio Netti

Minor refinements

- Boolean configuration options now all accept "true" and "on" keywords
- Cache interval and thread count parameters removed from the command-line
interface for consistency; these can still be set in the config files
like all other parameters
- global.conf file renamed to dcdbpusher.conf for consistency
parent 38bfdf30
......@@ -24,7 +24,7 @@ bool AnalyticsManager::load(const string& path, const string& globalFile, const
try {
boost::property_tree::read_info(_configPath + globalFile, cfg);
} catch (boost::property_tree::info_parser_error& e) {
LOG(error) << "Error when reading analyzer plugins from global.conf: " << e.what();
LOG(error) << "Error when reading analyzer plugins from " << globalFile << ": " << e.what();
return false;
}
......@@ -58,7 +58,7 @@ bool AnalyticsManager::load(const string& path, const string& globalFile, const
}
} else if (boost::iequals(val.first, "config")) {
pluginConfig = val.second.data();
// If config-path not specified we will look for pluginName.conf in the global.conf directory
// If config-path not specified we will look for pluginName.conf in the global conf directory
if (pluginConfig == "")
pluginConfig = _configPath + plugin.second.data() + ".conf";
} else {
......
......@@ -318,13 +318,13 @@ protected:
} else if (boost::iequals(val.first, "mqttPart")) {
an.setMqttPart(val.second.data());
} else if (boost::iequals(val.first, "sync")) {
an.setSync(val.second.data() == "true");
an.setSync(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "delay")) {
an.setDelayInterval(stoull(val.second.data()) / 1000);
} else if (boost::iequals(val.first, "duplicate")) {
an.setDuplicate(val.second.data() == "true");
an.setDuplicate(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "streaming")) {
an.setStreaming(val.second.data() == "true");
an.setStreaming(to_bool(val.second.data()));
} else if (boost::iequals(val.first, INPUT_BLOCK) || boost::iequals(val.first, OUTPUT_BLOCK)) {
// Instantiating all sensors contained within the "input" or "output" block
BOOST_FOREACH(boost::property_tree::iptree::value_type &valInner, val.second)
......@@ -416,9 +416,9 @@ protected:
if (boost::iequals(val.first, "mqttsuffix")) {
sBase.setMqtt(val.second.data());
} else if (boost::iequals(val.first, "skipConstVal")) {
sBase.setSkipConstVal( val.second.data() == "true" );
sBase.setSkipConstVal(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "delta")) {
sBase.setDelta( val.second.data() == "true" );
sBase.setDelta(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "sink")) {
sBase.setSinkPath( val.second.data() );
} else if (boost::iequals(val.first, "subSampling")) {
......
......@@ -244,7 +244,7 @@ void usage() {
012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
cout << "Usage:" << endl;
cout << " collectagent [-m<host>] [-r<host>] [-c<host>] [-C<interval>] [-u<username>] [-p<password>] [-t<ttl>] [-v<verbosity>] [-d] [-s] <path/to/configfiles/>" << endl;
cout << " collectagent [-d] [-s] [-m<host>] [-r<host>] [-c<host>] [-u<username>] [-p<password>] [-t<ttl>] [-v<verbosity>] <path/to/configfiles/>" << endl;
cout << " collectagent -h" << endl;
cout << endl;
......@@ -252,7 +252,6 @@ void usage() {
cout << " -m<host> MQTT listen address [default: " << defaults.mqttListenAddress << "]" << endl;
cout << " -r<host> REST API listen address [default: " << defaults.restListenAddress << "]" << endl;
cout << " -c<host> Cassandra host [default: " << defaults.cassandraSettings.address << "]" << endl;
cout << " -C<interval> Cache interval in [s] [default: " << defaults.cacheInterval << "]" << endl;
cout << " -u<username> Cassandra username [default: none]" << endl;
cout << " -p<password> Cassandra password [default: none]" << endl;
cout << " -t<ttl> Cassandra insert TTL [default: " << defaults.cassandraSettings.ttl << "]" << endl;
......@@ -322,9 +321,6 @@ int main(int argc, char* const argv[]) {
case 'c':
settings.cassandraSettings.address = optarg;
break;
case 'C':
settings.cacheInterval = stoul(optarg);
break;
case 'u':
settings.cassandraSettings.username = optarg;
break;
......
......@@ -73,9 +73,9 @@ bool Configuration::readGlobal() {
_global.tempDir.append("/");
}
} else if (boost::iequals(global.first, "daemonize")) {
_global.daemonize = global.second.data() == "true";
_global.daemonize = to_bool(global.second.data());
} else if (boost::iequals(global.first, "statistics")) {
_global.statistics = global.second.data() == "true";
_global.statistics = to_bool(global.second.data());
} else {
LOG(warning) << " Value \"" << global.first << "\" not recognized. Omitting";
}
......@@ -102,7 +102,7 @@ bool Configuration::readGlobal() {
} else if (boost::iequals(global.first, "maxConcRequests")) {
_global.cassandraSettings.maxConcRequests = stoul(global.second.data());
} else if (boost::iequals(global.first, "debugLog")) {
_global.cassandraSettings.debugLog = global.second.data() == "true";
_global.cassandraSettings.debugLog = to_bool(global.second.data());
} else {
LOG(warning) << " Value \"" << global.first << "\" not recognized. Omitting";
}
......
......@@ -14,6 +14,7 @@
#include <boost/algorithm/string.hpp>
#include "logging.h"
#include "pluginsettings.h"
#define LISTENHOST "localhost"
#define LISTENPORT "1883"
......
......@@ -12,4 +12,6 @@ typedef struct {
unsigned int cacheInterval;
} pluginSettings_t;
static bool to_bool(const std::string& s) { return s=="true" || s=="on"; }
#endif //PROJECT_PLUGINSETTINGS_H
......@@ -26,7 +26,7 @@ Configuration::Configuration(const std::string& cfgFilePath) :
//set default values for global variables
_global.validateConfig = false;
_global.qosLevel = 1;
_global.daemonize = 0;
_global.daemonize = false;
_global.hierarchy = "";
_global.brokerHost = "";
_global.brokerPort = 1883;
......@@ -61,14 +61,14 @@ Configuration::~Configuration() {
bool Configuration::readGlobal() {
//open file
std::string globalConfig = _cfgFilePath;
globalConfig.append("global.conf");
globalConfig.append("dcdbpusher.conf");
boost::property_tree::iptree cfg;
//parse to property_tree
try {
boost::property_tree::read_info(globalConfig, cfg);
} catch (boost::property_tree::info_parser_error& e) {
LOG(error) << "Error when reading global.conf: " << e.what();
LOG(error) << "Error when reading dcdbpusher.conf: " << e.what();
return false;
}
......@@ -108,13 +108,9 @@ bool Configuration::readGlobal() {
} else if (boost::iequals(global.first, "maxMsgNum")) {
_global.maxMsgNum = stoi(global.second.data());
} else if (boost::iequals(global.first, "daemonize")) {
if (global.second.data() == "true") {
_global.daemonize = 1;
}
_global.daemonize = to_bool(global.second.data());
} else if (boost::iequals(global.first, "validateConfig")) {
if (global.second.data() == "true") {
_global.validateConfig = true;
}
_global.validateConfig = to_bool(global.second.data());
} else if (boost::iequals(global.first, "verbosity")) {
_global.logLevelFile = translateLogLevel(stoi(global.second.data()));
} else if (boost::iequals(global.first, "cacheInterval")) {
......@@ -153,14 +149,14 @@ bool Configuration::readGlobal() {
bool Configuration::readAuthkeys(HttpsServer* server) {
//open file
std::string globalConfig = _cfgFilePath;
globalConfig.append("global.conf");
globalConfig.append("dcdbpusher.conf");
boost::property_tree::iptree cfg;
//parse to property_tree
try {
boost::property_tree::read_info(globalConfig, cfg);
} catch (boost::property_tree::info_parser_error& e) {
LOG(error) << "Error when reading authkeys from global.conf: " << e.what();
LOG(error) << "Error when reading authkeys from dcdbpusher.conf: " << e.what();
return false;
}
......@@ -202,13 +198,13 @@ bool Configuration::readAuthkeys(HttpsServer* server) {
bool Configuration::readPlugins() {
std::string globalConfig = _cfgFilePath;
globalConfig.append("global.conf");
globalConfig.append("dcdbpusher.conf");
boost::property_tree::iptree cfg;
try {
boost::property_tree::read_info(globalConfig, cfg);
} catch (boost::property_tree::info_parser_error& e) {
LOG(error) << "Error when reading plugins from global.conf: " << e.what();
LOG(error) << "Error when reading plugins from dcdbpusher.conf: " << e.what();
return false;
}
......@@ -238,7 +234,7 @@ bool Configuration::readPlugins() {
}
} else if (boost::iequals(val.first, "config")) {
pluginConfig = val.second.data();
//if config-path not specified we will look for pluginName.conf in the global.conf directory
//if config-path not specified we will look for pluginName.conf in the dcdbpusher.conf directory
if (pluginConfig == "") {
pluginConfig = _cfgFilePath + plugin.second.data() + ".conf";
}
......
......@@ -18,7 +18,7 @@
typedef struct {
bool validateConfig;
int daemonize;
bool daemonize;
int brokerPort;
int qosLevel;
unsigned int maxInflightMsgNum;
......
......@@ -19,19 +19,19 @@ mqttStart 00
metric MemFree {
type MemFree
mqttsuffix 36
skipConstVal on
skipConstVal true
}
metric AnonPages {
type AnonPages
mqttsuffix AA
skipConstVal on
skipConstVal true
}
metric Hugepagesize {
type Hugepagesize
mqttsuffix BB
skipConstVal on
skipConstVal true
}
}
......@@ -46,19 +46,19 @@ mqttStart 00
metric nr_dirty_threshold {
type nr_dirty_threshold
mqttsuffix F0
skipConstVal on
skipConstVal true
}
metric nr_file_pages {
type nr_file_pages
mqttsuffix F1
skipConstVal on
skipConstVal true
}
metric nr_alloc_batch {
type nr_alloc_batch
mqttsuffix F2
skipConstVal on
skipConstVal true
}
}
......@@ -74,29 +74,29 @@ cpus 250,36
metric col_idle {
type col_idle
mqttsuffix 36
skipConstVal on
perCpu on
skipConstVal true
perCpu true
}
metric col_user {
type col_user
mqttsuffix 37
skipConstVal on
perCpu on
skipConstVal true
perCpu true
}
metric col_nice {
type col_nice
mqttsuffix 38
skipConstVal on
perCpu off
skipConstVal true
perCpu false
}
metric ctxt {
type ctxt
mqttsuffix 40
skipConstVal on
perCpu off
skipConstVal true
perCpu false
}
}
......@@ -29,7 +29,7 @@ group temp {
path /sys/devices/virtual/thermal/thermal_zone1/temp
sensor temp1 {
skipConstVal on
skipConstVal true
mqttsuffix 01
}
}
......
......@@ -121,7 +121,7 @@ void printSyntax()
_configuration = new Configuration("");
global_t& globalSettings = _configuration->getGlobal();
cout << "Usage:" << endl;
cout << " dcdbpusher [-d] [-x] [-a<string>] [-b<host>] [-p<port>] [-m<string>] [-t<number>] <path/to/configfiles/>" << endl;
cout << " dcdbpusher [-d] [-x] [-a<string>] [-b<host>] [-p<port>] [-m<string>] [-w<path>] [-v<level>] <path/to/configfiles/>" << endl;
cout << " dcdbpusher -h" << endl;
cout << endl;
......@@ -130,9 +130,7 @@ void printSyntax()
cout << " -b <host> MQTT broker [default: none]" << endl;
cout << " -p <port> MQTT broker port [default: " << globalSettings.brokerPort << "]" << endl;
cout << " -m <string> MQTT topic prefix [default: none]" << endl;
cout << " -t <number> Thread count [default: " << globalSettings.threads << "]" << endl;
cout << " -w <path> Writable temp dir [default: .]" << endl;
cout << " -c <sec> Cache interval in [s] [default: " << globalSettings.pluginSettings.cacheInterval / 1000 << "]" << endl;
cout << " -v <level> Set verbosity of output [default: " << globalSettings.logLevelCmd << "]" << endl
<< " Can be a number between 5 (all) and 0 (fatal)." << endl;
cout << endl;
......@@ -157,7 +155,7 @@ int main(int argc, char** argv) {
}
//define allowed command-line options once
const char opts[] = "a:b:p:m:t:v:w:c:dxh";
const char opts[] = "a:b:p:m:v:w:dxh";
//check if help flag specified
char c;
......@@ -199,7 +197,7 @@ int main(int argc, char** argv) {
//reset getopt()
optind = 1;
//read in options (overwrite global.conf settings if necessary)
//read in options (overwrite dcdbpusher.conf settings if necessary)
while ((c = getopt(argc, argv, opts)) != -1) {
switch (c)
{
......@@ -215,9 +213,6 @@ int main(int argc, char** argv) {
case 'm':
pluginSettings.mqttPrefix = optarg;
break;
case 't':
globalSettings.threads = stoul(optarg);
break;
case 'v':
globalSettings.logLevelCmd = _configuration->translateLogLevel(stoi(optarg));
break;
......@@ -233,9 +228,6 @@ int main(int argc, char** argv) {
pluginSettings.tempdir.append("/");
}
break;
case 'c':
pluginSettings.cacheInterval = stoul(optarg) * 1000;
break;
case 'h':
printSyntax();
return 1;
......@@ -274,11 +266,7 @@ int main(int argc, char** argv) {
LOG(info) << "Global Settings:";
LOG(info) << " Broker: " << globalSettings.brokerHost << ":" << globalSettings.brokerPort;
LOG(info) << " Threads: " << globalSettings.threads;
if(globalSettings.daemonize) {
LOG(info) << " Daemonize: Enabled";
} else {
LOG(info) << " Daemonize: Disabled";
}
LOG(info) << " Daemonize: " << (globalSettings.daemonize ? "Enabled" : "Disabled");
LOG(info) << " MaxMsgNum: " << globalSettings.maxMsgNum;
LOG(info) << " MaxInflightMsgNum: " << globalSettings.maxInflightMsgNum;
LOG(info) << " MaxQueuedMsgNum: " << globalSettings.maxQueuedMsgNum;
......@@ -363,7 +351,7 @@ int main(int argc, char** argv) {
_queryEngine.triggerUpdate();
_queryEngine.setQueryCallback(sensorQueryCallback);
if(!_analyticsManager->load(argv[argc-1], "global.conf", pluginSettings)) {
if(!_analyticsManager->load(argv[argc-1], "dcdbpusher.conf", pluginSettings)) {
LOG(fatal) << "Failed to load data analytics manager!";
return 1;
}
......
......@@ -405,17 +405,13 @@ protected:
if (boost::iequals(val.first, "mqttsuffix")) {
sBase.setMqtt(val.second.data());
} else if (boost::iequals(val.first, "skipConstVal")) {
if (val.second.data() == "on") {
sBase.setSkipConstVal(true);
} else {
sBase.setSkipConstVal(false);
}
sBase.setSkipConstVal(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "delta")) {
sBase.setDelta( val.second.data() == "on" );
sBase.setDelta(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "sink")) {
sBase.setSinkPath( val.second.data() );
} else if (boost::iequals(val.first, "subSampling")) {
sBase.setSubsampling( std::stoul(val.second.data()) );
sBase.setSubsampling(std::stoul(val.second.data()));
}
}
sensorBase(sBase, config);
......
......@@ -75,9 +75,6 @@ bool ProcfsConfigurator::readConfig(std::string cfgPath) {
}
}
constructSensorNames();
for(const auto& g : _sensorGroups)
for(const auto& s : g->getSensors())
LOG(debug) << g->getGroupName() << "::" << s->getName() << " using MQTT-topic \"" << s->getMqtt() << "\"";
return true;
}
......@@ -93,7 +90,7 @@ void ProcfsConfigurator::sensorBase(ProcfsSensorBase& s, CFG_VAL config) {
if (boost::iequals(val.first, "type"))
s.setMetric(val.second.data());
else if (boost::iequals(val.first, "perCPU"))
s.setPerCPU( val.second.data() == "on" );
s.setPerCPU(to_bool(val.second.data()));
}
}
......
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