24 #ifndef SEASTAR_MODULE
28 #include <type_traits>
30 #include <fmt/format.h>
33 #include <seastar/core/sstring.hh>
34 #include <seastar/core/shared_ptr.hh>
36 #include <seastar/core/metrics_types.hh>
37 #include <seastar/util/std-compat.hh>
38 #include <seastar/util/bool_class.hh>
39 #include <seastar/util/modules.hh>
101 SEASTAR_MODULE_EXPORT_BEGIN
136 description(sstring s = sstring()) : _s(std::move(s))
138 const sstring& str()
const {
184 const sstring
key()
const {
226 explicit label(
const sstring& key) : key(key) {
253 SEASTAR_MODULE_EXPORT_END
265 enum class data_type : uint8_t {
273 template <
bool callable,
typename T>
278 template <
typename T>
280 using type = std::invoke_result_t<T>;
283 template <
typename T>
286 static constexpr
bool is_integral = std::is_integral_v<typename real_traits::type>;
287 static constexpr data_type type = is_integral ? data_type::COUNTER : data_type::REAL_COUNTER;
297 std::variant<double, histogram> u;
299 data_type type()
const {
304 return std::get<double>(u);
307 uint64_t ui()
const {
308 auto d = std::get<double>(u);
309 if (d >= 0 && d <=
double(std::numeric_limits<long>::max())) {
313 ulong_conversion_error(d);
319 auto d = std::get<double>(u);
320 if (d >=
double(std::numeric_limits<long>::min()) && d <=
double(std::numeric_limits<long>::max())) {
324 ulong_conversion_error(d);
330 : _type(data_type::GAUGE) {
334 u(std::move(h)), _type(t) {
351 return std::get<histogram>(u);
361 return ((_type == data_type::HISTOGRAM || _type == data_type::SUMMARY) && get_histogram().sample_count == 0) ||
362 ((_type == data_type::COUNTER || _type == data_type::REAL_COUNTER) && d() == 0);
365 static void ulong_conversion_error(
double d);
368 using metric_function = std::function<metric_value()>;
382 std::vector<std::string> aggregate_labels;
383 std::map<sstring, sstring> labels;
395 std::vector<label_instance> labels,
396 std::vector<label> aggregate_labels = {});
412 template<
typename T,
typename = std::enable_if_t<std::is_invocable_v<T>>>
413 metric_function make_function(T val, data_type dt) {
414 return [dt, val = std::move(val)] {
419 template<
typename T,
typename = std::enable_if_t<!std::is_invocable_v<T>>>
420 metric_function make_function(T& val, data_type dt) {
422 return metric_value(val, dt);
427 extern const bool metric_disabled;
429 extern label shard_label;
445 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, labels};
456 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, {}};
466 description d, std::vector<label_instance> labels, T&& val) {
467 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, labels};
480 [[deprecated(
"Use make_counter()")]]
483 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
496 [[deprecated(
"Use make_counter()")]]
499 return make_counter(std::move(name), std::forward<T>(val), std::move(d), {});
512 [[deprecated(
"Use make_counter()")]]
515 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
531 auto type = impl::counter_type_traits<std::remove_reference_t<T>>::type;
532 return {name, {type,
"counter"}, make_function(std::forward<T>(val), type), d, labels};
546 return make_counter(std::move(name), std::forward<T>(val), std::move(d), {});
560 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
570 [[deprecated(
"Use make_counter()")]]
573 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
585 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, labels};
596 description d, std::vector<label_instance> labels, T&& val) {
597 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, labels};
610 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, {}};
622 return {name, {impl::data_type::SUMMARY,
"summary"}, make_function(std::forward<T>(val), impl::data_type::SUMMARY), d, {}};
637 return make_counter(name, std::forward<T>(val), d, labels).set_type(
"total_bytes");
651 return make_gauge(name, std::forward<T>(val), d, labels).set_type(
"bytes");
665 return make_gauge(name, std::forward<T>(val), d, labels).set_type(
"queue_length");
679 return make_counter(name, std::forward<T>(val), d, labels).set_type(
"total_operations");
Human-readable description of a metric/group.
Definition: metrics.hh:134
Definition: metrics.hh:103
Definition: metrics.hh:399
A helper class that used to return metrics value.
Definition: metrics.hh:295
bool is_empty() const noexcept
return true if this metric was never used
Definition: metrics.hh:360
Label a metrics.
Definition: metrics.hh:162
const sstring key() const
returns the label key
Definition: metrics.hh:184
label_instance(const sstring &key, T v)
create a label_instance label instance consists of key and value. The key is an sstring....
Definition: metrics.hh:179
const sstring value() const
returns the label value
Definition: metrics.hh:191
Class that creates label instances.
Definition: metrics.hh:217
instance operator()(T value) const
creating a label instance
Definition: metrics.hh:242
label(const sstring &key)
creating a label key is the label name, it will be the key for all label_instance that will be create...
Definition: metrics.hh:226
const sstring & name() const
returns the label name
Definition: metrics.hh:249
Definition: metrics_registration.hh:67
impl::metric_definition_impl make_queue_length(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={}, instance_id_type=impl::shard())
create a queue_length metric.
Definition: metrics.hh:662
sstring metric_type_def
Definition: metrics.hh:114
sstring metric_name_type
Definition: metrics.hh:115
impl::metric_definition_impl make_total_operations(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={}, instance_id_type=impl::shard())
create a total operation metric.
Definition: metrics.hh:676
sstring instance_id_type
Definition: metrics.hh:116
impl::metric_definition_impl make_total_bytes(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={}, instance_id_type=impl::shard())
create a total_bytes metric.
Definition: metrics.hh:634
impl::metric_definition_impl make_derive(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
Derive are used when a rate is more interesting than the value.
Definition: metrics.hh:481
impl::metric_definition_impl make_current_bytes(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={}, instance_id_type=impl::shard())
create a current_bytes metric.
Definition: metrics.hh:648
impl::metric_definition_impl make_summary(metric_name_type name, description d, T &&val)
create a summary metric.
Definition: metrics.hh:620
impl::metric_definition_impl make_gauge(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
Gauge are a general purpose metric.
Definition: metrics.hh:443
impl::metric_definition_impl make_absolute(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
create an absolute metric.
Definition: metrics.hh:571
impl::metric_definition_impl make_counter(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
create a counter metric
Definition: metrics.hh:529
impl::metric_definition_impl make_histogram(metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
create a histogram metric.
Definition: metrics.hh:583
holds the metric_groups definition needed by class that reports metrics
holds the implementation parts of the metrics layer, do not use directly.
sstring group_name_type
Definition: metrics_registration.hh:64
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Histogram data type.
Definition: metrics_types.hh:54
Definition: metrics.hh:284
Definition: metrics.hh:375
Definition: metrics.hh:370
Definition: metrics.hh:274