Add hostname_in_path=true option to garaphite config (#1701)

* Add hostname_in_path=true option to garaphite config

* fix style

* Update config.xml
This commit is contained in:
proller 2017-12-25 23:36:24 +03:00 committed by alexey-milovidov
parent 73ae622b12
commit 3c54be8d5b
2 changed files with 17 additions and 7 deletions

View File

@ -180,6 +180,7 @@
<!--
interval - send every X second
root_path - prefix for keys
hostname_in_path - append hostname to root_path (default = true)
metrics - send data from table system.metrics
events - send data from table system.events
asynchronous_metrics - send data from table system.asynchronous_metrics
@ -191,6 +192,7 @@
<timeout>0.1</timeout>
<interval>60</interval>
<root_path>one_min</root_path>
<hostname_in_path>true<hostname_in_path>
<metrics>true</metrics>
<events>true</events>

View File

@ -16,18 +16,26 @@ GraphiteWriter::GraphiteWriter(const std::string & config_name, const std::strin
timeout = config.getDouble(config_name + ".timeout", 0.1);
root_path = config.getString(config_name + ".root_path", "one_min");
if (!root_path.empty())
root_path += ".";
std::string hostname_in_path = getFQDNOrHostName();
if (config.getBool(config_name + ".hostname_in_path", true))
{
if (!root_path.empty())
root_path += ".";
/// Заменяем точки на подчёркивания, чтобы Graphite не интерпретировал их, как разделители пути.
std::replace(std::begin(hostname_in_path), std::end(hostname_in_path), '.', '_');
std::string hostname_in_path = getFQDNOrHostName();
root_path += hostname_in_path;
/// 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;
}
if (sub_path.size())
root_path += "." + sub_path;
{
if (!root_path.empty())
root_path += ".";
root_path += sub_path;
}
}