blob: 330107e811ce1e6f5971881b3cb19bac21e55976 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "bucket_spaces_stats_provider.h"
#include "distributor_host_info_reporter.h"
#include "min_replica_provider.h"
#include <set>
namespace storage::distributor {
using BucketSpacesStats = BucketSpacesStatsProvider::BucketSpacesStats;
using PerNodeBucketSpacesStats = BucketSpacesStatsProvider::PerNodeBucketSpacesStats;
using Object = vespalib::JsonStream::Object;
using Array = vespalib::JsonStream::Array;
using End = vespalib::JsonStream::End;
DistributorHostInfoReporter::DistributorHostInfoReporter(
MinReplicaProvider& minReplicaProvider,
BucketSpacesStatsProvider& bucketSpacesStatsProvider)
: _minReplicaProvider(minReplicaProvider),
_bucketSpacesStatsProvider(bucketSpacesStatsProvider)
{
}
namespace {
void
writeBucketSpacesStats(vespalib::JsonStream& stream,
const BucketSpacesStats& stats)
{
for (const auto& elem : stats) {
stream << Object() << "name" << elem.first;
if (elem.second.valid()) {
stream << "buckets" << Object()
<< "total" << elem.second.bucketsTotal()
<< "pending" << elem.second.bucketsPending()
<< End();
}
stream << End();
}
}
void
outputStorageNodes(vespalib::JsonStream& output,
const MinReplicaMap & minReplica,
const PerNodeBucketSpacesStats& bucketSpacesStats)
{
std::set<uint16_t> nodes;
for (const auto& element : minReplica) {
nodes.insert(element.first);
}
for (const auto& element : bucketSpacesStats) {
nodes.insert(element.first);
}
for (uint16_t node : nodes) {
output << Object();
{
output << "node-index" << node;
auto minReplicaIt = minReplica.find(node);
if (minReplicaIt != minReplica.end()) {
output << "min-current-replication-factor"
<< minReplicaIt->second;
}
auto bucketSpacesStatsIt = bucketSpacesStats.find(node);
if (bucketSpacesStatsIt != bucketSpacesStats.end()) {
output << "bucket-spaces" << Array();
writeBucketSpacesStats(output, bucketSpacesStatsIt->second);
output << End();
}
}
output << End();
}
}
} // anonymous namespace
void
DistributorHostInfoReporter::report(vespalib::JsonStream& output)
{
auto minReplica = _minReplicaProvider.getMinReplica();
auto bucketSpacesStats = _bucketSpacesStatsProvider.getBucketSpacesStats();
output << "distributor" << Object();
{
output << "storage-nodes" << Array();
outputStorageNodes(output, minReplica, bucketSpacesStats);
output << End();
}
output << End();
}
}
|