Integrate metric tank into build

pull/517/head
Michael 5 years ago
parent 3b5d49e0f8
commit 9bc501bbf7

@ -5,6 +5,7 @@
#include <ev/ev.hpp>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
@ -48,6 +49,10 @@ namespace llarp
bool singleThreaded = false;
bool disableMetrics = false;
bool disableMetricLogs = false;
std::string jsonMetricsPath;
std::string metricTankHost;
std::map< std::string, std::string > metricTags;
std::unique_ptr< Crypto > crypto;
std::unique_ptr< AbstractRouter > router;
std::unique_ptr< llarp_threadpool > worker;

@ -61,6 +61,7 @@ set(LIB_PLATFORM_SRC
# for networking
ev/ev.cpp
ev/pipe.cpp
metrics/metrictank_publisher.cpp
metrics/publishers.cpp
net/net.cpp
net/net_addr.cpp

@ -7,6 +7,7 @@
#include <dns/dotlokilookup.hpp>
#include <dnsd.hpp>
#include <ev/ev.hpp>
#include <metrics/metrictank_publisher.hpp>
#include <metrics/publishers.hpp>
#include <nodedb.hpp>
#include <router/router.hpp>
@ -14,6 +15,7 @@
#include <util/metrics.hpp>
#include <util/scheduler.hpp>
#include <absl/strings/str_split.h>
#include <getopt.h>
#include <signal.h>
@ -81,17 +83,22 @@ namespace llarp
{
disableMetrics = true;
}
if(!strcmp(key, "disable-metrics-log"))
else if(!strcmp(key, "disable-metrics-log"))
{
disableMetricLogs = true;
}
if(!strcmp(key, "json-metrics-path"))
else 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)));
jsonMetricsPath = val;
}
else if(!strcmp(key, "metric-tank-host"))
{
metricTankHost = val;
}
else
{
// consume everything else as a metric tag
metricTags[key] = val;
}
}
if(!strcmp(section, "router"))
@ -139,7 +146,50 @@ namespace llarp
*m_scheduler, m_metricsManager->instance());
}
m_metricsPublisher->setDefault(absl::Seconds(30));
m_metricsManager->instance()->addGlobalPublisher(
std::make_shared< metrics::JsonPublisher >(
std::bind(&metrics::JsonPublisher::directoryPublisher,
std::placeholders::_1, jsonMetricsPath)));
if(!metricTankHost.empty())
{
if(std::getenv("LOKINET_ENABLE_METRIC_TANK"))
{
static std::string WARNING = R"(
__ ___ ____ _ _ ___ _ _ ____
\ \ / / \ | _ \| \ | |_ _| \ | |/ ___|
\ \ /\ / / _ \ | |_) | \| || || \| | | _
\ V V / ___ \| _ <| |\ || || |\ | |_| |
\_/\_/_/ \_\_| \_\_| \_|___|_| \_|\____|
This Lokinet session is not private
Sending connection metrics to metrictank
__ ___ ____ _ _ ___ _ _ ____
\ \ / / \ | _ \| \ | |_ _| \ | |/ ___|
\ \ /\ / / _ \ | |_) | \| || || \| | | _
\ V V / ___ \| _ <| |\ || || |\ | |_| |
\_/\_/_/ \_\_| \_\_| \_|___|_| \_|\____|
)";
std::cerr << WARNING << '\n';
std::pair< std::string, std::string > split =
absl::StrSplit(metricTankHost, ':');
m_metricsManager->instance()->addGlobalPublisher(
std::make_shared< metrics::MetricTankPublisher >(
metricTags, split.first, stoi(split.second)));
}
else
{
std::cerr << "metrictank host specified, but "
"LOKINET_ENABLE_METRIC_TANK not set, skipping\n";
}
}
m_metricsPublisher->setDefault(absl::Seconds(1));
m_scheduler->start();
}
@ -227,8 +277,8 @@ namespace llarp
return 1;
}
// must be done after router is made so we can use its disk io worker
// must also be done after configure so that netid is properly set if it is
// provided by config
// must also be done after configure so that netid is properly set if it
// is provided by config
if(!this->LoadDatabase())
return 1;
return 0;

Loading…
Cancel
Save