From: Remi Gacogne Date: Thu, 19 Nov 2015 15:20:54 +0000 (+0100) Subject: Export dnsdist CPU usage to carbon. Fixes #2913. X-Git-Tag: dnsdist-1.0.0-alpha1~210^2~10^2~3^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f99f3d3f16f6ceae7bc986a6ea5f7232d6c9956;p=pdns Export dnsdist CPU usage to carbon. Fixes #2913. --- diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index d3450e1fb..3220e2044 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -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} }; }; diff --git a/pdns/misc.cc b/pdns/misc.cc index 3c251e11f..61c64f9fe 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -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); +} diff --git a/pdns/misc.hh b/pdns/misc.hh index eea3b4a9a..78d42ec84 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -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 std::unique_ptr make_unique(Args&&... args)