Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::metrics::MetricsBackend Class Referenceabstract

Abstract interface for metrics export backends. More...

#include <metrics_backend.h>

Inheritance diagram for kcenon::thread::metrics::MetricsBackend:
Inheritance graph
Collaboration diagram for kcenon::thread::metrics::MetricsBackend:
Collaboration graph

Public Member Functions

virtual ~MetricsBackend ()=default
 Virtual destructor for proper cleanup.
 
virtual std::string name () const =0
 Get the backend name.
 
virtual std::string export_base (const BaseSnapshot &snapshot) const =0
 Export base metrics snapshot.
 
virtual std::string export_enhanced (const EnhancedSnapshot &snapshot) const =0
 Export enhanced metrics snapshot.
 
virtual void set_prefix (const std::string &prefix)
 Set metric name prefix.
 
const std::string & prefix () const
 Get current metric name prefix.
 
virtual void add_label (const std::string &key, const std::string &value)
 Add a label to all exported metrics.
 
const std::map< std::string, std::string > & labels () const
 Get all configured labels.
 

Protected Member Functions

 MetricsBackend ()=default
 Default constructor.
 

Protected Attributes

std::string prefix_ {"thread_pool"}
 Metric name prefix.
 
std::map< std::string, std::string > labels_
 Labels to attach to all metrics.
 

Detailed Description

Abstract interface for metrics export backends.

This interface defines the contract for exporting metrics to various monitoring systems (Prometheus, JSON, logging, etc.).

Implementation Guidelines

  • Implementations should be thread-safe
  • Export methods should not throw exceptions
  • Use canonical metric naming conventions

Example Implementation

class CustomBackend : public MetricsBackend {
public:
std::string name() const override { return "custom"; }
std::string export_base(const BaseSnapshot& snap) const override {
// Export base metrics in custom format
}
std::string export_enhanced(const EnhancedSnapshot& snap) const override {
// Export enhanced metrics in custom format
}
};
Abstract interface for metrics export backends.
virtual std::string export_base(const BaseSnapshot &snapshot) const =0
Export base metrics snapshot.
virtual std::string name() const =0
Get the backend name.
virtual std::string export_enhanced(const EnhancedSnapshot &snapshot) const =0
Export enhanced metrics snapshot.
Base snapshot structure containing common metric values.
See also
PrometheusBackend
JsonBackend
LoggingBackend

Definition at line 57 of file metrics_backend.h.

Constructor & Destructor Documentation

◆ ~MetricsBackend()

virtual kcenon::thread::metrics::MetricsBackend::~MetricsBackend ( )
virtualdefault

Virtual destructor for proper cleanup.

◆ MetricsBackend()

kcenon::thread::metrics::MetricsBackend::MetricsBackend ( )
protecteddefault

Default constructor.

Member Function Documentation

◆ add_label()

virtual void kcenon::thread::metrics::MetricsBackend::add_label ( const std::string & key,
const std::string & value )
inlinevirtual

Add a label to all exported metrics.

Parameters
keyLabel key.
valueLabel value.

Definition at line 107 of file metrics_backend.h.

107 {
108 labels_[key] = value;
109 }
std::map< std::string, std::string > labels_
Labels to attach to all metrics.

References labels_.

◆ export_base()

virtual std::string kcenon::thread::metrics::MetricsBackend::export_base ( const BaseSnapshot & snapshot) const
nodiscardpure virtual

Export base metrics snapshot.

Parameters
snapshotThe base metrics snapshot to export.
Returns
Formatted string representation.

Implemented in kcenon::thread::metrics::JsonBackend, kcenon::thread::metrics::LoggingBackend, and kcenon::thread::metrics::PrometheusBackend.

◆ export_enhanced()

virtual std::string kcenon::thread::metrics::MetricsBackend::export_enhanced ( const EnhancedSnapshot & snapshot) const
nodiscardpure virtual

Export enhanced metrics snapshot.

Parameters
snapshotThe enhanced metrics snapshot to export.
Returns
Formatted string representation.

Implemented in kcenon::thread::metrics::JsonBackend, kcenon::thread::metrics::LoggingBackend, and kcenon::thread::metrics::PrometheusBackend.

◆ labels()

const std::map< std::string, std::string > & kcenon::thread::metrics::MetricsBackend::labels ( ) const
inlinenodiscard

Get all configured labels.

Returns
Map of label key-value pairs.

Definition at line 115 of file metrics_backend.h.

115 {
116 return labels_;
117 }

References labels_.

Referenced by kcenon::thread::metrics::PrometheusBackend::export_base(), and kcenon::thread::metrics::PrometheusBackend::export_enhanced().

Here is the caller graph for this function:

◆ name()

virtual std::string kcenon::thread::metrics::MetricsBackend::name ( ) const
nodiscardpure virtual

Get the backend name.

Returns
Human-readable backend identifier (e.g., "prometheus", "json").

Implemented in kcenon::thread::metrics::JsonBackend, kcenon::thread::metrics::LoggingBackend, and kcenon::thread::metrics::PrometheusBackend.

◆ prefix()

const std::string & kcenon::thread::metrics::MetricsBackend::prefix ( ) const
inlinenodiscard

Get current metric name prefix.

Returns
Current prefix string.

Definition at line 98 of file metrics_backend.h.

98 {
99 return prefix_;
100 }
std::string prefix_
Metric name prefix.

References prefix_.

Referenced by set_prefix().

Here is the caller graph for this function:

◆ set_prefix()

virtual void kcenon::thread::metrics::MetricsBackend::set_prefix ( const std::string & prefix)
inlinevirtual

Set metric name prefix.

Parameters
prefixPrefix to prepend to all metric names.

Definition at line 90 of file metrics_backend.h.

90 {
92 }
const std::string & prefix() const
Get current metric name prefix.

References prefix(), and prefix_.

Referenced by kcenon::thread::metrics::EnhancedThreadPoolMetrics::to_prometheus().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ labels_

std::map<std::string, std::string> kcenon::thread::metrics::MetricsBackend::labels_
protected

◆ prefix_

std::string kcenon::thread::metrics::MetricsBackend::prefix_ {"thread_pool"}
protected

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