2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUS_PROMETHEUSLOGGERMETRICS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUS_PROMETHEUSLOGGERMETRICS_HPP_INCLUDED
65 return now_ms > last ? now_ms - last : 0;
74 std::vector<PrometheusMetricFamily>& families,
76 const std::string& logger_name,
77 int64_t now_ms = 0)
const {
84 mf.
name = prefix +
"log_records_total";
85 mf.
help =
"Total number of log records processed";
88 s.
name = prefix +
"log_records_total";
92 families.push_back(mf);
98 mf.
name = prefix +
"dropped_logs_total";
99 mf.
help =
"Total number of dropped log records";
102 s.
name = prefix +
"dropped_logs_total";
106 families.push_back(mf);
112 mf.
name = prefix +
"failed_exports_total";
113 mf.
help =
"Total number of failed export attempts";
116 s.
name = prefix +
"failed_exports_total";
120 families.push_back(mf);
126 mf.
name = prefix +
"last_log_timestamp_ms";
127 mf.
help =
"Timestamp of the last log record in milliseconds";
130 s.
name = prefix +
"last_log_timestamp_ms";
134 families.push_back(mf);
140 mf.
name = prefix +
"time_since_last_log_ms";
141 mf.
help =
"Milliseconds since the last log record";
144 s.
name = prefix +
"time_since_last_log_ms";
148 families.push_back(mf);
154 mf.
name = prefix +
"build_info";
155 mf.
help =
"Build information for logit-cpp";
158 s.
name = prefix +
"build_info";
161 s.
labels.push_back({
"version", LOGIT_VERSION});
163 s.
labels.push_back({
"version",
"1.0.2"});
165#if defined(__GNUC__) && !defined(__clang__)
166 s.
labels.push_back({
"compiler",
"gcc"});
167#elif defined(__clang__)
168 s.
labels.push_back({
"compiler",
"clang"});
169#elif defined(_MSC_VER)
170 s.
labels.push_back({
"compiler",
"msvc"});
172 s.
labels.push_back({
"compiler",
"unknown"});
176 families.push_back(mf);
182 const uint64_t max_value =
static_cast<uint64_t
>((std::numeric_limits<int64_t>::max)());
183 return value > max_value ? (std::numeric_limits<int64_t>::max)() :
static_cast<int64_t
>(value);
195 const std::string& logger_name) {
Defines Prometheus text exposition format types and configuration.
Tracks log-record counters and builds built-in Prometheus metric families.
void add_failed_export(uint64_t count=1)
Increment failed export/collect counter.
std::atomic< uint64_t > m_failed_exports
uint64_t dropped_count() const
Total dropped log records.
std::atomic< uint64_t > m_log_records_total
std::atomic< uint64_t > m_dropped
uint64_t log_records_total() const
Total log records processed.
int64_t last_log_ts() const
Last log timestamp (ms).
uint64_t failed_export_count() const
Total failed export/collect attempts.
void add_dropped(uint64_t count=1)
Increment dropped log counter.
static void add_common_labels(PrometheusSample &sample, const PrometheusTextFormatConfig &config, const std::string &logger_name)
static int64_t counter_to_int64(uint64_t value)
Safely convert uint64_t counter to int64_t (clamping on overflow).
int64_t time_since_last_log_ms(int64_t now_ms) const
Milliseconds since last log record (0 if none).
std::atomic< int64_t > m_last_log_ts
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.
void on_log(int64_t timestamp_ms)
Update metrics when a log record is processed.
The primary namespace for the LogIt++ library.
A group of related samples sharing a name, help, and type.
std::vector< PrometheusSample > samples
Samples in this family.
std::string help
HELP text.
std::string name
Metric family name.
PrometheusMetricType type
Metric type.
A single metric sample with optional labels and timestamp.
std::string name
Full metric name (including suffixes).
std::vector< PrometheusLabel > labels
Labels for this sample.
double value
Sample value.
Configuration for Prometheus text exposition format output.
std::string logger_label_name
Name of logger label.
bool include_build_info
Emit logit_build_info metric.
std::string instance_label_value
Value of instance label.
bool include_instance_label
Add instance label to built-in metrics.
std::string instance_label_name
Name of instance label.
bool include_logger_label
Add logger label to built-in metrics.
std::string metric_prefix
Prefix applied to built-in metric names.