]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add functions to retrieve 'IO wait' and 'steal' metrics on Linux
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 3 Feb 2020 10:05:23 +0000 (11:05 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 5 Feb 2020 09:40:38 +0000 (10:40 +0100)
pdns/misc.cc
pdns/misc.hh

index f9248af42a1193d8f28af6aa2bcdcdcf11dcd8a1..279151116a9ee6cf2d85cbd7c1d7c1f4473cc2da 100644 (file)
@@ -1236,6 +1236,56 @@ uint64_t udpErrorStats(const std::string& str)
   return 0;
 }
 
+uint64_t getCPUIOWait(const std::string& str)
+{
+#ifdef __linux__
+  ifstream ifs("/proc/stat");
+  if (!ifs) {
+    return 0;
+  }
+
+  string line;
+  vector<string> parts;
+  while (getline(ifs, line)) {
+    if (boost::starts_with(line, "cpu ")) {
+      stringtok(parts, line, " \n\t\r");
+
+      if (parts.size() < 6) {
+        break;
+      }
+
+      return std::stoull(parts[5]);
+    }
+  }
+#endif
+  return 0;
+}
+
+uint64_t getCPUSteal(const std::string& str)
+{
+#ifdef __linux__
+  ifstream ifs("/proc/stat");
+  if (!ifs) {
+    return 0;
+  }
+
+  string line;
+  vector<string> parts;
+  while (getline(ifs, line)) {
+    if (boost::starts_with(line, "cpu ")) {
+      stringtok(parts, line, " \n\t\r");
+
+      if (parts.size() < 9) {
+        break;
+      }
+
+      return std::stoull(parts[8]);
+    }
+  }
+#endif
+  return 0;
+}
+
 bool getTSIGHashEnum(const DNSName& algoName, TSIGHashEnum& algoEnum)
 {
   if (algoName == DNSName("hmac-md5.sig-alg.reg.int") || algoName == DNSName("hmac-md5"))
index 4bd9439a87deab30b7511402d391fe65b36c320c..b4924c427468f4130f73956ccb58802ebc25f919 100644 (file)
@@ -551,6 +551,8 @@ uint64_t getSpecialMemoryUsage(const std::string&);
 uint64_t getOpenFileDescriptors(const std::string&);
 uint64_t getCPUTimeUser(const std::string&);
 uint64_t getCPUTimeSystem(const std::string&);
+uint64_t getCPUIOWait(const std::string&);
+uint64_t getCPUSteal(const std::string&);
 std::string getMACAddress(const ComboAddress& ca);
 template<typename T, typename... Args>
 std::unique_ptr<T> make_unique(Args&&... args)