AnyCollect  1.1.2
AnyCollect::Matcher Class Reference

Class used to represent a matcher, that is a way to convert expressions matches into a metric. More...

#include <Matcher.h>

Collaboration diagram for AnyCollect::Matcher:

Public Member Functions

 Matcher () noexcept
 Construct a new Matcher object. More...
 
 Matcher (const Config::expression::metric &config) noexcept
 Construct a new Matcher object. More...
 
const std::vector< std::string > & name () const noexcept
 Returns the pattern for the name of the metric. More...
 
const std::string & value () const noexcept
 Returns the pattern for the value of the metric. More...
 
const std::string & unit () const noexcept
 Returns the pattern for the unit of the metric. More...
 
const std::map< std::string, std::string > & tags () const noexcept
 Returns the pattern for the tags of the metric. More...
 
bool computeRate () const noexcept
 Returns whether the metric is a rate. More...
 
bool convertToUnitsPerSecond () const noexcept
 Returns whether the metric should be converted to units per second. More...
 
void setName (const std::vector< std::string > &name) noexcept
 Sets the pattern for the name of the metric. More...
 
void setValue (const std::string &value) noexcept
 Sets the pattern for the value of the metric. More...
 
void setUnit (const std::string &unit) noexcept
 Sets the pattern for the unit of the metric. More...
 
void setTags (const std::map< std::string, std::string > &tags) noexcept
 Sets the pattern for the tags of the metric. More...
 
void setComputeRate (bool computeRate) noexcept
 Sets whether the metric is a rate. More...
 
void setConvertToUnitsPerSecond (bool convertToUnitsPerSecond) noexcept
 Sets whether the metric should be converted to units per second. More...
 
std::optional< std::vector< std::string > > getName (const std::cmatch &match, const std::vector< std::string > &pathParts) const noexcept
 Use an expression match to compute the metric's name. More...
 
std::optional< double > getValue (const std::cmatch &match, const std::vector< std::string > &pathParts) const noexcept
 Use an expression match to compute the metric's value. More...
 
std::optional< std::string > getUnit (const std::cmatch &match, const std::vector< std::string > &pathParts) const noexcept
 Use an expression match to compute the metric's unit. More...
 
std::optional< std::map< std::string, std::string > > getTags (const std::cmatch &match, const std::vector< std::string > &pathParts) const noexcept
 Use an expression match to compute the metric's tags. More...
 
std::optional< MetricgetMetric (const std::cmatch &match, const std::vector< std::string > &pathParts) const noexcept
 Use an expression match to compute the metric. More...
 

Static Public Attributes

static constexpr char matchEscapeChar = '\\'
 Escape character. More...
 
static constexpr char matchSubstitutionPrefix = '$'
 Variables prefix character. More...
 
static constexpr std::string_view matchSubstitutionPathPrefix = "path_"sv
 Path part prefix variable string. More...
 

Protected Attributes

std::vector< std::string > name_
 Pattern for the name of the metric. More...
 
std::string value_
 Pattern for the value of the metric. More...
 
std::string unit_
 Pattern for the unit of the metric. More...
 
std::map< std::string, std::string > tags_
 Pattern for the tags of the metric. More...
 
bool computeRate_
 Whether the metric is a rate. More...
 
bool convertToUnitsPerSecond_
 Whether the metric should be converted to units per second. More...
 

Detailed Description

Class used to represent a matcher, that is a way to convert expressions matches into a metric.

Definition at line 40 of file Matcher.h.

Constructor & Destructor Documentation

◆ Matcher() [1/2]

AnyCollect::Matcher::Matcher ( )
noexcept

Construct a new Matcher object.

Definition at line 29 of file Matcher.cc.

◆ Matcher() [2/2]

AnyCollect::Matcher::Matcher ( const Config::expression::metric config)
noexcept

Construct a new Matcher object.

Parameters
configconfiguration to use

Definition at line 31 of file Matcher.cc.

Member Function Documentation

◆ computeRate()

bool AnyCollect::Matcher::computeRate ( ) const
noexcept

Returns whether the metric is a rate.

Definition at line 57 of file Matcher.cc.

◆ convertToUnitsPerSecond()

bool AnyCollect::Matcher::convertToUnitsPerSecond ( ) const
noexcept

Returns whether the metric should be converted to units per second.

Definition at line 61 of file Matcher.cc.

◆ getMetric()

std::optional< Metric > AnyCollect::Matcher::getMetric ( const std::cmatch &  match,
const std::vector< std::string > &  pathParts 
) const
noexcept

Use an expression match to compute the metric.

Parameters
matchexpression match to use
pathPartsparts of the source file's path, if any
Returns
the computed metric, or an empty std::optional if any of its fields couldn't be matched

Definition at line 193 of file Matcher.cc.

◆ getName()

std::optional< std::vector< std::string > > AnyCollect::Matcher::getName ( const std::cmatch &  match,
const std::vector< std::string > &  pathParts 
) const
noexcept

Use an expression match to compute the metric's name.

Parameters
matchexpression match to use
pathPartsparts of the source file's path, if any
Returns
the matched name, or an empty std::optional if it couldn't be matched

