diff options
author | Medha Potluri <medha.potluri@mongodb.com> | 2019-06-14 11:13:14 -0400 |
---|---|---|
committer | Medha Potluri <medha.potluri@mongodb.com> | 2019-06-21 09:45:15 -0400 |
commit | eab3425cdea51ce0e990e168f772f6999ce5c919 (patch) | |
tree | eaf147680f7a50b755726c8582d85a58149c6c2b /src/mongo/db | |
parent | 874f1e2c64c1500e17c79b86fb61d7777541cf39 (diff) | |
download | mongo-eab3425cdea51ce0e990e168f772f6999ce5c919.tar.gz |
SERVER-41498 Create ReplicationMetrics class
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/repl/SConscript | 15 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_metrics.cpp | 55 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_metrics.h | 60 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_metrics.idl | 18 |
4 files changed, 147 insertions, 1 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index b1b7b1c9cb7..520d3b95ec6 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -1354,3 +1354,18 @@ env.CppUnitTest( 'databases_cloner', ], ) + +env.Library( + target='replication_metrics', + source=[ + 'replication_metrics.cpp', + env.Idlc('replication_metrics.idl')[0], + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/commands/server_status', + '$BUILD_DIR/mongo/db/service_context', + ], +)
\ No newline at end of file diff --git a/src/mongo/db/repl/replication_metrics.cpp b/src/mongo/db/repl/replication_metrics.cpp new file mode 100644 index 00000000000..1c1c4075d68 --- /dev/null +++ b/src/mongo/db/repl/replication_metrics.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * 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 + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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 Server Side 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 "src/mongo/db/repl/replication_metrics.h" + +#include "mongo/db/commands/server_status.h" + +namespace mongo { +namespace repl { + +namespace { +static const auto getReplicationMetrics = ServiceContext::declareDecoration<ReplicationMetrics>(); +} // namespace + +ReplicationMetrics& ReplicationMetrics::get(ServiceContext* svc) { + return getReplicationMetrics(svc); +} + +ReplicationMetrics& ReplicationMetrics::get(OperationContext* opCtx) { + return get(opCtx->getServiceContext()); +} + +class ReplicationMetrics::ElectionMetricsSSS : public ServerStatusSection { +public: + ElectionMetricsSSS() : ServerStatusSection("electionMetrics") {} +} electionMetricsSSS; + +} // namespace repl +} // namespace mongo diff --git a/src/mongo/db/repl/replication_metrics.h b/src/mongo/db/repl/replication_metrics.h new file mode 100644 index 00000000000..7012f4802cf --- /dev/null +++ b/src/mongo/db/repl/replication_metrics.h @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * 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 + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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 Server Side 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. + */ + +#pragma once + +#include "mongo/db/repl/replication_metrics_gen.h" +#include "mongo/db/service_context.h" +#include "mongo/stdx/mutex.h" + +namespace mongo { +namespace repl { + +/** + * A service context decoration that stores metrics related to elections and replication health. + */ +class ReplicationMetrics { +public: + static ReplicationMetrics& get(ServiceContext* svc); + static ReplicationMetrics& get(OperationContext* opCtx); + + ReplicationMetrics(); + ~ReplicationMetrics(); + +private: + class ElectionMetricsSSS; + + mutable stdx::mutex _mutex; + ElectionMetrics _electionMetrics; + ElectionCandidateMetrics _electionCandidateMetrics; + ElectionParticipantMetrics _electionParticipantMetrics; +}; + +} // namespace repl +} // namespace mongo diff --git a/src/mongo/db/repl/replication_metrics.idl b/src/mongo/db/repl/replication_metrics.idl index 043935596a9..566d2ee665b 100644 --- a/src/mongo/db/repl/replication_metrics.idl +++ b/src/mongo/db/repl/replication_metrics.idl @@ -39,10 +39,26 @@ imports: structs: ElectionMetrics: description: "Stores metrics related to all the elections a node has called" + strict: true + fields: + numStepUpsRequested: + description: "Number of elections this node has called due to step up requests" + type: int + ElectionCandidateMetrics: description: "Stores metrics that are specific to the last election in which the node was a candidate" + strict: true + fields: + priorityAtElection: + description: "The node's priority at the time of the election" + type: double ElectionParticipantMetrics: - description: "Stores metrics that are specific to the last election in which the node voted"
\ No newline at end of file + description: "Stores metrics that are specific to the last election in which the node voted" + strict: true + fields: + priorityAtElection: + description: "The node's priority at the time of the election" + type: double |