]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/rec-carbon.cc
6 #include "rec_channel.hh"
9 #include "arguments.hh"
13 void doCarbonDump(void*)
18 string namespace_name
;
19 vector
<string
> carbonServers
;
22 Lock
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()) {
37 memset(tmp
, 0, sizeof(tmp
));
38 gethostname(tmp
, sizeof(tmp
));
39 char *p
= strchr(tmp
, '.');
43 boost::replace_all(hostname
, ".", "_");
45 if(instance_name
.empty()) {
46 instance_name
="recursor";
51 for(const auto& carbonServer
: carbonServers
) {
52 ComboAddress
remote(carbonServer
, 2003);
53 Socket
s(remote
.sin4
.sin_family
, SOCK_STREAM
);
56 s
.connect(remote
); // we do the connect so the first attempt happens while we gather stats
59 typedef map
<string
,string
> all_t
;
60 all_t all
=getAllStatsMap(StatComponent::Carbon
);
65 for(const all_t::value_type
& val
: all
) {
66 str
<<namespace_name
<<'.'<<hostname
<<'.'<<instance_name
<<'.'<<val
.first
<<' '<<val
.second
<<' '<<now
<<"\r\n";
71 int ret
=asendtcp(msg
, &s
); // this will actually do the right thing waiting on the connect
73 g_log
<<Logger::Warning
<<"Error writing carbon data to "<<remote
.toStringWithPort()<<": "<<strerror(errno
)<<endl
;
75 g_log
<<Logger::Warning
<<"Timeout connecting/writing carbon data to "<<remote
.toStringWithPort()<<endl
;
78 catch(PDNSException
& e
)
80 g_log
<<Logger::Error
<<"Error in carbon thread: "<<e
.reason
<<endl
;
82 catch(std::exception
& e
)
84 g_log
<<Logger::Error
<<"Error in carbon thread: "<<e
.what()<<endl
;
88 g_log
<<Logger::Error
<<"Unknown error in carbon thread"<<endl
;