Apache Mesos
metrics.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MASTER_ALLOCATOR_MESOS_METRICS_HPP__
18 #define __MASTER_ALLOCATOR_MESOS_METRICS_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <mesos/quota/quota.hpp>
24 
30 
31 #include <process/pid.hpp>
32 
33 #include <stout/hashmap.hpp>
34 
35 namespace mesos {
36 namespace internal {
37 namespace master {
38 namespace allocator {
39 namespace internal {
40 
41 // Forward declarations.
42 class HierarchicalAllocatorProcess;
43 
44 
46 {
47 public:
48  explicit QuotaMetrics(const std::string& suffix_) : suffix(suffix_){};
49  ~QuotaMetrics();
50 
51  template <class Quantities>
52  void update(const std::string& role, const Quantities& quantities);
53 
54 private:
55  const std::string suffix;
56 
58  metrics;
59 };
60 
61 
62 // Collection of metrics for the allocator; these begin
63 // with the following prefix: `allocator/mesos/`.
64 struct Metrics
65 {
66  explicit Metrics(const HierarchicalAllocatorProcess& allocator);
67 
68  ~Metrics();
69 
70  void updateQuota(const std::string& role, const Quota& quota);
71  void updateConsumed(
72  const std::string& role, const ResourceQuantities& consumed);
73 
74  void addRole(const std::string& role);
75  void removeRole(const std::string& role);
76 
78 
79  // Number of dispatch events currently waiting in the allocator process.
81 
82  // TODO(bbannier) This metric is identical to `event_queue_dispatches`, but
83  // uses a name deprecated in 1.0. This metric should be removed after the
84  // deprecation cycle.
86 
87  // Number of times the allocation algorithm has run.
89 
90  // Time spent in the allocation algorithm.
92 
93  // The latency of allocation runs due to the batching of allocation requests.
95 
96  // PullGauges for the total amount of each resource in the cluster.
97  std::vector<process::metrics::PullGauge> resources_total;
98 
99  // PullGauges for the allocated amount of each resource in the cluster.
100  std::vector<process::metrics::PullGauge> resources_offered_or_allocated;
101 
102  // PullGauges for the per-role quota allocation for each resource.
105 
106  // PushGauges for the per-role quota guarantee for each resource.
109 
110  // PushGauges for the per-role quota limit for each resource.
113 
114  // PullGauges for the per-role count of active offer filters.
116 
117 private:
118  // NOTE: Quota metrics should have a suffix in singilar.
119  // (Example of a name: allocator/mesos/quota/roles/roleA/resources/cpu/limit.)
120  QuotaMetrics quotaGuarantees {"/guarantee"};
121  QuotaMetrics quotaLimits {"/limit"};
122  QuotaMetrics quotaConsumed {"/consumed"};
123 };
124 
125 
127 {
129  const FrameworkInfo& _frameworkInfo,
130  const bool _publishPerFrameworkMetrics);
131 
132  ~FrameworkMetrics();
133 
134  void reviveRole(const std::string& role);
135  void suppressRole(const std::string& role);
136 
137  // Since frameworks can update their list of roles,
138  // these methods add/remove per-role metrics.
139  void addSubscribedRole(const std::string& role);
140  void removeSubscribedRole(const std::string& role);
141 
142  // Add or remove per-framework metrics.
143  template <typename T> void addMetric(const T& metric);
144  template <typename T> void removeMetric(const T& metric);
145 
146  const FrameworkInfo frameworkInfo;
147 
149 
150  // Suppresion state metric (boolean 0 or 1) for each role.
152 };
153 
154 } // namespace internal {
155 } // namespace allocator {
156 } // namespace master {
157 } // namespace internal {
158 } // namespace mesos {
159 
160 #endif // __MASTER_ALLOCATOR_MESOS_METRICS_HPP__
const process::PID< HierarchicalAllocatorProcess > allocator
Definition: metrics.hpp:77
std::vector< process::metrics::PullGauge > resources_total
Definition: metrics.hpp:97
process::metrics::Counter allocation_runs
Definition: metrics.hpp:88
hashmap< std::string, hashmap< std::string, process::metrics::PushGauge > > quota_limit
Definition: metrics.hpp:112
std::vector< process::metrics::PullGauge > resources_offered_or_allocated
Definition: metrics.hpp:100
Definition: master.hpp:27
Definition: resource_quantities.hpp:63
process::metrics::Timer< Milliseconds > allocation_run_latency
Definition: metrics.hpp:94
hashmap< std::string, process::metrics::PullGauge > offer_filters_active
Definition: metrics.hpp:115
const bool publishPerFrameworkMetrics
Definition: metrics.hpp:148
const FrameworkInfo frameworkInfo
Definition: metrics.hpp:146
Definition: counter.hpp:26
Definition: hashmap.hpp:38
Definition: pull_gauge.hpp:46
hashmap< std::string, process::metrics::PushGauge > suppressed
Definition: metrics.hpp:151
hashmap< std::string, hashmap< std::string, process::metrics::PullGauge > > quota_allocated
Definition: metrics.hpp:104
Definition: agent.hpp:25
QuotaMetrics(const std::string &suffix_)
Definition: metrics.hpp:48
process::metrics::Timer< Milliseconds > allocation_run
Definition: metrics.hpp:91
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: attributes.hpp:24
process::metrics::PullGauge event_queue_dispatches
Definition: metrics.hpp:80
JSON::Object Metrics()
hashmap< std::string, hashmap< std::string, process::metrics::PushGauge > > quota_guarantee
Definition: metrics.hpp:108
Definition: quota.hpp:27
void update(const std::string &role, const Quantities &quantities)
process::metrics::PullGauge event_queue_dispatches_
Definition: metrics.hpp:85