summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ingestor.cpp15
-rw-r--r--src/ingestor.hpp13
-rw-r--r--src/settings.hpp9
-rw-r--r--src/webstat_logger_main.cpp16
4 files changed, 38 insertions, 15 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp
index db5f317..db11799 100644
--- a/src/ingestor.cpp
+++ b/src/ingestor.cpp
@@ -58,8 +58,17 @@ namespace WebStat {
}
}
- Ingestor::Ingestor(const utsname & host, DB::ConnectionPoolPtr dbpl) :
- dbpool {std::move(dbpl)}, hostnameId {crc32(host.nodename)}, curl {curl_multi_init()}
+ Ingestor::Ingestor(const utsname & host, IngestorSettings settings) :
+ Ingestor {host,
+ std::make_shared<DB::ConnectionPool>(
+ settings.dbMax, settings.dbKeep, settings.dbType, settings.dbConnStr),
+ std::move(settings)}
+ {
+ }
+
+ Ingestor::Ingestor(const utsname & host, DB::ConnectionPoolPtr dbpl, IngestorSettings settings) :
+ settings {std::move(settings)}, dbpool {std::move(dbpl)}, hostnameId {crc32(host.nodename)},
+ curl {curl_multi_init()}
{
auto dbconn = dbpool->get();
auto ins = dbconn->modify(SQL::HOST_UPSERT, SQL::HOST_UPSERT_OPTS);
@@ -202,7 +211,7 @@ namespace WebStat {
if (insert->execute() > 0) {
switch (type) {
case EntityType::UserAgent: {
- auto curlOp = curlGetUserAgentDetail(entityId, value, userAgentAPI.c_str());
+ auto curlOp = curlGetUserAgentDetail(entityId, value, settings.userAgentAPI.c_str());
auto added = curlOperations.emplace(curlOp->hnd.get(), std::move(curlOp));
curl_multi_add_handle(curl.get(), added.first->first);
break;
diff --git a/src/ingestor.hpp b/src/ingestor.hpp
index 879526d..719b65b 100644
--- a/src/ingestor.hpp
+++ b/src/ingestor.hpp
@@ -2,6 +2,7 @@
#include "curlOp.hpp"
#include "logTypes.hpp"
+#include "settings.hpp"
#include <c++11Helpers.h>
#include <connectionPool.h>
#include <connection_fwd.h>
@@ -12,9 +13,17 @@
#include <sys/utsname.h>
namespace WebStat {
+ struct IngestorSettings : Settings {
+ std::string dbConnStr = "dbname=webstat user=webstat";
+ std::string userAgentAPI = "https://useragentstring.com";
+ unsigned int dbMax = 4;
+ unsigned int dbKeep = 2;
+ };
+
class Ingestor {
public:
- Ingestor(const utsname &, DB::ConnectionPoolPtr);
+ Ingestor(const utsname &, IngestorSettings);
+ Ingestor(const utsname &, DB::ConnectionPoolPtr, IngestorSettings);
virtual ~Ingestor() = default;
SPECIAL_MEMBERS_DELETE(Ingestor);
@@ -32,7 +41,7 @@ namespace WebStat {
template<typename... T> void storeLogLine(DB::Connection *, const std::tuple<T...> &) const;
- std::string userAgentAPI = "https://useragentstring.com";
+ IngestorSettings settings;
protected:
DB::ConnectionPoolPtr dbpool;
diff --git a/src/settings.hpp b/src/settings.hpp
new file mode 100644
index 0000000..8ac5c0d
--- /dev/null
+++ b/src/settings.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <string>
+
+namespace WebStat {
+ struct Settings {
+ std::string dbType = "postgresql";
+ };
+}
diff --git a/src/webstat_logger_main.cpp b/src/webstat_logger_main.cpp
index d30da80..eb8a30d 100644
--- a/src/webstat_logger_main.cpp
+++ b/src/webstat_logger_main.cpp
@@ -24,22 +24,19 @@ main(int argc, char ** argv)
namespace po = boost::program_options;
po::options_description opts("WebStat logger");
- std::string dbType;
- std::string dbConnStr;
- unsigned int dbMax = 4;
- unsigned int dbKeep = 2;
+ WebStat::IngestorSettings settings;
// clang-format off
opts.add_options()
("help,h", "Show this help message")
("config,c", po::value<std::string>(), "Read config from this config file")
- ("db.type", po::value(&dbType)->default_value("postgresql"),
+ ("db.type", po::value(&settings.dbType)->default_value(settings.dbType),
"Database connection type")
- ("db.wr.connstr,D", po::value(&dbConnStr)->default_value("dbname=webstat user=webstat"),
+ ("db.wr.connstr,D", po::value(&settings.dbConnStr)->default_value(settings.dbConnStr),
"Database connection string (read/write)")
- ("db.wr.max", po::value(&dbMax)->default_value(4),
+ ("db.wr.max", po::value(&settings.dbMax)->default_value(settings.dbMax),
"Maximum number of concurrent write/read write DB connections")
- ("db.wr.keep", po::value(&dbKeep)->default_value(2),
+ ("db.wr.keep", po::value(&settings.dbKeep)->default_value(settings.dbKeep),
"Number of write/read write DB connections to keep open")
;
// clang-format on
@@ -56,9 +53,8 @@ main(int argc, char ** argv)
}
po::notify(optVars);
- auto pool = std::make_shared<DB::ConnectionPool>(dbMax, dbKeep, std::move(dbType), std::move(dbConnStr));
try {
- WebStat::Ingestor {getHostDetail(), pool}.ingestLog(stdin);
+ WebStat::Ingestor {getHostDetail(), std::move(settings)}.ingestLog(stdin);
return EXIT_SUCCESS;
}
catch (const std::exception & excp) {