2016-01-15 04:13:00 +00:00
|
|
|
#include <daemon/GraphiteWriter.h>
|
2016-02-09 17:06:50 +00:00
|
|
|
#include <daemon/BaseDaemon.h>
|
2016-01-15 03:55:07 +00:00
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
#include <Poco/Util/Application.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/getFQDNOrHostName.h>
|
2016-01-15 03:55:07 +00:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
|
|
GraphiteWriter::GraphiteWriter(const std::string & config_name, const std::string & sub_path)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Util::LayeredConfiguration & config = Poco::Util::Application::instance().config();
|
|
|
|
port = config.getInt(config_name + ".port", 42000);
|
|
|
|
host = config.getString(config_name + ".host", "localhost");
|
|
|
|
timeout = config.getDouble(config_name + ".timeout", 0.1);
|
2016-01-15 03:55:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
root_path = config.getString(config_name + ".root_path", "one_min");
|
2016-01-15 03:55:07 +00:00
|
|
|
|
2017-12-25 20:36:24 +00:00
|
|
|
if (config.getBool(config_name + ".hostname_in_path", true))
|
|
|
|
{
|
|
|
|
if (!root_path.empty())
|
|
|
|
root_path += ".";
|
2016-01-15 03:55:07 +00:00
|
|
|
|
2017-12-25 20:36:24 +00:00
|
|
|
std::string hostname_in_path = getFQDNOrHostName();
|
2016-01-15 03:55:07 +00:00
|
|
|
|
2017-12-25 20:36:24 +00:00
|
|
|
/// Replace dots to underscores so that Graphite does not interpret them as path separators
|
|
|
|
std::replace(std::begin(hostname_in_path), std::end(hostname_in_path), '.', '_');
|
|
|
|
|
|
|
|
root_path += hostname_in_path;
|
|
|
|
}
|
2016-03-31 20:13:56 +00:00
|
|
|
|
2020-03-08 21:04:10 +00:00
|
|
|
if (!sub_path.empty())
|
2017-12-25 20:36:24 +00:00
|
|
|
{
|
|
|
|
if (!root_path.empty())
|
|
|
|
root_path += ".";
|
|
|
|
root_path += sub_path;
|
|
|
|
}
|
2016-01-15 03:55:07 +00:00
|
|
|
}
|