diff options
author | Andrew Morrow <acm@mongodb.com> | 2017-04-27 14:26:11 -0400 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2017-04-27 19:55:38 -0400 |
commit | 2fac57f28272d900e7926bed481e42b01cc45d00 (patch) | |
tree | 422c7c3a2b7e7a8777c4a47c22d249eaec160365 /src/mongo/db/stats | |
parent | b3b32ae51349a66670f2ef17dc88f43b3ab9b90f (diff) | |
download | mongo-2fac57f28272d900e7926bed481e42b01cc45d00.tar.gz |
SERVER-29000 Remove the miniwebserver and derivatives
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/stats/snapshots.cpp | 124 | ||||
-rw-r--r-- | src/mongo/db/stats/snapshots.h | 116 | ||||
-rw-r--r-- | src/mongo/db/stats/snapshots_webplugins.cpp | 123 |
4 files changed, 0 insertions, 364 deletions
diff --git a/src/mongo/db/stats/SConscript b/src/mongo/db/stats/SConscript index 270cadafe80..2bc9b1c1775 100644 --- a/src/mongo/db/stats/SConscript +++ b/src/mongo/db/stats/SConscript @@ -93,7 +93,6 @@ env.Library( source=[ "latency_server_status_section.cpp", "lock_server_status_section.cpp", - "snapshots.cpp", 'storage_stats.cpp', ], LIBDEPS=[ diff --git a/src/mongo/db/stats/snapshots.cpp b/src/mongo/db/stats/snapshots.cpp deleted file mode 100644 index c5ab5832534..00000000000 --- a/src/mongo/db/stats/snapshots.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// snapshots.cpp - -/** -* Copyright (C) 2008 10gen 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. -*/ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault - -#include "mongo/platform/basic.h" - -#include "mongo/db/stats/snapshots.h" - -#include "mongo/base/static_assert.h" -#include "mongo/db/client.h" -#include "mongo/db/clientcursor.h" -#include "mongo/db/service_context.h" -#include "mongo/util/concurrency/idle_thread_block.h" -#include "mongo/util/exit.h" -#include "mongo/util/log.h" - -/** - handles snapshotting performance metrics and other such things - */ -namespace mongo { - -using std::unique_ptr; -using std::endl; - -void SnapshotData::takeSnapshot() { - _created = curTimeMicros64(); - Top::get(getGlobalServiceContext()).cloneMap(_usage); -} - -SnapshotDelta::SnapshotDelta(const SnapshotData& older, const SnapshotData& newer) - : _older(older), _newer(newer) { - verify(_newer._created > _older._created); - _elapsed = _newer._created - _older._created; -} - -Top::UsageMap SnapshotDelta::collectionUsageDiff() { - verify(_newer._created > _older._created); - Top::UsageMap u; - - for (Top::UsageMap::const_iterator i = _newer._usage.begin(); i != _newer._usage.end(); ++i) { - Top::UsageMap::const_iterator j = _older._usage.find(i->first); - if (j != _older._usage.end()) - u[i->first] = Top::CollectionData(j->second, i->second); - else - u[i->first] = i->second; - } - return u; -} - -Snapshots::Snapshots() : _loc(0), _stored(0) {} - -const SnapshotData* Snapshots::takeSnapshot() { - stdx::lock_guard<stdx::mutex> lk(_lock); - _loc = (_loc + 1) % kNumSnapshots; - _snapshots[_loc].takeSnapshot(); - if (_stored < kNumSnapshots) - _stored++; - return &_snapshots[_loc]; -} - -StatusWith<SnapshotDiff> Snapshots::computeDelta() { - stdx::lock_guard<stdx::mutex> lk(_lock); - - // We need 2 snapshots to calculate a delta - if (_stored < 2) { - return StatusWith<SnapshotDiff>(ErrorCodes::BadValue, "Less than 2 snapshots exist"); - } - - // The following logic depends on there being exactly 2 stored snapshots - MONGO_STATIC_ASSERT(kNumSnapshots == 2); - - // Current and previous napshot alternates between indexes 0 and 1 - int currIdx = _loc; - int prevIdx = _loc > 0 ? 0 : 1; - SnapshotDelta delta(_snapshots[prevIdx], _snapshots[currIdx]); - - return SnapshotDiff(delta.collectionUsageDiff(), delta.elapsed()); -} - -void StatsSnapshotThread::run() { - Client::initThread("statsSnapshot"); - while (!globalInShutdownDeprecated()) { - try { - statsSnapshots.takeSnapshot(); - } catch (std::exception& e) { - log() << "ERROR in SnapshotThread: " << redact(e.what()) << endl; - } - - MONGO_IDLE_THREAD_BLOCK; - sleepsecs(4); - } -} - -Snapshots statsSnapshots; -StatsSnapshotThread statsSnapshotThread; -} diff --git a/src/mongo/db/stats/snapshots.h b/src/mongo/db/stats/snapshots.h deleted file mode 100644 index 5013275265b..00000000000 --- a/src/mongo/db/stats/snapshots.h +++ /dev/null @@ -1,116 +0,0 @@ -// snapshots.h - -/** -* Copyright (C) 2008 10gen 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. -*/ - -#pragma once - -#include "mongo/base/status_with.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/stats/top.h" -#include "mongo/stdx/mutex.h" -#include "mongo/util/background.h" - -/** - handles snapshotting performance metrics and other such things - */ -namespace mongo { - -class StatsSnapshotThread; - -/** - * stores a point in time snapshot - * i.e. all counters at a given time - */ -class SnapshotData { - void takeSnapshot(); - - unsigned long long _created; - Top::UsageMap _usage; - - friend class StatsSnapshotThread; - friend class SnapshotDelta; - friend class Snapshots; -}; - -/** - * contains performance information for a time period - */ -class SnapshotDelta { -public: - SnapshotDelta(const SnapshotData& older, const SnapshotData& newer); - - unsigned long long elapsed() const { - return _elapsed; - } - - Top::UsageMap collectionUsageDiff(); - -private: - const SnapshotData& _older; - const SnapshotData& _newer; - - unsigned long long _elapsed; -}; - -struct SnapshotDiff { - Top::UsageMap usageDiff; - unsigned long long timeElapsed; - - SnapshotDiff() = default; - SnapshotDiff(Top::UsageMap map, unsigned long long elapsed) - : usageDiff(std::move(map)), timeElapsed(elapsed) {} -}; - -class Snapshots { -public: - Snapshots(); - - const SnapshotData* takeSnapshot(); - - StatusWith<SnapshotDiff> computeDelta(); - -private: - stdx::mutex _lock; - static const int kNumSnapshots = 2; - SnapshotData _snapshots[kNumSnapshots]; - int _loc; - int _stored; -}; - -class StatsSnapshotThread : public BackgroundJob { -public: - virtual std::string name() const { - return "statsSnapshot"; - } - void run(); -}; - -extern Snapshots statsSnapshots; -extern StatsSnapshotThread statsSnapshotThread; -} diff --git a/src/mongo/db/stats/snapshots_webplugins.cpp b/src/mongo/db/stats/snapshots_webplugins.cpp deleted file mode 100644 index c45d827ebf3..00000000000 --- a/src/mongo/db/stats/snapshots_webplugins.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/** -* Copyright (C) 2008 10gen 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/dbwebserver.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/stats/snapshots.h" -#include "mongo/util/mongoutils/html.h" - -namespace mongo { -namespace { - -using namespace html; - -using std::fixed; -using std::setprecision; -using std::string; -using std::stringstream; - -class DBTopStatus : public WebStatusPlugin { -public: - DBTopStatus() : WebStatusPlugin("dbtop", 50, "(occurrences|percent of elapsed)") {} - - void display(stringstream& ss, double elapsed, const Top::UsageData& usage) { - ss << "<td>"; - ss << usage.count; - ss << "</td><td>"; - double per = 100 * ((double)usage.time) / elapsed; - if (per == (int)per) - ss << (int)per; - else { - const auto precision = ss.precision(); - const auto flags = ss.flags(); - ss << setprecision(1) << fixed << per; - ss.flags(flags); - ss.precision(precision); - } - ss << '%'; - ss << "</td>"; - } - - void display(stringstream& ss, - double elapsed, - const string& ns, - const Top::CollectionData& data) { - if (ns != "TOTAL" && data.total.count == 0) - return; - ss << "<tr><th>" << html::escape(ns) << "</th>"; - - display(ss, elapsed, data.total); - - display(ss, elapsed, data.readLock); - display(ss, elapsed, data.writeLock); - - display(ss, elapsed, data.queries); - display(ss, elapsed, data.getmore); - display(ss, elapsed, data.insert); - display(ss, elapsed, data.update); - display(ss, elapsed, data.remove); - - ss << "</tr>\n"; - } - - void run(OperationContext* opCtx, stringstream& ss) { - StatusWith<SnapshotDiff> diff = statsSnapshots.computeDelta(); - - if (!diff.isOK()) - return; - - ss << "<table border=1 cellpadding=2 cellspacing=0>"; - ss << "<tr align='left'><th>"; - ss << a("http://dochub.mongodb.org/core/whatisanamespace", "namespace") - << "NS</a></th>" - "<th colspan=2>total</th>" - "<th colspan=2>Reads</th>" - "<th colspan=2>Writes</th>" - "<th colspan=2>Queries</th>" - "<th colspan=2>GetMores</th>" - "<th colspan=2>Inserts</th>" - "<th colspan=2>Updates</th>" - "<th colspan=2>Removes</th>"; - ss << "</tr>\n"; - - const Top::UsageMap& usage = diff.getValue().usageDiff; - unsigned long long elapsed = diff.getValue().timeElapsed; - for (Top::UsageMap::const_iterator i = usage.begin(); i != usage.end(); ++i) { - display(ss, (double)elapsed, i->first, i->second); - } - - ss << "</table>"; - } - - virtual void init() {} -} dbtopStatus; - -} // namespace -} // namespace mongo |