From: Remi Gacogne Date: Mon, 3 Feb 2020 10:05:23 +0000 (+0100) Subject: Add functions to retrieve 'IO wait' and 'steal' metrics on Linux X-Git-Tag: auth-4.3.0-beta2~28^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=591d1bd31f42e6f5af64bd663ad4de5b907a971e;p=thirdparty%2Fpdns.git Add functions to retrieve 'IO wait' and 'steal' metrics on Linux --- diff --git a/pdns/misc.cc b/pdns/misc.cc index f9248af42a..279151116a 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -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 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 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")) diff --git a/pdns/misc.hh b/pdns/misc.hh index 4bd9439a87..b4924c4274 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -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 std::unique_ptr make_unique(Args&&... args)