]> granicus.if.org Git - pdns/commitdiff
teach powerdns to measure number of open file descriptors + dnsdist to report that...
authorbert hubert <bert.hubert@powerdns.com>
Thu, 5 Nov 2015 16:13:52 +0000 (17:13 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Thu, 5 Nov 2015 16:13:52 +0000 (17:13 +0100)
pdns/dnsdist.hh
pdns/misc.cc
pdns/misc.hh

index c1e74374525cbc12d6e43942ae11f837703f9229..a5c598aacad8378486627820860da4ff1b12aac4 100644 (file)
@@ -45,7 +45,8 @@ struct DNSDistStats
     {"latency-avg100", &latencyAvg100}, {"latency-avg1000", &latencyAvg1000}, 
     {"latency-avg10000", &latencyAvg10000}, {"latency-avg1000000", &latencyAvg1000000},
     {"uptime", uptimeOfProcess},
-    {"real-memory-usage", getRealMemoryUsage}
+    {"real-memory-usage", getRealMemoryUsage},
+    {"fd-usage", getOpenFileDescriptors}
   };
 };
 
index ea4b3f6cd79ddf8b199a3573dacc92631cafbf98..bf5dae296daeb0bda60b788003b9376178d5ea5b 100644 (file)
@@ -40,6 +40,8 @@
 #include <errno.h>
 #include <cstring>
 #include <iostream>
+#include <sys/types.h>
+#include <dirent.h>
 #include <algorithm>
 #include <boost/optional.hpp>
 #include <poll.h>
@@ -1114,6 +1116,28 @@ DNSName getTSIGAlgoName(TSIGHashEnum& algoEnum)
   throw PDNSException("getTSIGAlgoName does not understand given algorithm, please fix!");
 }
 
+uint64_t getOpenFileDescriptors(const std::string&)
+{
+#ifdef __linux__
+  DIR* dirhdl=opendir(("/proc/"+std::to_string(getpid())+"/fd/").c_str());
+  if(!dirhdl) 
+    return 0;
+
+  struct dirent *entry;
+  int ret=0;
+  while((entry = readdir(dirhdl))) {
+    uint32_t num = atoi(entry->d_name);
+    if(std::to_string(num) == entry->d_name)
+      ret++;
+  }
+  closedir(dirhdl);
+  return ret;
+
+#else
+  return 0;
+#endif
+}
+
 uint64_t getRealMemoryUsage(const std::string&)
 {
 #ifdef __linux__
index b72016a0e0170ad130ed7f03b08c39dc738125cf..2141cd143cb18b9492eb600e434f47886f964774 100644 (file)
@@ -623,6 +623,7 @@ bool setCloseOnExec(int sock);
 uint64_t udpErrorStats(const std::string& str);
 
 uint64_t getRealMemoryUsage(const std::string&);
+uint64_t getOpenFileDescriptors(const std::string&);
 
 template<typename T, typename... Args>
 std::unique_ptr<T> make_unique(Args&&... args)