1 | #include <daemon/GraphiteWriter.h> |
2 | #include <daemon/BaseDaemon.h> |
3 | #include <Poco/Util/LayeredConfiguration.h> |
4 | #include <Poco/Util/Application.h> |
5 | #include <Common/getFQDNOrHostName.h> |
6 | |
7 | #include <mutex> |
8 | #include <iomanip> |
9 | |
10 | |
11 | GraphiteWriter::GraphiteWriter(const std::string & config_name, const std::string & sub_path) |
12 | { |
13 | Poco::Util::LayeredConfiguration & config = Poco::Util::Application::instance().config(); |
14 | port = config.getInt(config_name + ".port" , 42000); |
15 | host = config.getString(config_name + ".host" , "localhost" ); |
16 | timeout = config.getDouble(config_name + ".timeout" , 0.1); |
17 | |
18 | root_path = config.getString(config_name + ".root_path" , "one_min" ); |
19 | |
20 | if (config.getBool(config_name + ".hostname_in_path" , true)) |
21 | { |
22 | if (!root_path.empty()) |
23 | root_path += "." ; |
24 | |
25 | std::string hostname_in_path = getFQDNOrHostName(); |
26 | |
27 | /// Replace dots to underscores so that Graphite does not interpret them as path separators |
28 | std::replace(std::begin(hostname_in_path), std::end(hostname_in_path), '.', '_'); |
29 | |
30 | root_path += hostname_in_path; |
31 | } |
32 | |
33 | if (sub_path.size()) |
34 | { |
35 | if (!root_path.empty()) |
36 | root_path += "." ; |
37 | root_path += sub_path; |
38 | } |
39 | } |
40 | |
41 | |
42 | std::string GraphiteWriter::getPerServerPath(const std::string & server_name, const std::string & root_path) |
43 | { |
44 | std::string path = root_path + "." + server_name; |
45 | std::replace(path.begin() + root_path.size() + 1, path.end(), '.', '_'); |
46 | return path; |
47 | } |
48 | |