diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/db/ftdc | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/db/ftdc')
| -rw-r--r-- | src/mongo/db/ftdc/SConscript | 1 | ||||
| -rw-r--r-- | src/mongo/db/ftdc/ftdc_system_stats_linux.cpp | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/mongo/db/ftdc/SConscript b/src/mongo/db/ftdc/SConscript index 72a96523195..6a21cf9efdc 100644 --- a/src/mongo/db/ftdc/SConscript +++ b/src/mongo/db/ftdc/SConscript @@ -25,6 +25,7 @@ ftdcEnv.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/bson/bson_validate', '$BUILD_DIR/mongo/bson/util/bson_extract', '$BUILD_DIR/mongo/db/server_options_core', '$BUILD_DIR/mongo/db/service_context', diff --git a/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp b/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp index 121a51e3489..3f13d8bc080 100644 --- a/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp +++ b/src/mongo/db/ftdc/ftdc_system_stats_linux.cpp @@ -33,6 +33,7 @@ #include <memory> #include <string> +#include <sys/resource.h> #include <vector> #include "mongo/base/status.h" @@ -40,6 +41,8 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/ftdc/collector.h" #include "mongo/db/ftdc/controller.h" +#include "mongo/util/errno_util.h" +#include "mongo/util/functional.h" #include "mongo/util/processinfo.h" #include "mongo/util/procparser.h" @@ -181,10 +184,66 @@ private: std::vector<StringData> _disksStringData; }; +class SimpleFunctionCollector final : public FTDCCollectorInterface { +public: + SimpleFunctionCollector(StringData name, + unique_function<void(OperationContext*, BSONObjBuilder&)> collectFn) + : _name(name.toString()), _collectFn(std::move(collectFn)) {} + + void collect(OperationContext* opCtx, BSONObjBuilder& builder) override { + _collectFn(opCtx, builder); + } + + std::string name() const override { + return _name; + } + +private: + std::string _name; + unique_function<void(OperationContext*, BSONObjBuilder&)> _collectFn; +}; + + +void collectUlimit(int resource, StringData resourceName, BSONObjBuilder& builder) { + + struct rlimit rlim; + + BSONObjBuilder subObjBuilder(builder.subobjStart(resourceName)); + + if (!getrlimit(resource, &rlim)) { + subObjBuilder.append("soft", static_cast<int64_t>(rlim.rlim_cur)); + subObjBuilder.append("hard", static_cast<int64_t>(rlim.rlim_max)); + } else { + auto ec = lastSystemError(); + + subObjBuilder.append("error", errorMessage(ec)); + } +} + +void collectUlimits(OperationContext*, BSONObjBuilder& builder) { + collectUlimit(RLIMIT_CPU, "cpuTime_secs"_sd, builder); + collectUlimit(RLIMIT_FSIZE, "fileSize_blocks"_sd, builder); + collectUlimit(RLIMIT_DATA, "dataSegSize_kb"_sd, builder); + collectUlimit(RLIMIT_STACK, "stackSize_kb"_sd, builder); + collectUlimit(RLIMIT_CORE, "coreFileSize_blocks"_sd, builder); + collectUlimit(RLIMIT_RSS, "residentSize_kb"_sd, builder); + collectUlimit(RLIMIT_NOFILE, "fileDescriptors"_sd, builder); + collectUlimit(RLIMIT_AS, "addressSpace_kb"_sd, builder); + collectUlimit(RLIMIT_NPROC, "processes"_sd, builder); + collectUlimit(RLIMIT_MEMLOCK, "memLock_kb"_sd, builder); + collectUlimit(RLIMIT_LOCKS, "fileLocks"_sd, builder); + collectUlimit(RLIMIT_SIGPENDING, "pendingSignals"_sd, builder); +} + } // namespace + void installSystemMetricsCollector(FTDCController* controller) { controller->addPeriodicCollector(std::make_unique<LinuxSystemMetricsCollector>()); + + // Collect ULimits settings on rotation. + controller->addOnRotateCollector( + std::make_unique<SimpleFunctionCollector>("ulimits", collectUlimits)); } } // namespace mongo |