Definition at line 152 of file Matcher.cc.

Here is the call graph for this function:

◆ getTags()

std::optional< std::map< std::string, std::string > > AnyCollect::Matcher::getTags ( const std::cmatch &  match,
const std::vector< std::string > &  pathParts 
) const
noexcept

Use an expression match to compute the metric's tags.

Parameters
matchexpression match to use
pathPartsparts of the source file's path, if any
Returns
the matched tags, or an empty std::optional if it couldn't be matched

Definition at line 178 of file Matcher.cc.

Here is the call graph for this function:

◆ getUnit()

std::optional< std::string > AnyCollect::Matcher::getUnit ( const std::cmatch &  match,
const std::vector< std::string > &  pathParts 
) const
noexcept

Use an expression match to compute the metric's unit.

Parameters
matchexpression match to use
pathPartsparts of the source file's path, if any
Returns
the matched unit, or an empty std::optional if it couldn't be matched

Definition at line 172 of file Matcher.cc.

Here is the call graph for this function:

◆ getValue()

std::optional< double > AnyCollect::Matcher::getValue ( const std::cmatch &  match,
const std::vector< std::string > &  pathParts 
) const
noexcept

Use an expression match to compute the metric's value.

Parameters
matchexpression match to use
pathPartsparts of the source file's path, if any
Returns
the matched value, or an empty std::optional if it couldn't be matched

Definition at line 162 of file Matcher.cc.

Here is the call graph for this function:

◆ name()

const std::vector< std::string > & AnyCollect::Matcher::name ( ) const
noexcept

Returns the pattern for the name of the metric.

Definition at line 41 of file Matcher.cc.

◆ setComputeRate()

void AnyCollect::Matcher::setComputeRate ( bool  computeRate)
noexcept

Sets whether the metric is a rate.

Definition at line 82 of file Matcher.cc.

◆ setConvertToUnitsPerSecond()

void AnyCollect::Matcher::setConvertToUnitsPerSecond ( bool  convertToUnitsPerSecond)
noexcept

Sets whether the metric should be converted to units per second.

Definition at line 86 of file Matcher.cc.

◆ setName()

void AnyCollect::Matcher::setName ( const std::vector< std::string > &  name)
noexcept

Sets the pattern for the name of the metric.

Definition at line 66 of file Matcher.cc.

◆ setTags()

void AnyCollect::Matcher::setTags ( const std::map< std::string, std::string > &  tags)
noexcept

Sets the pattern for the tags of the metric.

Definition at line 78 of file Matcher.cc.

◆ setUnit()

void AnyCollect::Matcher::setUnit ( const std::string &  unit)
noexcept

Sets the pattern for the unit of the metric.

Definition at line 74 of file Matcher.cc.

◆ setValue()

void AnyCollect::Matcher::setValue ( const std::string &  value)
noexcept

Sets the pattern for the value of the metric.

Definition at line 70 of file Matcher.cc.

◆ tags()

const std::map< std::string, std::string > & AnyCollect::Matcher::tags ( ) const
noexcept

Returns the pattern for the tags of the metric.

Definition at line 53 of file Matcher.cc.

◆ unit()

const std::string & AnyCollect::Matcher::unit ( ) const
noexcept

Returns the pattern for the unit of the metric.

Definition at line 49 of file Matcher.cc.

◆ value()

const std::string & AnyCollect::Matcher::value ( ) const
noexcept

Returns the pattern for the value of the metric.

Definition at line 45 of file Matcher.cc.

Member Data Documentation

◆ computeRate_

bool AnyCollect::Matcher::computeRate_
protected

Whether the metric is a rate.

Definition at line 51 of file Matcher.h.

◆ convertToUnitsPerSecond_

bool AnyCollect::Matcher::convertToUnitsPerSecond_
protected

Whether the metric should be converted to units per second.

Definition at line 52 of file Matcher.h.

◆ matchEscapeChar

constexpr char AnyCollect::Matcher::matchEscapeChar = '\\'
static

Escape character.

Definition at line 42 of file Matcher.h.

◆ matchSubstitutionPathPrefix

constexpr std::string_view AnyCollect::Matcher::matchSubstitutionPathPrefix = "path_"sv
static

Path part prefix variable string.

Definition at line 44 of file Matcher.h.

◆ matchSubstitutionPrefix

constexpr char AnyCollect::Matcher::matchSubstitutionPrefix = '$'
static

Variables prefix character.

Definition at line 43 of file Matcher.h.

◆ name_

std::vector<std::string> AnyCollect::Matcher::name_
protected

Pattern for the name of the metric.

Definition at line 47 of file Matcher.h.

◆ tags_

std::map<std::string, std::string> AnyCollect::Matcher::tags_
protected

Pattern for the tags of the metric.

Definition at line 50 of file Matcher.h.

◆ unit_

std::string AnyCollect::Matcher::unit_
protected

Pattern for the unit of the metric.

Definition at line 49 of file Matcher.h.

◆ value_

std::string AnyCollect::Matcher::value_
protected

Pattern for the value of the metric.

Definition at line 48 of file Matcher.h.


The documentation for this class was generated from the following files: