Seastar
High performance C++ framework for concurrent servers
Classes | Typedefs | Functions | Variables
seastar::metrics Namespace Reference

Detailed Description

metrics creation and registration

the metrics namespace holds the relevant method and classes to generate metrics.

The metrics layer support registering metrics, that later will be exported via different API protocols.

To be able to support multiple protocols the following simplifications where made:

  1. The id of the metrics is based on the collectd id
  2. A metric could be a single value either a reference or a function

To add metrics definition to class A do the following:

In A header file

class A {
metric_groups _metrics
void setup_metrics();
};
holds the metric_groups definition needed by class that reports metrics

In A source file:

include "core/metrics.hh"
void A::setup_metrics() {
namespace sm = seastar::metrics;
_metrics = sm::create_metric_group();
_metrics->add_group("cache", {sm::make_gauge("bytes", "used", [this] { return _region.occupancy().used_space(); })});
}
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
metrics creation and registration
Definition: estimated_histogram.hh:34

Classes

class  double_registration
 
class  description
 Human-readable description of a metric/group. More...
 
class  label_instance
 Label a metrics. More...
 
class  label
 Class that creates label instances. More...
 
struct  metric_relabeling_result
 result of metric relabeling More...
 
struct  options
 Metrics configuration options. More...
 
class  metric_definition
 
class  metric_group_definition
 
class  metric_groups
 holds the metric definition. More...
 
class  metric_group
 hold a single metric group Initialization is done in the constructor or with a call to add_group More...
 
struct  histogram_bucket
 Histogram bucket type. More...
 
struct  histogram
 Histogram data type. More...
 
class  relabel_config_regex
 a wrapper class around regex with the original expr More...
 
struct  relabel_config
 a relabel_config allows changing metrics labels dynamically More...
 

Typedefs

using metric_type_def = sstring
 
using metric_name_type = sstring
 
using instance_id_type = sstring
 
using skip_when_empty = bool_class< class skip_when_empty_tag >
 
using group_name_type = sstring
 

Functions

template<typename T >
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. More...
 
template<typename T >
impl::metric_definition_impl make_gauge (metric_name_type name, description d, T &&val)
 Gauge are a general purpose metric. More...
 
template<typename T >
impl::metric_definition_impl make_gauge (metric_name_type name, description d, std::vector< label_instance > labels, T &&val)
 Gauge are a general purpose metric. More...
 
template<typename T >
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. More...
 
template<typename T >
impl::metric_definition_impl make_derive (metric_name_type name, description d, T &&val)
 Derive are used when a rate is more interesting than the value. More...
 
template<typename T >
impl::metric_definition_impl make_derive (metric_name_type name, description d, std::vector< label_instance > labels, T &&val)
 Derive are used when a rate is more interesting than the value. More...
 
template<typename T >
impl::metric_definition_impl make_counter (metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
 create a counter metric More...
 
template<typename T >
impl::metric_definition_impl make_counter (metric_name_type name, description d, T &&val)
 create a counter metric More...
 
template<typename T >
impl::metric_definition_impl make_counter (metric_name_type name, description d, std::vector< label_instance > labels, T &&val)
 create a counter metric More...
 
template<typename T >
impl::metric_definition_impl make_absolute (metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
 create an absolute metric. More...
 
template<typename T >
impl::metric_definition_impl make_histogram (metric_name_type name, T &&val, description d=description(), std::vector< label_instance > labels={})
 create a histogram metric. More...
 
template<typename T >
impl::metric_definition_impl make_histogram (metric_name_type name, description d, std::vector< label_instance > labels, T &&val)
 create a histogram metric. More...
 
template<typename T >
impl::metric_definition_impl make_histogram (metric_name_type name, description d, T &&val)
 create a histogram metric. More...
 
template<typename T >
impl::metric_definition_impl make_summary (metric_name_type name, description d, T &&val)
 create a summary metric. More...
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
future configure (const options &opts)
 set the metrics configuration
 
future< metric_relabeling_resultset_relabel_configs (const std::vector< relabel_config > &relabel_configs)
 Perform relabeling and operation on metrics dynamically. More...
 
const std::vector< relabel_config > & get_relabel_configs ()
 
relabel_config::relabel_action relabel_config_action (const std::string &action)
 a helper function to translate a string to relabel_config::relabel_action enum values
 

Variables

const bool metric_disabled
 
label shard_label
 

Class Documentation

◆ seastar::metrics::metric_relabeling_result

struct seastar::metrics::metric_relabeling_result
Class Members
size_t metrics_relabeled_due_to_collision

◆ seastar::metrics::histogram_bucket

struct seastar::metrics::histogram_bucket
Class Members
uint64_t count
double upper_bound

Typedef Documentation

◆ group_name_type

using seastar::metrics::group_name_type = typedef sstring

A group of logically related metrics

Function Documentation

◆ set_relabel_configs()

future<metric_relabeling_result> seastar::metrics::set_relabel_configs ( const std::vector< relabel_config > &  relabel_configs)

Perform relabeling and operation on metrics dynamically.

The function would return true if the changes were applied with no conflict or false, if there was a conflict in the registration.

The general logic follows Prometheus metrics_relabel_config configuration. The relabel rules are applied one after the other. You can add or change a label. you can enable or disable a metric, in that case the metrics will not be reported at all. You can turn on and off the skip_when_empty flag.

Using the Prometheus convention, the metric name is name. Names cannot be changed.

Import notes:

  • The relabeling always starts from the original set of labels the metric was created with.
  • calling with an empty set will remove the relabel config and will return all metrics to their original labels
  • To prevent a situation that calling this function would crash the system. in a situation where a conflicting metrics name are entered, an additional label will be added to the labels with a unique ID.

A few examples: To add a level label with a value 1, to the reactor_utilization metric: std::vector<sm::relabel_config> rl(1); rl[0].source_labels = {"__name__"}; rl[0].target_label = "level"; rl[0].replacement = "1"; rl[0].expr = "reactor_utilization"; set_relabel_configs(rl);

To report only the metrics with the level label equals 1

std::vector<sm::relabel_config> rl(2); rl[0].source_labels = {"__name__"}; rl[0].action = sm::relabel_config::relabel_action::drop;

rl[1].source_labels = {"level"}; rl[1].expr = "1"; rl[1].action = sm::relabel_config::relabel_action::keep; set_relabel_configs(rl);