1 2 /** 3 * Copyright (C) 2018-present MongoDB, Inc. 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the Server Side Public License, version 1, 7 * as published by MongoDB, Inc. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * Server Side Public License for more details. 13 * 14 * You should have received a copy of the Server Side Public License 15 * along with this program. If not, see 16 * <http://www.mongodb.com/licensing/server-side-public-license>. 17 * 18 * As a special exception, the copyright holders give permission to link the 19 * code of portions of this program with the OpenSSL library under certain 20 * conditions as described in each individual source file and distribute 21 * linked combinations including the program with the OpenSSL library. You 22 * must comply with the Server Side Public License in all respects for 23 * all of the code used other than as permitted herein. If you modify file(s) 24 * with this exception, you may extend this exception to your version of the 25 * file(s), but you are not obligated to do so. If you do not wish to do so, 26 * delete this exception statement from your version. If you delete this 27 * exception statement from all source files in the program, then also delete 28 * it in the license file. 29 */ 30 31 #pragma once 32 33 #include <memory> 34 #include <set> 35 #include <string> 36 #include <vector> 37 38 #include "mongo/base/disallow_copying.h" 39 #include "mongo/s/client/shard.h" 40 41 namespace mongo { 42 43 class BSONObj; 44 class OperationContext; 45 template <typename T> 46 class StatusWith; 47 48 /** 49 * This interface serves as means for obtaining data distribution and shard utilization statistics 50 * for the entire sharded cluster. Implementations may choose whatever means necessary to perform 51 * the statistics collection. There should be one instance of this object per service context. 52 */ 53 class ClusterStatistics { 54 MONGO_DISALLOW_COPYING(ClusterStatistics); 55 56 public: 57 /** 58 * Structure, which describes the statistics of a single shard host. 59 */ 60 struct ShardStatistics { 61 public: 62 ShardStatistics(ShardId shardId, 63 uint64_t maxSizeMB, 64 uint64_t currSizeMB, 65 bool isDraining, 66 std::set<std::string> shardTags, 67 std::string mongoVersion); 68 69 /** 70 * Returns true if a shard is not allowed to receive any new chunks because it has reached 71 * the per-shard data size limit. 72 */ 73 bool isSizeMaxed() const; 74 75 /** 76 * Returns BSON representation of this shard's statistics, for reporting purposes. 77 */ 78 BSONObj toBSON() const; 79 80 // The id of the shard for which this statistic applies 81 ShardId shardId; 82 83 // The maximum storage size allowed for the shard. Zero means no maximum specified. 84 uint64_t maxSizeMB{0}; 85 86 // The current storage size of the shard. 87 uint64_t currSizeMB{0}; 88 89 // Whether the shard is in draining mode 90 bool isDraining{false}; 91 92 // Set of tags for the shard 93 std::set<std::string> shardTags; 94 95 // Version of mongod, which runs on this shard's primary 96 std::string mongoVersion; 97 }; 98 99 virtual ~ClusterStatistics(); 100 101 /** 102 * Retrieves a snapshot of the current shard utilization state. The implementation of this 103 * method may block if necessary in order to refresh its state or may return a cached value. 104 */ 105 virtual StatusWith<std::vector<ShardStatistics>> getStats(OperationContext* opCtx) = 0; 106 107 protected: 108 ClusterStatistics(); 109 }; 110 111 } // namespace mongo 112