Add metrics section to config

pull/493/head
Michael 5 years ago
parent 6f23cbe176
commit 5df8e16c44
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -43,8 +43,10 @@ namespace llarp
std::unique_ptr< metrics::DefaultManagerGuard > m_metricsManager;
std::unique_ptr< metrics::PublisherScheduler > m_metricsPublisher;
int num_nethreads = 1;
bool singleThreaded = false;
int num_nethreads = 1;
bool singleThreaded = false;
bool disableMetrics = false;
bool disableMetricLogs = false;
std::unique_ptr< Crypto > crypto;
std::unique_ptr< AbstractRouter > router;
std::unique_ptr< llarp_threadpool > worker;
@ -106,6 +108,9 @@ namespace llarp
void
progress();
void
setupMetrics();
std::string configfile;
std::string pidfile;
};

@ -22,7 +22,8 @@ namespace llarp
[&ret](const ConfigParser::Section_t &s) -> bool {
for(const auto &item : s)
{
ret.emplace_back(string_view_string(item.first), string_view_string(item.second));
ret.emplace_back(string_view_string(item.first),
string_view_string(item.second));
}
return true;
}))
@ -47,6 +48,7 @@ namespace llarp
iwp_links = find_section(parser, "bind", section_t{});
services = find_section(parser, "services", section_t{});
system = find_section(parser, "system", section_t{});
metrics = find_section(parser, "metrics", section_t{});
api = find_section(parser, "api", section_t{});
lokid = find_section(parser, "lokid", section_t{});
bootstrap = find_section(parser, "bootstrap", section_t{});
@ -57,9 +59,13 @@ namespace llarp
Config::visit(const Visitor &functor)
{
std::unordered_map< std::string, const llarp::Config::section_t & >
sections = {{"network", network}, {"connect", connect},
{"bootstrap", bootstrap}, {"system", system},
{"netdb", netdb}, {"api", api},
sections = {{"network", network},
{"connect", connect},
{"bootstrap", bootstrap},
{"system", system},
{"metrics", metrics},
{"netdb", netdb},
{"api", api},
{"services", services}};
auto visitor = [&](const char *name, const auto &item) {
@ -172,6 +178,12 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
f << "# nickname=lokinet" << std::endl;
f << std::endl << std::endl;
// metrics
f << "[metrics]\n";
f << "json-metrics-path=" << basepath << "metrics.json\n";
f << std::endl << std::endl;
f << "# admin api (disabled by default)" << std::endl;
f << "[api]" << std::endl;
f << "enabled=false" << std::endl;

@ -20,6 +20,7 @@ namespace llarp
section_t connect;
section_t services;
section_t system;
section_t metrics;
section_t api;
section_t lokid;
section_t bootstrap;

@ -26,17 +26,7 @@
namespace llarp
{
Context::Context()
: m_scheduler(std::make_unique< thread::Scheduler >())
, m_metricsManager(std::make_unique< metrics::DefaultManagerGuard >())
, m_metricsPublisher(std::make_unique< metrics::PublisherScheduler >(
*m_scheduler, m_metricsManager->instance()))
{
m_metricsManager->instance()->addGlobalPublisher(
std::make_shared< llarp::metrics::StreamPublisher >(std::cerr));
m_metricsPublisher->setDefault(absl::Seconds(30));
m_scheduler->start();
}
Context::~Context()
@ -65,6 +55,16 @@ namespace llarp
}
using namespace std::placeholders;
config->visit(std::bind(&Context::iter_config, this, _1, _2, _3));
if(!disableMetrics)
{
setupMetrics();
if(!disableMetricLogs)
{
m_metricsManager->instance()->addGlobalPublisher(
std::make_shared< metrics::StreamPublisher >(std::cerr));
}
}
return true;
}
@ -78,6 +78,25 @@ namespace llarp
SetPIDFile(val);
}
}
if(!strcmp(section, "metrics"))
{
if(!strcmp(key, "disable-metrics"))
{
disableMetrics = true;
}
if(!strcmp(key, "disable-metrics-log"))
{
disableMetricLogs = true;
}
if(!strcmp(key, "json-metrics-path"))
{
setupMetrics();
m_metricsManager->instance()->addGlobalPublisher(
std::make_shared< metrics::JsonPublisher >(
std::bind(&metrics::JsonPublisher::directoryPublisher,
std::placeholders::_1, val)));
}
}
if(!strcmp(section, "router"))
{
if(!strcmp(key, "worker-threads") && !singleThreaded)
@ -106,6 +125,28 @@ namespace llarp
}
}
void
Context::setupMetrics()
{
if(!m_scheduler)
{
m_scheduler = std::make_unique< thread::Scheduler >();
}
if(!m_metricsManager)
{
m_metricsManager = std::make_unique< metrics::DefaultManagerGuard >();
}
if(!m_metricsPublisher)
{
m_metricsPublisher = std::make_unique< metrics::PublisherScheduler >(
*m_scheduler, m_metricsManager->instance());
}
m_metricsPublisher->setDefault(absl::Seconds(30));
m_scheduler->start();
}
void
Context::SetPIDFile(const std::string &fname)
{

Loading…
Cancel
Save