summaryrefslogtreecommitdiff
path: root/src/mongo/db/ftdc
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2016-07-26 10:43:13 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2016-07-26 10:43:13 -0400
commitaca68d91a7226a14cfdc73171eb97c4922559940 (patch)
tree6c5c047224ee90e4af543916d47d664fca4c4318 /src/mongo/db/ftdc
parentee4038aebd217f0ddc499d8d3da6e3b0ca485354 (diff)
downloadmongo-aca68d91a7226a14cfdc73171eb97c4922559940.tar.gz
SERVER-24610 Refactor System Stats Collectors
Diffstat (limited to 'src/mongo/db/ftdc')
-rw-r--r--src/mongo/db/ftdc/SConscript1
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats.cpp93
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats.h26
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_freebsd.cpp37
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_linux.cpp107
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_openbsd.cpp37
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_osx.cpp37
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_solaris.cpp37
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_windows.cpp37
9 files changed, 331 insertions, 81 deletions
diff --git a/src/mongo/db/ftdc/SConscript b/src/mongo/db/ftdc/SConscript
index ba630ba68c1..c6fedc0e9e1 100644
--- a/src/mongo/db/ftdc/SConscript
+++ b/src/mongo/db/ftdc/SConscript
@@ -41,6 +41,7 @@ env.Library(
'ftdc_commands.cpp',
'ftdc_mongod.cpp',
'ftdc_system_stats.cpp',
+ 'ftdc_system_stats_${TARGET_OS}.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/db/ftdc/ftdc_system_stats.cpp b/src/mongo/db/ftdc/ftdc_system_stats.cpp
index f0ffb319284..b087735d244 100644
--- a/src/mongo/db/ftdc/ftdc_system_stats.cpp
+++ b/src/mongo/db/ftdc/ftdc_system_stats.cpp
@@ -28,103 +28,34 @@
#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"
-
-#ifdef __linux__
-#include "mongo/util/procparser.h"
-#endif
namespace mongo {
-constexpr auto kSystemMetricsCollector = "systemMetrics";
-
-#ifdef __linux__
-static const std::vector<StringData> kCpuKeys{
- "btime", "cpu", "ctxt", "processes", "procs_blocked", "procs_running"};
-
-// Collect all the memory keys by specifying an empty set.
-static const std::vector<StringData> kMemKeys{};
+namespace {
/**
- * Collect metrics from the Linux /proc file system.
+ * Name of FTDC collector to create.
*/
-class LinuxSystemMetricsCollector final : public FTDCCollectorInterface {
-public:
- LinuxSystemMetricsCollector() : _disks(procparser::findPhysicalDisks("/sys/block")) {
- for (const auto& disk : _disks) {
- _disksStringData.emplace_back(disk);
- }
- }
-
- void collect(OperationContext* txn, BSONObjBuilder& builder) override {
- {
- BSONObjBuilder subObjBuilder(builder.subobjStart("cpu"));
- processStatusErrors(
- procparser::parseProcStatFile("/proc/stat", kCpuKeys, &subObjBuilder),
- &subObjBuilder);
- subObjBuilder.doneFast();
- }
-
- {
- BSONObjBuilder subObjBuilder(builder.subobjStart("memory"));
- processStatusErrors(
- procparser::parseProcMemInfoFile("/proc/meminfo", kMemKeys, &subObjBuilder),
- &subObjBuilder);
- subObjBuilder.doneFast();
- }
+constexpr auto kSystemMetricsCollector = "systemMetrics";
- // Skip the disks section if we could not find any disks.
- // This can happen when we do not have permission to /sys/block for instance.
- if (!_disksStringData.empty()) {
- BSONObjBuilder subObjBuilder(builder.subobjStart("disks"));
- processStatusErrors(procparser::parseProcDiskStatsFile(
- "/proc/diskstats", _disksStringData, &subObjBuilder),
- &subObjBuilder);
- subObjBuilder.doneFast();
- }
- }
+} // namespace
- std::string name() const override {
- return kSystemMetricsCollector;
- }
+std::string SystemMetricsCollector::name() const {
+ return kSystemMetricsCollector;
+}
-private:
- /**
- * Convert any errors we see into BSON for the user to see in the final FTDC document. It is
- * acceptable for the proc parser to fail, but we do not want to shutdown the FTDC loop because
- * of it. We assume that the BSONBuilder is not corrupt on non-OK Status but nothing else with
- * regards to the final document output.
- */
- static void processStatusErrors(Status s, BSONObjBuilder* builder) {
- if (!s.isOK()) {
- builder->append("error", s.toString());
- }
+void SystemMetricsCollector::processStatusErrors(Status s, BSONObjBuilder* builder) {
+ if (!s.isOK()) {
+ builder->append("error", s.toString());
}
-
-private:
- // List of physical disks to collect stats from as string from findPhysicalDisks.
- std::vector<std::string> _disks;
-
- // List of physical disks to collect stats from as StringData to pass to parseProcDiskStatsFile.
- std::vector<StringData> _disksStringData;
-};
-
-void installSystemMetricsCollector(FTDCController* controller) {
- controller->addPeriodicCollector(stdx::make_unique<LinuxSystemMetricsCollector>());
}
-#else
-
-void installSystemMetricsCollector(FTDCController* controller) {}
-
-#endif
-
} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats.h b/src/mongo/db/ftdc/ftdc_system_stats.h
index 4d88b596da2..20d21ef4f39 100644
--- a/src/mongo/db/ftdc/ftdc_system_stats.h
+++ b/src/mongo/db/ftdc/ftdc_system_stats.h
@@ -26,11 +26,37 @@
* then also delete it in the license file.
*/
+#include <string>
+
+#include "mongo/base/status.h"
+#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/ftdc/controller.h"
+#include "mongo/db/ftdc/controller.h"
+
namespace mongo {
class FTDCController;
/**
+ * Base class for system metrics collectors. Sets collector name to a common name all system metrics
+ * collectors to use.
+ */
+class SystemMetricsCollector : public FTDCCollectorInterface {
+public:
+ std::string name() const final;
+
+protected:
+ /**
+ * Convert any errors we see into BSON for the user to see in the final FTDC document. It is
+ * acceptable for the collector to fail, but we do not want to shutdown the FTDC loop because
+ * of it. We assume that the BSONBuilder is not corrupt on non-OK Status but nothing else with
+ * regards to the final document output.
+ */
+ static void processStatusErrors(Status s, BSONObjBuilder* builder);
+};
+
+
+/**
* Install a system metrics collector if it exists as a periodic collector.
*/
void installSystemMetricsCollector(FTDCController* controller);
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_freebsd.cpp b/src/mongo/db/ftdc/ftdc_system_stats_freebsd.cpp
new file mode 100644
index 00000000000..d06092f9ba9
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_freebsd.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ftdc/ftdc_system_stats.h"
+
+namespace mongo {
+
+void installSystemMetricsCollector(FTDCController* controller) {}
+
+} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp b/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp
new file mode 100644
index 00000000000..42fdc1afbc1
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp
@@ -0,0 +1,107 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#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/procparser.h"
+
+namespace mongo {
+
+namespace {
+
+static const std::vector<StringData> kCpuKeys{
+ "btime"_sd, "cpu"_sd, "ctxt"_sd, "processes"_sd, "procs_blocked"_sd, "procs_running"_sd};
+
+// Collect all the memory keys by specifying an empty set.
+static const std::vector<StringData> kMemKeys{};
+
+/**
+ * Collect metrics from the Linux /proc file system.
+ */
+class LinuxSystemMetricsCollector final : public SystemMetricsCollector {
+public:
+ LinuxSystemMetricsCollector() : _disks(procparser::findPhysicalDisks("/sys/block"_sd)) {
+ for (const auto& disk : _disks) {
+ _disksStringData.emplace_back(disk);
+ }
+ }
+
+ void collect(OperationContext* txn, BSONObjBuilder& builder) override {
+ {
+ BSONObjBuilder subObjBuilder(builder.subobjStart("cpu"_sd));
+ processStatusErrors(
+ procparser::parseProcStatFile("/proc/stat"_sd, kCpuKeys, &subObjBuilder),
+ &subObjBuilder);
+ subObjBuilder.doneFast();
+ }
+
+ {
+ BSONObjBuilder subObjBuilder(builder.subobjStart("memory"_sd));
+ processStatusErrors(
+ procparser::parseProcMemInfoFile("/proc/meminfo"_sd, kMemKeys, &subObjBuilder),
+ &subObjBuilder);
+ subObjBuilder.doneFast();
+ }
+
+ // Skip the disks section if we could not find any disks.
+ // This can happen when we do not have permission to /sys/block for instance.
+ if (!_disksStringData.empty()) {
+ BSONObjBuilder subObjBuilder(builder.subobjStart("disks"_sd));
+ processStatusErrors(procparser::parseProcDiskStatsFile(
+ "/proc/diskstats"_sd, _disksStringData, &subObjBuilder),
+ &subObjBuilder);
+ subObjBuilder.doneFast();
+ }
+ }
+
+private:
+ // List of physical disks to collect stats from as string from findPhysicalDisks.
+ std::vector<std::string> _disks;
+
+ // List of physical disks to collect stats from as StringData to pass to parseProcDiskStatsFile.
+ std::vector<StringData> _disksStringData;
+};
+
+} // namespace
+
+void installSystemMetricsCollector(FTDCController* controller) {
+ controller->addPeriodicCollector(stdx::make_unique<LinuxSystemMetricsCollector>());
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_openbsd.cpp b/src/mongo/db/ftdc/ftdc_system_stats_openbsd.cpp
new file mode 100644
index 00000000000..d06092f9ba9
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_openbsd.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ftdc/ftdc_system_stats.h"
+
+namespace mongo {
+
+void installSystemMetricsCollector(FTDCController* controller) {}
+
+} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_osx.cpp b/src/mongo/db/ftdc/ftdc_system_stats_osx.cpp
new file mode 100644
index 00000000000..d06092f9ba9
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_osx.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ftdc/ftdc_system_stats.h"
+
+namespace mongo {
+
+void installSystemMetricsCollector(FTDCController* controller) {}
+
+} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_solaris.cpp b/src/mongo/db/ftdc/ftdc_system_stats_solaris.cpp
new file mode 100644
index 00000000000..d06092f9ba9
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_solaris.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ftdc/ftdc_system_stats.h"
+
+namespace mongo {
+
+void installSystemMetricsCollector(FTDCController* controller) {}
+
+} // namespace mongo
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp
new file mode 100644
index 00000000000..d06092f9ba9
--- /dev/null
+++ b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/ftdc/ftdc_system_stats.h"
+
+namespace mongo {
+
+void installSystemMetricsCollector(FTDCController* controller) {}
+
+} // namespace mongo