]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/rec-carbon.cc
6 #include "rec_channel.hh"
9 #include "arguments.hh"
12 GlobalStateHolder
< CarbonConfig
> g_carbonConfig
;
14 void doCarbonDump ( void *)
17 static thread_local
auto configHolder
= g_carbonConfig
. getLocal ();
19 auto config
= * configHolder
;
20 if ( config
. servers
. empty ()) {
24 if ( config
. namespace_name
. empty ()) {
25 config
. namespace_name
= "pdns" ;
28 if ( config
. hostname
. empty ()) {
30 config
. hostname
= getCarbonHostName ();
32 catch ( const std :: exception
& e
) {
33 throw std :: runtime_error ( std :: string ( "The 'carbon-ourname' setting has not been set and we are unable to determine the system's hostname: " ) + e
. what ());
36 if ( config
. instance_name
. empty ()) {
37 config
. instance_name
= "recursor" ;
42 for ( const auto & carbonServer
: config
. servers
) {
43 ComboAddress
remote ( carbonServer
, 2003 );
44 Socket
s ( remote
. sin4
. sin_family
, SOCK_STREAM
);
46 std :: shared_ptr
< TLSCtx
> tlsCtx
{ nullptr };
47 const struct timeval timeout
49 g_networkTimeoutMsec
/ 1000 , static_cast < suseconds_t
>( g_networkTimeoutMsec
) % 1000 * 1000
51 auto handler
= std :: make_shared
< TCPIOHandler
>( "" , false , s
. releaseHandle (), timeout
, tlsCtx
, time ( nullptr ));
52 handler
-> tryConnect ( SyncRes :: s_tcp_fast_open_connect
, remote
); // we do the connect so the first attempt happens while we gather stats
55 auto all
= getAllStatsMap ( StatComponent :: Carbon
);
60 for ( const auto & val
: all
) {
61 str
<< config
. namespace_name
<< '.' << config
. hostname
<< '.' << config
. instance_name
<< '.' << val
. first
<< ' ' << val
. second
. d_value
<< ' ' << now
<< " \r\n " ;
63 const string
& x
= str
. str ();
64 msg
. insert ( msg
. end (), x
. cbegin (), x
. cend ());
67 auto ret
= asendtcp ( msg
, handler
); // this will actually do the right thing waiting on the connect
68 if ( ret
== LWResult :: Result :: Timeout
) {
69 g_log
<< Logger :: Warning
<< "Timeout connecting/writing carbon data to " << remote
. toStringWithPort () << endl
;
71 else if ( ret
!= LWResult :: Result :: Success
) {
72 g_log
<< Logger :: Warning
<< "Error writing carbon data to " << remote
. toStringWithPort () << ": " << stringerror () << endl
;
77 catch ( const PDNSException
& e
) {
78 g_log
<< Logger :: Error
<< "Error in carbon thread: " << e
. reason
<< endl
;
80 catch ( const std :: exception
& e
) {
81 g_log
<< Logger :: Error
<< "Error in carbon thread: " << e
. what () << endl
;
84 g_log
<< Logger :: Error
<< "Unknown error in carbon thread" << endl
;