]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add 'queue full' metrics for our remote logger, log at debug only 8883/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Feb 2020 16:21:19 +0000 (17:21 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Feb 2020 16:21:19 +0000 (17:21 +0100)
pdns/dnsdist.hh
pdns/fstrm_logger.cc
pdns/fstrm_logger.hh
pdns/remote_logger.cc
pdns/remote_logger.hh

index d1d951545277085422b084960589eaf60b83946b..c5c36167d5d1816db34355e543c8ba4de571f117 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <boost/variant.hpp>
 
-#include "bpf-filter.hh"
 #include "capabilities.hh"
 #include "circular_buffer.hh"
 #include "dnscrypt.hh"
index 62ccd72ebd10a5b3f52c9b5ebd7b3ef89c66f6d9..9e5608f94703c8bdfa1dac85af6ba857d25f0d7c 100644 (file)
@@ -195,13 +195,15 @@ void FrameStreamLogger::queueData(const std::string& data)
 
   if (res == fstrm_res_success) {
     // Frame successfully queued.
+    ++d_framesSent;
   } else if (res == fstrm_res_again) {
     free(frame);
 #ifdef RECURSOR
-    g_log<<Logger::Warning<<"FrameStreamLogger: queue full, dropping."<<std::endl;
+    g_log<<Logger::Debug<<"FrameStreamLogger: queue full, dropping."<<std::endl;
 #else
-    warnlog("FrameStreamLogger: queue full, dropping.");
+    vinfolog("FrameStreamLogger: queue full, dropping.");
 #endif
+    ++d_queueFullDrops;
  } else {
     // Permanent failure.
     free(frame);
@@ -210,6 +212,7 @@ void FrameStreamLogger::queueData(const std::string& data)
 #else
     warnlog("FrameStreamLogger: submitting to queue failed.");
 #endif
+    ++d_permanentFailures;
   }
 }
 
index c6844a515d7baf9e6144aabecfa46c4204a5871b..a59e194b9deb6d25f0fd5502f2a06bce72ad9a77 100644 (file)
@@ -37,11 +37,11 @@ class FrameStreamLogger : public RemoteLoggerInterface, boost::noncopyable
 {
 public:
   FrameStreamLogger(int family, const std::string& address, bool connect, const std::unordered_map<string,unsigned>& options = std::unordered_map<string,unsigned>());
-  virtual ~FrameStreamLogger();
-  virtual void queueData(const std::string& data) override;
-  virtual std::string toString() const override
+  ~FrameStreamLogger();
+  void queueData(const std::string& data) override;
+  std::string toString() const override
   {
-    return "FrameStreamLogger to " + d_address;
+    return "FrameStreamLogger to " + d_address + " (" + std::to_string(d_framesSent) + " frames sent, " + std::to_string(d_queueFullDrops) + " dropped, " + std::to_string(d_permanentFailures) + " permanent failures)";
   }
 
 private:
@@ -57,6 +57,9 @@ private:
   struct fstrm_writer *d_writer{nullptr};
   struct fstrm_iothr_options *d_iothropt{nullptr};
   struct fstrm_iothr *d_iothr{nullptr};
+  std::atomic<uint64_t> d_framesSent{0};
+  std::atomic<uint64_t> d_queueFullDrops{0};
+  std::atomic<uint64_t> d_permanentFailures{0};
 
   void cleanup();
 };
index 69934b98a9517850e31c17d31bcbd686cbab3083..b277c7f191077fda271eb81ef0a2998ff7b69ba4 100644 (file)
@@ -54,11 +54,13 @@ void CircularWriteBuffer::flush()
     throw std::runtime_error("EOF");
   }
   //  cout<<"Flushed "<<res<<" bytes out of " << total <<endl;
-  if((size_t)res == d_buffer.size())
+  if (static_cast<size_t>(res) == d_buffer.size()) {
     d_buffer.clear();
+  }
   else {
-    while(res--)
+    while(res--) {
       d_buffer.pop_front();
+    }
   }
 }
 
@@ -96,17 +98,18 @@ bool RemoteLogger::reconnect()
 void RemoteLogger::queueData(const std::string& data)
 {
   if(!d_writer) {
-    d_drops++;
+    ++d_drops;
     return;
   }
   std::unique_lock<std::mutex> lock(d_mutex);
   if(d_writer) {
     try {
       d_writer->write(data);
+      ++d_queued;
     }
-    catch(std::exception& e) {
+    catch(const std::exception& e) {
       //      cout << "Got exception writing: "<<e.what()<<endl;
-      d_drops++;
+      ++d_drops;
       d_writer.reset();
       close(d_socket);
       d_socket = -1;
@@ -151,7 +154,7 @@ try
     sleep(d_reconnectWaitTime);
   }
 }
-catch(std::exception& e)
+catch(const std::exception& e)
 {
   cerr<<"Thead died on: "<<e.what()<<endl;
 }
index d5356c2d3e2b232f8f8c9286b9d0c042a67ba4be..8bcf6b05288e5f70021041780a5cd9c4e285aa2e 100644 (file)
@@ -89,22 +89,23 @@ public:
   void queueData(const std::string& data) override;
   std::string toString() const override
   {
-    return d_remote.toStringWithPort();
+    return d_remote.toStringWithPort() + " (" + std::to_string(d_queued) + " queued, " + std::to_string(d_drops) + " dropped)";
   }
   void stop()
   {
     d_exiting = true;
   }
-  std::atomic<uint32_t> d_drops{0};
 
 private:
   bool reconnect();
   void maintenanceThread();
 
+  std::unique_ptr<CircularWriteBuffer> d_writer;
   ComboAddress d_remote;
+  std::atomic<uint64_t> d_drops{0};
+  std::atomic<uint64_t> d_queued{0};
   uint64_t d_maxQueuedBytes;
   int d_socket{-1};
-  std::unique_ptr<CircularWriteBuffer> d_writer;
   uint16_t d_timeout;
   uint8_t d_reconnectWaitTime;
   std::atomic<bool> d_exiting{false};