]> granicus.if.org Git - pdns/commitdiff
Export dnsdist CPU usage to carbon. Fixes #2913.
authorRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 19 Nov 2015 15:20:54 +0000 (16:20 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 19 Nov 2015 15:21:33 +0000 (16:21 +0100)
pdns/dnsdist.hh
pdns/misc.cc
pdns/misc.hh

index d3450e1fb7e260bad3847a707fd51881ed603c61..3220e2044e344ff29c1157488a0a203c5ed15d31 100644 (file)
@@ -46,6 +46,8 @@ struct DNSDistStats
     {"latency-avg10000", &latencyAvg10000}, {"latency-avg1000000", &latencyAvg1000000},
     {"uptime", uptimeOfProcess},
     {"real-memory-usage", getRealMemoryUsage},
+    {"cpu-user-msec", getCPUTimeUser},
+    {"cpu-sys-msec", getCPUTimeSystem},
     {"fd-usage", getOpenFileDescriptors}
   };
 };
index 3c251e11f215909bdffa687f72265eca725b2c81..61c64f9fe93ca5268ecef5f3cf303a92bbd8d157 100644 (file)
@@ -1194,3 +1194,17 @@ uint64_t getRealMemoryUsage(const std::string&)
   return 0;
 #endif
 }
+
+uint64_t getCPUTimeUser(const std::string&)
+{
+  struct rusage ru;
+  getrusage(RUSAGE_SELF, &ru);
+  return (ru.ru_utime.tv_sec*1000ULL + ru.ru_utime.tv_usec/1000);
+}
+
+uint64_t getCPUTimeSystem(const std::string&)
+{
+  struct rusage ru;
+  getrusage(RUSAGE_SELF, &ru);
+  return (ru.ru_stime.tv_sec*1000ULL + ru.ru_stime.tv_usec/1000);
+}
index eea3b4a9a0d65dd0c790325cfa41447a75a8a2c6..78d42ec84903c75b33cf26bc95105a6c68367e6c 100644 (file)
@@ -623,6 +623,8 @@ uint64_t udpErrorStats(const std::string& str);
 
 uint64_t getRealMemoryUsage(const std::string&);
 uint64_t getOpenFileDescriptors(const std::string&);
+uint64_t getCPUTimeUser(const std::string&);
+uint64_t getCPUTimeSystem(const std::string&);
 
 template<typename T, typename... Args>
 std::unique_ptr<T> make_unique(Args&&... args)