![]() |
LogIt++
Header-only, macro-first C++ logging library
|
Serves Prometheus metrics via an embedded HTTP server. More...
#include <PrometheusHttpServerLogger.hpp>
Classes | |
| struct | Config |
Public Types | |
| using | HttpServer = SimpleWeb::Server<SimpleWeb::HTTP> |
Public Member Functions | |
| PrometheusHttpServerLogger () | |
| Constructs Prometheus HTTP server logger with default configuration. | |
| PrometheusHttpServerLogger (const Config &config) | |
| Constructs Prometheus HTTP server logger with custom configuration. | |
| ~PrometheusHttpServerLogger () override | |
| PrometheusHttpServerLogger (const PrometheusHttpServerLogger &)=delete | |
| PrometheusHttpServerLogger & | operator= (const PrometheusHttpServerLogger &)=delete |
| void | start () |
| Starts the HTTP server thread. | |
| void | log (const LogRecord &record, const std::string &message) override |
| Updates internal metric counters for a log message. | |
| void | wait () override |
| No-op; server is independently serving metrics. | |
| void | shutdown () override |
| Stops the HTTP server and joins the server thread. | |
| std::string | collect_payload () |
| Collects current metrics and returns serialized Prometheus text payload. | |
| std::string | get_string_param (const LoggerParam ¶m) const override |
| Retrieves a string parameter from the logger. | |
| int64_t | get_int_param (const LoggerParam ¶m) const override |
| Retrieves an integer parameter from the logger. | |
| double | get_float_param (const LoggerParam ¶m) const override |
| Retrieves a floating-point parameter from the logger. | |
| void | set_log_level (LogLevel level) override |
| Sets minimal log level for this logger. | |
| LogLevel | get_log_level () const override |
| Gets minimal log level for this logger. | |
| uint64_t | dropped_count () const |
| Returns number of dropped records. | |
| uint64_t | failed_export_count () const |
| Returns number of failed export attempts. | |
Public Member Functions inherited from logit::ILogger | |
| virtual | ~ILogger ()=default |
| virtual std::vector< std::string > | get_buffered_strings () const |
| Returns buffered formatted messages in chronological order. | |
| virtual std::vector< BufferedLogEntry > | get_buffered_entries () const |
| Returns buffered structured entries in chronological order. | |
| virtual std::vector< LogFileInfo > | list_log_files () const |
| Lists persisted log files owned by this backend. | |
| virtual LogFileReadResult | read_log_file (const std::string &path) const |
| Reads one persisted log file owned by this backend. | |
| virtual std::vector< LogFileReadResult > | read_log_files (const std::vector< std::string > &paths) const |
| Reads several persisted log files owned by this backend. | |
| virtual LogClearResult | clear_logs (const LogClearOptions &options=LogClearOptions()) |
| Clears logger-owned buffered or persisted records when supported. | |
Private Member Functions | |
| void | build_scrape_metrics (std::vector< PrometheusMetricFamily > &families) const |
| void | add_scrape_labels (PrometheusSample &sample) const |
| void | stop () |
Private Attributes | |
| Config | m_config |
| HttpServer | m_server |
| std::thread | m_server_thread |
| std::mutex | m_collect_mutex |
| std::atomic< bool > | m_running = ATOMIC_VAR_INIT(false) |
| PrometheusLoggerMetrics | m_metrics |
| std::atomic< int > | m_log_level = ATOMIC_VAR_INIT(static_cast<int>(LogLevel::LOG_LVL_TRACE)) |
| std::atomic< uint64_t > | m_scrapes_total {0} |
| std::atomic< uint64_t > | m_scrape_errors_total {0} |
| std::atomic< int64_t > | m_last_scrape_timestamp_ms {0} |
| std::atomic< double > | m_last_collect_duration_sec {0.0} |
Serves Prometheus metrics via an embedded HTTP server.
This backend starts a Simple-Web-Server HTTP server and serves Prometheus text exposition format on the configured path (default: /metrics). It tracks the same internal counters and gauges as PrometheusPayloadLogger.
Definition at line 36 of file PrometheusHttpServerLogger.hpp.
| using logit::PrometheusHttpServerLogger::HttpServer = SimpleWeb::Server<SimpleWeb::HTTP> |
Definition at line 38 of file PrometheusHttpServerLogger.hpp.
|
inline |
Constructs Prometheus HTTP server logger with default configuration.
Definition at line 52 of file PrometheusHttpServerLogger.hpp.
|
inlineexplicit |
Constructs Prometheus HTTP server logger with custom configuration.
| config | Server and format configuration. |
Definition at line 56 of file PrometheusHttpServerLogger.hpp.
|
inlineoverride |
Definition at line 104 of file PrometheusHttpServerLogger.hpp.
|
delete |
|
inlineprivate |
Definition at line 309 of file PrometheusHttpServerLogger.hpp.
|
inlineprivate |
Definition at line 249 of file PrometheusHttpServerLogger.hpp.
|
inline |
Collects current metrics and returns serialized Prometheus text payload.
Definition at line 140 of file PrometheusHttpServerLogger.hpp.
|
inline |
Returns number of dropped records.
Definition at line 225 of file PrometheusHttpServerLogger.hpp.
|
inline |
Returns number of failed export attempts.
Definition at line 230 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Retrieves a floating-point parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 196 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Retrieves an integer parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 181 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Gets minimal log level for this logger.
Implements logit::ILogger.
Definition at line 220 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Retrieves a string parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 166 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Updates internal metric counters for a log message.
| record | Structured log record. |
| message | Formatted log message (unused by Prometheus metrics). |
Implements logit::ILogger.
Definition at line 125 of file PrometheusHttpServerLogger.hpp.
|
delete |
|
inlineoverridevirtual |
Sets minimal log level for this logger.
| level | Minimum log level. |
Implements logit::ILogger.
Definition at line 214 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
Stops the HTTP server and joins the server thread.
Implements logit::ILogger.
Definition at line 134 of file PrometheusHttpServerLogger.hpp.
|
inline |
Starts the HTTP server thread.
Definition at line 112 of file PrometheusHttpServerLogger.hpp.
|
inlineprivate |
Definition at line 322 of file PrometheusHttpServerLogger.hpp.
|
inlineoverridevirtual |
No-op; server is independently serving metrics.
Implements logit::ILogger.
Definition at line 131 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 238 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 235 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 247 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 246 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 242 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 240 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 239 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 245 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 244 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 236 of file PrometheusHttpServerLogger.hpp.
|
private |
Definition at line 237 of file PrometheusHttpServerLogger.hpp.