LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
logit::PrometheusLoggerMetrics Class Reference

Tracks log-record counters and builds built-in Prometheus metric families. More...

#include <PrometheusLoggerMetrics.hpp>

Public Member Functions

void on_log (int64_t timestamp_ms)
 Update metrics when a log record is processed.
 
void add_dropped (uint64_t count=1)
 Increment dropped log counter.
 
void add_failed_export (uint64_t count=1)
 Increment failed export/collect counter.
 
uint64_t log_records_total () const
 Total log records processed.
 
uint64_t dropped_count () const
 Total dropped log records.
 
uint64_t failed_export_count () const
 Total failed export/collect attempts.
 
int64_t last_log_ts () const
 Last log timestamp (ms).
 
int64_t time_since_last_log_ms (int64_t now_ms) const
 Milliseconds since last log record (0 if none).
 
void build_builtin_metrics (std::vector< PrometheusMetricFamily > &families, const PrometheusTextFormatConfig &config, const std::string &logger_name, int64_t now_ms=0) const
 Append the six built-in metric families to families.
 

Static Public Member Functions

static int64_t counter_to_int64 (uint64_t value)
 Safely convert uint64_t counter to int64_t (clamping on overflow).
 

Static Private Member Functions

static void add_common_labels (PrometheusSample &sample, const PrometheusTextFormatConfig &config, const std::string &logger_name)
 

Private Attributes

std::atomic< uint64_t > m_log_records_total {0}
 
std::atomic< uint64_t > m_dropped {0}
 
std::atomic< uint64_t > m_failed_exports {0}
 
std::atomic< int64_t > m_last_log_ts {0}
 

Detailed Description

Tracks log-record counters and builds built-in Prometheus metric families.

Definition at line 20 of file PrometheusLoggerMetrics.hpp.

Member Function Documentation

◆ add_common_labels()

static void logit::PrometheusLoggerMetrics::add_common_labels ( PrometheusSample & sample,
const PrometheusTextFormatConfig & config,
const std::string & logger_name )
inlinestaticprivate

Definition at line 192 of file PrometheusLoggerMetrics.hpp.

◆ add_dropped()

void logit::PrometheusLoggerMetrics::add_dropped ( uint64_t count = 1)
inline

Increment dropped log counter.

Definition at line 29 of file PrometheusLoggerMetrics.hpp.

◆ add_failed_export()

void logit::PrometheusLoggerMetrics::add_failed_export ( uint64_t count = 1)
inline

Increment failed export/collect counter.

Definition at line 34 of file PrometheusLoggerMetrics.hpp.

◆ build_builtin_metrics()

void logit::PrometheusLoggerMetrics::build_builtin_metrics ( std::vector< PrometheusMetricFamily > & families,
const PrometheusTextFormatConfig & config,
const std::string & logger_name,
int64_t now_ms = 0 ) const
inline

Append the six built-in metric families to families.

Parameters
familiesDestination vector.
configFormat configuration (prefix, labels, build-info flag).
logger_nameValue for the logger label (e.g. "prometheus_payload").
now_msCurrent wall time in milliseconds (from LOGIT_CURRENT_TIMESTAMP_MS()).

Definition at line 73 of file PrometheusLoggerMetrics.hpp.

◆ counter_to_int64()

static int64_t logit::PrometheusLoggerMetrics::counter_to_int64 ( uint64_t value)
inlinestatic

Safely convert uint64_t counter to int64_t (clamping on overflow).

Definition at line 181 of file PrometheusLoggerMetrics.hpp.

◆ dropped_count()

uint64_t logit::PrometheusLoggerMetrics::dropped_count ( ) const
inline

Total dropped log records.

Definition at line 44 of file PrometheusLoggerMetrics.hpp.

◆ failed_export_count()

uint64_t logit::PrometheusLoggerMetrics::failed_export_count ( ) const
inline

Total failed export/collect attempts.

Definition at line 49 of file PrometheusLoggerMetrics.hpp.

◆ last_log_ts()

int64_t logit::PrometheusLoggerMetrics::last_log_ts ( ) const
inline

Last log timestamp (ms).

Definition at line 54 of file PrometheusLoggerMetrics.hpp.

◆ log_records_total()

uint64_t logit::PrometheusLoggerMetrics::log_records_total ( ) const
inline

Total log records processed.

Definition at line 39 of file PrometheusLoggerMetrics.hpp.

◆ on_log()

void logit::PrometheusLoggerMetrics::on_log ( int64_t timestamp_ms)
inline

Update metrics when a log record is processed.

Definition at line 23 of file PrometheusLoggerMetrics.hpp.

◆ time_since_last_log_ms()

int64_t logit::PrometheusLoggerMetrics::time_since_last_log_ms ( int64_t now_ms) const
inline

Milliseconds since last log record (0 if none).

Parameters
now_msCurrent wall time in milliseconds (from LOGIT_CURRENT_TIMESTAMP_MS()).

Definition at line 60 of file PrometheusLoggerMetrics.hpp.

Member Data Documentation

◆ m_dropped

std::atomic<uint64_t> logit::PrometheusLoggerMetrics::m_dropped {0}
private

Definition at line 188 of file PrometheusLoggerMetrics.hpp.

◆ m_failed_exports

std::atomic<uint64_t> logit::PrometheusLoggerMetrics::m_failed_exports {0}
private

Definition at line 189 of file PrometheusLoggerMetrics.hpp.

◆ m_last_log_ts

std::atomic<int64_t> logit::PrometheusLoggerMetrics::m_last_log_ts {0}
private

Definition at line 190 of file PrometheusLoggerMetrics.hpp.

◆ m_log_records_total

std::atomic<uint64_t> logit::PrometheusLoggerMetrics::m_log_records_total {0}
private

Definition at line 187 of file PrometheusLoggerMetrics.hpp.


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