30#include <fmt/format.h>
32#include <seastar/core/sstring.hh>
33#include <seastar/core/shared_ptr.hh>
35#include <seastar/core/metrics_types.hh>
36#include <seastar/util/std-compat.hh>
37#include <seastar/util/bool_class.hh>
38#include <seastar/util/modules.hh>
100SEASTAR_MODULE_EXPORT_BEGIN
135 description(sstring s = sstring()) : _s(std::move(s))
137 const sstring& str()
const {
183 const sstring
key()
const {
225 explicit label(
const sstring& key) : key(key) {
252SEASTAR_MODULE_EXPORT_END
264enum class data_type : uint8_t {
272template <
bool callable,
typename T>
279 using type = std::invoke_result_t<T>;
285 static constexpr bool is_integral = std::is_integral_v<typename real_traits::type>;
286 static constexpr data_type type = is_integral ? data_type::COUNTER : data_type::REAL_COUNTER;
296 std::variant<double, histogram> u;
298 data_type type()
const {
303 return std::get<double>(u);
306 uint64_t ui()
const {
307 auto d = std::get<double>(u);
308 if (d >= 0 && d <=
double(std::numeric_limits<long>::max())) {
312 ulong_conversion_error(d);
318 auto d = std::get<double>(u);
319 if (d >=
double(std::numeric_limits<long>::min()) && d <=
double(std::numeric_limits<long>::max())) {
323 ulong_conversion_error(d);
329 : _type(data_type::GAUGE) {
333 u(std::move(h)), _type(t) {
350 return std::get<histogram>(u);
360 return ((_type == data_type::HISTOGRAM || _type == data_type::SUMMARY) && get_histogram().sample_count == 0) ||
361 ((_type == data_type::COUNTER || _type == data_type::REAL_COUNTER) && d() == 0);
364 static void ulong_conversion_error(
double d);
367using metric_function = std::function<metric_value()>;
381 std::vector<std::string> aggregate_labels;
382 std::map<sstring, sstring> labels;
394 std::vector<label_instance> labels,
395 std::vector<label> aggregate_labels = {});
411template<
typename T,
typename = std::enable_if_t<std::is_invocable_v<T>>>
412metric_function make_function(T val, data_type dt) {
413 return [dt, val = std::move(val)] {
418template<
typename T,
typename = std::enable_if_t<!std::is_invocable_v<T>>>
419metric_function make_function(T& val, data_type dt) {
421 return metric_value(val, dt);
426extern const bool metric_disabled;
428extern label shard_label;
444 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, labels};
455 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, {}};
465 description d, std::vector<label_instance> labels, T&& val) {
466 return {name, {impl::data_type::GAUGE,
"gauge"}, make_function(std::forward<T>(val), impl::data_type::GAUGE), d, labels};
479[[deprecated(
"Use make_counter()")]]
482 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
495[[deprecated(
"Use make_counter()")]]
498 return make_counter(std::move(name), std::forward<T>(val), std::move(d), {});
511[[deprecated(
"Use make_counter()")]]
514 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
530 auto type = impl::counter_type_traits<std::remove_reference_t<T>>::type;
531 return {name, {type,
"counter"}, make_function(std::forward<T>(val), type), d, labels};
545 return make_counter(std::move(name), std::forward<T>(val), std::move(d), {});
559 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
569[[deprecated(
"Use make_counter()")]]
572 return make_counter(std::move(name), std::forward<T>(val), std::move(d), std::move(labels));
584 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, labels};
595 description d, std::vector<label_instance> labels, T&& val) {
596 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, labels};
609 return {name, {impl::data_type::HISTOGRAM,
"histogram"}, make_function(std::forward<T>(val), impl::data_type::HISTOGRAM), d, {}};
621 return {name, {impl::data_type::SUMMARY,
"summary"}, make_function(std::forward<T>(val), impl::data_type::SUMMARY), d, {}};
636 return make_counter(name, std::forward<T>(val), d, labels).set_type(
"total_bytes");
650 return make_gauge(name, std::forward<T>(val), d, labels).set_type(
"bytes");
664 return make_gauge(name, std::forward<T>(val), d, labels).set_type(
"queue_length");
678 return make_counter(name, std::forward<T>(val), d, labels).set_type(
"total_operations");
Human-readable description of a metric/group.
Definition: metrics.hh:133
Definition: metrics.hh:102
Definition: metrics.hh:398
A helper class that used to return metrics value.
Definition: metrics.hh:294
bool is_empty() const noexcept
return true if this metric was never used
Definition: metrics.hh:359
Label a metrics.
Definition: metrics.hh:161
const sstring key() const
returns the label key
Definition: metrics.hh:183
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:178
const sstring value() const
returns the label value
Definition: metrics.hh:190
Class that creates label instances.
Definition: metrics.hh:216
instance operator()(T value) const
creating a label instance
Definition: metrics.hh:241
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:225
const sstring & name() const
returns the label name
Definition: metrics.hh:248
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:661
sstring metric_type_def
Definition: metrics.hh:113
sstring metric_name_type
Definition: metrics.hh:114
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:675
sstring instance_id_type
Definition: metrics.hh:115
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:633
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:480
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:647
impl::metric_definition_impl make_summary(metric_name_type name, description d, T &&val)
create a summary metric.
Definition: metrics.hh:619
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:442
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:570
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:528
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:582
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:69
Definition: metrics.hh:283
Definition: metrics.hh:374
Definition: metrics.hh:369
Definition: metrics.hh:273