]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/auth-carbon.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "threadname.hh"
30 #include "arguments.hh"
31 #include "auth-main.hh"
33 #include "namespaces.hh"
35 void carbonDumpThread ()
38 setThreadName ( "pdns/carbonDump" );
41 string namespace_name
= arg ()[ "carbon-namespace" ];
42 string hostname
= arg ()[ "carbon-ourname" ];
43 if ( hostname
. empty ()) {
45 hostname
= getCarbonHostName ();
47 catch ( const std :: exception
& e
) {
48 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 ());
51 string instance_name
= arg ()[ "carbon-instance" ];
53 vector
< string
> carbonServers
;
54 stringtok ( carbonServers
, arg ()[ "carbon-server" ], ", " );
57 if ( carbonServers
. empty ()) {
63 vector
< string
> entries
= S
. getEntries ();
65 time_t now
= time ( nullptr );
66 for ( const string
& entry
: entries
) {
67 str
<< namespace_name
<< '.' << hostname
<< '.' << instance_name
<< '.' << entry
<< ' ' << S
. read ( entry
)<< ' ' << now
<< " \r\n " ;
71 for ( const auto & carbonServer
: carbonServers
) {
72 ComboAddress
remote ( carbonServer
, 2003 );
75 Socket
s ( remote
. sin4
. sin_family
, SOCK_STREAM
);
79 writen2WithTimeout ( s
. getHandle (), msg
. c_str (), msg
. length (), timeval
{ 2 , 0 });
80 } catch ( runtime_error
& e
){
81 g_log
<< Logger :: Warning
<< "Unable to write data to carbon server at " << remote
. toStringWithPort ()<< ": " << e
. what ()<< endl
;
85 sleep ( arg (). asNum ( "carbon-interval" ));
88 catch ( std :: exception
& e
)
90 g_log
<< Logger :: Error
<< "Carbon thread died: " << e
. what ()<< endl
;
92 catch ( PDNSException
& e
)
94 g_log
<< Logger :: Error
<< "Carbon thread died, PDNSException: " << e
. reason
<< endl
;
98 g_log
<< Logger :: Error
<< "Carbon thread died" << endl
;