diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-04-17 17:59:04 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-04-17 17:59:04 -0400 |
commit | 874d317c01b5293ce7ba6f7de2e61155816b821e (patch) | |
tree | 71826c70f5dc90adddeb36a9afdc232c4966fc06 | |
parent | dc4cfd6e5c458fcb03a5d5086ab6112fb692fbc0 (diff) | |
download | mongo-874d317c01b5293ce7ba6f7de2e61155816b821e.tar.gz |
SERVER-24610 Add FTDC Collector for Windows Performance Counters
(cherry picked from commit ccb68d79b4dbe790bb228d78fa2c70627cdea883)
-rw-r--r-- | src/mongo/db/ftdc/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/db/ftdc/ftdc_system_stats_windows.cpp | 123 |
2 files changed, 126 insertions, 1 deletions
diff --git a/src/mongo/db/ftdc/SConscript b/src/mongo/db/ftdc/SConscript index 26cbb8a8382..4b696acbf0a 100644 --- a/src/mongo/db/ftdc/SConscript +++ b/src/mongo/db/ftdc/SConscript @@ -38,6 +38,10 @@ if env.TargetOSIs('linux'): platform_libs = [ '$BUILD_DIR/mongo/util/procparser' ] +elif env.TargetOSIs('windows'): + platform_libs = [ + '$BUILD_DIR/mongo/util/perfctr_collect' + ] env.Library( target='ftdc_mongod', diff --git a/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp index d06092f9ba9..401e6776523 100644 --- a/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp +++ b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp @@ -26,12 +26,133 @@ * then also delete it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kFTDC + #include "mongo/platform/basic.h" #include "mongo/db/ftdc/ftdc_system_stats.h" +#include <string> +#include <vector> + +#include "mongo/base/status.h" +#include "mongo/base/string_data.h" +#include "mongo/bson/bsonobjbuilder.h" +#include "mongo/db/ftdc/collector.h" +#include "mongo/db/ftdc/controller.h" +#include "mongo/stdx/memory.h" +#include "mongo/util/log.h" +#include "mongo/util/perfctr_collect.h" + namespace mongo { -void installSystemMetricsCollector(FTDCController* controller) {} +namespace { + +const std::vector<StringData> kCpuCounters = { + "\\Processor(_Total)\\% Idle Time", + "\\Processor(_Total)\\% Interrupt Time", + "\\Processor(_Total)\\% Privileged Time", + "\\Processor(_Total)\\% Processor Time", + "\\Processor(_Total)\\% User Time", + "\\Processor(_Total)\\Interrupts/sec", + "\\System\\Context Switches/sec", + "\\System\\Processes", + "\\System\\Processor Queue Length", + "\\System\\System Up Time", + "\\System\\Threads", +}; + +const std::vector<StringData> kMemoryCounters = { + "\\Memory\\Available Bytes", + "\\Memory\\Cache Bytes", + "\\Memory\\Cache Faults/sec", + "\\Memory\\Committed Bytes", + "\\Memory\\Commit Limit", + "\\Memory\\Page Reads/sec", + "\\Memory\\Page Writes/sec", + "\\Memory\\Pages Input/sec", + "\\Memory\\Pages Output/sec", + "\\Memory\\Pool Nonpaged Bytes", + "\\Memory\\Pool Paged Bytes", + "\\Memory\\Pool Paged Resident Bytes", + "\\Memory\\System Cache Resident Bytes", + "\\Memory\\System Code Total Bytes", + +}; + +const std::vector<StringData> kDiskCounters = { + "\\PhysicalDisk(*)\\% Disk Read Time", + "\\PhysicalDisk(*)\\% Disk Write Time", + "\\PhysicalDisk(*)\\Avg. Disk Bytes/Read", + "\\PhysicalDisk(*)\\Avg. Disk Bytes/Write", + "\\PhysicalDisk(*)\\Avg. Disk Read Queue Length", + "\\PhysicalDisk(*)\\Avg. Disk Write Queue Length", + "\\PhysicalDisk(*)\\Avg. Disk sec/Read", + "\\PhysicalDisk(*)\\Avg. Disk sec/Write", + "\\PhysicalDisk(*)\\Disk Read Bytes/sec", + "\\PhysicalDisk(*)\\Disk Write Bytes/sec", + "\\PhysicalDisk(*)\\Disk Reads/sec", + "\\PhysicalDisk(*)\\Disk Writes/sec", + "\\PhysicalDisk(*)\\Current Disk Queue Length", +}; + + +/** + * Collect metrics from Windows Performance Counters. + */ +class WindowsSystemMetricsCollector final : public SystemMetricsCollector { +public: + WindowsSystemMetricsCollector(std::unique_ptr<PerfCounterCollector> collector) + : _collector(std::move(collector)) {} + + void collect(OperationContext* txn, BSONObjBuilder& builder) override { + processStatusErrors(_collector->collect(&builder), &builder); + } + +private: + std::unique_ptr<PerfCounterCollector> _collector; +}; + + +StatusWith<std::unique_ptr<PerfCounterCollector>> createCollector() { + PerfCounterCollection collection; + + Status s = collection.addCountersGroup("cpu", kCpuCounters); + if (!s.isOK()) { + return s; + } + + // TODO: Should we capture the Heap Counters for the current process? + s = collection.addCountersGroup("memory", kMemoryCounters); + if (!s.isOK()) { + return s; + } + + s = collection.addCountersGroupedByInstanceName("disks", kDiskCounters); + if (!s.isOK()) { + return s; + } + + auto swCollector = PerfCounterCollector::create(std::move(collection)); + if (!swCollector.getStatus().isOK()) { + return swCollector.getStatus(); + } + + return {std::move(swCollector.getValue())}; +} + +} // namespace + +void installSystemMetricsCollector(FTDCController* controller) { + auto swCollector = createCollector(); + if (!swCollector.getStatus().isOK()) { + warning() << "Failed to initialize Performance Counters for FTDC: " + << swCollector.getStatus(); + return; + } + + controller->addPeriodicCollector( + stdx::make_unique<WindowsSystemMetricsCollector>(std::move(swCollector.getValue()))); +} } // namespace mongo |