25#include <seastar/util/modules.hh>
26#include <seastar/core/shared_ptr.hh>
27#include <seastar/core/sharded.hh>
29#include <boost/functional/hash.hpp>
45using labels_type = std::map<sstring, sstring>;
46using internalized_labels_ref = lw_shared_ptr<const labels_type>;
55struct hash<
seastar::metrics::impl::labels_type> {
56 using argument_type = seastar::metrics::impl::labels_type;
57 using result_type = ::std::size_t;
58 result_type operator()(argument_type
const& s)
const {
61 boost::hash_combine(h, std::hash<seastar::sstring>{}(i.second));
76struct metric_family_config;
90 size_t metrics_relabeled_due_to_collision;
113 : _group(std::move(group)), _name(
114 std::move(name)), _labels(labels) {
129 return _labels->at(shard_label.
name());
134 const labels_type& labels()
const {
143 sstring full_name()
const;
148 auto as_tuple()
const {
149 return std::tie(group_name(), instance_id(), name(), labels());
165 typedef ::std::size_t result_type;
168 result_type
const h1 ( std::hash<seastar::sstring>{}(s.group_name()) );
169 result_type
const h2 ( std::hash<seastar::sstring>{}(s.instance_id()) );
170 return h1 ^ (h2 << 1);
191 std::vector<std::string> aggregate_labels;
208 explicit internalized_holder(labels_type labels) : _labels(make_lw_shared<labels_type>(std::move(labels))) {
218 const labels_type& labels()
const {
222 size_t has_users()
const {
224 return _labels.use_count() > 1;
229 return lhs.labels() < rhs;
231inline bool operator<(
const labels_type& lhs,
const internalized_holder& rhs) {
232 return lhs < rhs.labels();
234inline bool operator<(
const internalized_holder& lhs,
const internalized_holder& rhs) {
235 return lhs.labels() < rhs.labels();
250 bool is_enabled()
const {
251 return _info.enabled;
254 void set_enabled(
bool b) {
258 _info.should_skip_when_empty = skip;
270 const metric_function& get_function()
const {
276using metric_instances = std::map<internalized_holder, register_ref, std::less<>>;
277using metrics_registration = std::vector<register_ref>;
280 metrics_registration _registration;
293 metric_instances _instances;
296 using iterator = metric_instances::iterator;
297 using const_iterator = metric_instances::const_iterator;
301 metric_family(
const metric_instances& instances) : _instances(instances) {
307 metric_family(metric_instances&& instances) : _instances(std::move(instances)) {
326 iterator find(
const labels_type& l) {
327 return _instances.find(l);
330 const_iterator find(
const labels_type& l)
const {
331 return _instances.find(l);
335 return _instances.begin();
338 const_iterator begin()
const {
339 return _instances.cbegin();
343 return _instances.end();
347 return _instances.empty();
350 iterator erase(const_iterator position) {
351 return _instances.erase(position);
354 const_iterator end()
const {
355 return _instances.cend();
358 uint32_t size()
const {
359 return _instances.size();
364using value_map = std::map<sstring, metric_family>;
383 : _id(std::move(
id)), _should_skip_when_empty(should_skip_when_empty) {
392 const labels_type& labels()
const {
397 return _should_skip_when_empty;
401 return _id.group_name();
409using metric_metadata_fifo = std::deque<metric_series_metadata>;
425 metric_metadata_fifo metrics;
431 : mf(std::move(mf)), metrics(std::move(metrics)) {}
434static_assert(std::is_nothrow_move_assignable_v<metric_family_metadata>);
436using value_vector = std::deque<metric_value>;
437using metric_metadata = std::vector<metric_family_metadata>;
438using metric_values = std::deque<value_vector>;
442 metric_values values;
449using internalized_set = std::set<internalized_holder, std::less<>>;
452 value_map _value_map;
456 std::set<sstring> _labels;
457 std::vector<std::deque<metric_function>> _current_metrics;
458 std::vector<relabel_config> _relabel_configs;
459 std::vector<metric_family_config> _metric_family_configs;
460 internalized_set _internalized_labels;
462 value_map& get_value_map() {
466 const value_map& get_value_map()
const {
472 void remove_registration(
const metric_id&
id);
474 return make_ready_future<>();
476 const config& get_config()
const {
479 void set_config(
const config& c) {
485 std::vector<std::deque<metric_function>>& functions();
487 void update_metrics_if_needed();
493 const std::set<sstring>& get_labels()
const noexcept {
499 const std::vector<relabel_config>& get_relabel_configs()
const noexcept {
500 return _relabel_configs;
502 const std::vector<metric_family_config>& get_metric_family_configs()
const noexcept {
503 return _metric_family_configs;
506 void set_metric_family_configs(
const std::vector<metric_family_config>& metrics_config);
511 void gc_internalized_labels();
515const value_map& get_value_map();
522void unregister_metric(
const metric_id &
id);
599const std::vector<relabel_config>& get_relabel_configs();
618void set_metric_family_configs(
const std::vector<metric_family_config>& metrics_config);
624const std::vector<metric_family_config>& get_metric_family_configs();
Definition: sharded.hh:945
A representation of a possibly not-yet-computed value.
Definition: future.hh:1219
Human-readable description of a metric/group.
Definition: metrics.hh:133
Definition: metrics_api.hh:205
Definition: metrics_api.hh:292
Definition: metrics.hh:398
Definition: metrics_api.hh:279
Definition: metrics_api.hh:108
A helper class that used to return metrics value.
Definition: metrics.hh:294
Definition: metrics_api.hh:241
const sstring & name() const
returns the label name
Definition: metrics.hh:248
Definition: metrics_registration.hh:67
Definition: program-options.hh:293
Definition: shared_ptr.hh:507
sstring metric_type_def
Definition: metrics.hh:113
sstring metric_name_type
Definition: metrics.hh:114
sstring instance_id_type
Definition: metrics.hh:115
header for metrics creation.
std::unique_ptr< metric_groups_def > create_metric_groups()
initialize metric group
holds the implementation parts of the metrics layer, do not use directly.
sstring group_name_type
Definition: metrics_registration.hh:64
future configure(const options &opts)
set the metrics configuration
future< metric_relabeling_result > set_relabel_configs(const std::vector< relabel_config > &relabel_configs)
Perform relabeling and operation on metrics dynamically.
result of metric relabeling
Definition: metrics_api.hh:89
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: metrics_api.hh:445
holds metadata information of a metric family
Definition: metrics_api.hh:186
holds metric metadata
Definition: metrics_api.hh:198
Definition: metrics.hh:369
Definition: metrics_api.hh:440
Metrics configuration options.
Definition: metrics_api.hh:535
program_options::value< std::string > metrics_hostname
The hostname used by the metrics.
Definition: metrics_api.hh:539
a relabel_config allows changing metrics labels dynamically
Definition: relabel_config.hh:101