]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/rec-carbon.cc
ef1204d6ec1d3231742bf7df74f6835143a64b8e
6 #include "rec_channel.hh"
9 #include "arguments.hh"
13 void doCarbonDump(void*)
18 string namespace_name
;
19 vector
<string
> carbonServers
;
22 std::lock_guard
<std::mutex
> l(g_carbon_config_lock
);
23 stringtok(carbonServers
, arg()["carbon-server"], ", ");
24 namespace_name
=arg()["carbon-namespace"];
25 hostname
=arg()["carbon-ourname"];
26 instance_name
=arg()["carbon-instance"];
29 if(carbonServers
.empty())
32 if(namespace_name
.empty()) {
33 namespace_name
="pdns";
35 if(hostname
.empty()) {
36 char tmp
[HOST_NAME_MAX
+1];
37 memset(tmp
, 0, sizeof(tmp
));
38 if (gethostname(tmp
, sizeof(tmp
)) != 0) {
39 throw std::runtime_error("The 'carbon-ourname' setting has not been set and we are unable to determine the system's hostname: " + stringerror());
41 char *p
= strchr(tmp
, '.');
45 boost::replace_all(hostname
, ".", "_");
47 if(instance_name
.empty()) {
48 instance_name
="recursor";
53 for(const auto& carbonServer
: carbonServers
) {
54 ComboAddress
remote(carbonServer
, 2003);
55 Socket
s(remote
.sin4
.sin_family
, SOCK_STREAM
);
58 s
.connect(remote
); // we do the connect so the first attempt happens while we gather stats
61 typedef map
<string
,string
> all_t
;
62 all_t all
=getAllStatsMap(StatComponent::Carbon
);
67 for(const all_t::value_type
& val
: all
) {
68 str
<<namespace_name
<<'.'<<hostname
<<'.'<<instance_name
<<'.'<<val
.first
<<' '<<val
.second
<<' '<<now
<<"\r\n";
73 int ret
=asendtcp(msg
, &s
); // this will actually do the right thing waiting on the connect
75 g_log
<<Logger::Warning
<<"Error writing carbon data to "<<remote
.toStringWithPort()<<": "<<stringerror()<<endl
;
77 g_log
<<Logger::Warning
<<"Timeout connecting/writing carbon data to "<<remote
.toStringWithPort()<<endl
;
80 catch(PDNSException
& e
)
82 g_log
<<Logger::Error
<<"Error in carbon thread: "<<e
.reason
<<endl
;
84 catch(std::exception
& e
)
86 g_log
<<Logger::Error
<<"Error in carbon thread: "<<e
.what()<<endl
;
90 g_log
<<Logger::Error
<<"Unknown error in carbon thread"<<endl
;