26 .help =
"Active io_uring SQEs waiting for kernel pickup",
29 .help =
"In-flight fixed buffers in io_uring pool",
32 .help =
"Active HTTP/2 streams",
35 .help =
"Active HTTP/3 streams",
38 .help =
"Flow-control window health (0-100)",
41 .help =
"Validation error frequency",
44 .help =
"Total HTTP requests handled",
47 .help =
"Request duration sum in nanoseconds",
50 {.name =
"cwist_http_header_overflow_total",
51 .help =
"HTTP/1.1 connections dropped because headers exceeded the read buffer",
54 {.name =
"cwist_h2_headers_dropped_total",
55 .help =
"HTTP/2 header fields dropped due to unresolvable HPACK index",
58 {.name =
"cwist_http_continuation_shed_total",
59 .help =
"Pipelined HTTP/1.1 continuations dropped due to full reactor queue",
62 {.name =
"cwist_tls_handshakes_total",
63 .help =
"TLS handshakes completed (full + resumed)",
66 {.name =
"cwist_tls_handshakes_resumed_total",
67 .help =
"TLS handshakes resumed via session ID or ticket",
70 {.name =
"cwist_tls_connections_active",
71 .help =
"Currently established TLS connections",
74 {.name =
"cwist_tls_handshakes_tls12_total",
75 .help =
"TLS handshakes that negotiated TLS 1.2",
78 {.name =
"cwist_tls_handshakes_tls13_total",
79 .help =
"TLS handshakes that negotiated TLS 1.3",
82 {.name =
"cwist_tls_ciphers_aes128_gcm_total",
83 .help =
"TLS handshakes negotiated with TLS_AES_128_GCM_SHA256",
86 {.name =
"cwist_tls_ciphers_aes256_gcm_total",
87 .help =
"TLS handshakes negotiated with TLS_AES_256_GCM_SHA384",
90 {.name =
"cwist_tls_ciphers_chacha20_total",
91 .help =
"TLS handshakes negotiated with TLS_CHACHA20_POLY1305_SHA256",
94 {.name =
"cwist_tls_ciphers_other_total",
95 .help =
"TLS handshakes negotiated with any other cipher",
118 memcpy(
alloc->metrics, metric_defaults,
sizeof(metric_defaults));
149 static const struct {
270 default:
return "unknown";
303 if (!buf)
return NULL;
316 m->name,
m->help,
m->name, type_str(
m->type),
m->name,
317 (
unsigned long)(raw / 1000), (
unsigned long)(raw % 1000),
m->name,
325 if (required >
cap - len) {
342 m->name,
m->help,
m->name, type_str(
m->type),
m->name,
343 (
unsigned long)(raw / 1000), (
unsigned long)(raw % 1000),
m->name,
378 "text/plain; version=0.0.4; charset=utf-8");
Memory allocation wrappers backed by libttak.
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
Safe string type with helper methods.
cwist_error_t cwist_sstring_assign(cwist_sstring *str, const char *data)
Assign a C string.
@ CWIST_HTTP_INTERNAL_ERROR
cwist_error_t cwist_http_header_add(cwist_http_header_node **head, const char *key, const char *value)
Add a header to the list.
uintmax_t cwist_metric_load(const cwist_metrics_registry_t *reg, cwist_metric_id_t id)
Read the current raw value of a metric.
void cwist_metrics_serve_http(cwist_http_response *res)
HTTP handler that serves the metrics registry as Prometheus text.
void cwist_metrics_reset(cwist_metrics_registry_t *reg)
Reset all metrics in a registry to zero.
void cwist_metric_set(cwist_metrics_registry_t *reg, cwist_metric_id_t id, long double value)
Set a gauge metric to an absolute value.
char * cwist_metrics_render_prometheus(const cwist_metrics_registry_t *reg)
Render the full registry in Prometheus text exposition format.
void cwist_metric_inc(cwist_metrics_registry_t *reg, cwist_metric_id_t id)
Increment a metric's value by one and bump its observation count.
void cwist_metric_observe(cwist_metrics_registry_t *reg, cwist_metric_id_t id, long double value)
Observe a sample for a metric: accumulate sum and bump the count.
void cwist_metric_add(cwist_metrics_registry_t *reg, cwist_metric_id_t id, uintmax_t delta)
Add a delta to a metric's value and bump its observation count.
Production-grade metrics engine for CWIST.
cwist_metrics_registry_t * cwist_metrics_registry(void)
Obtain the global registry, creating it on first call.
@ CWIST_METRIC_REQUESTS_TOTAL
@ CWIST_METRIC_HTTP_HEADER_OVERFLOW
@ CWIST_METRIC_TLS_HANDSHAKES_TLS13
@ CWIST_METRIC_TLS_CIPHERS_CHACHA20
@ CWIST_METRIC_TLS_CIPHERS_AES128_GCM
@ CWIST_METRIC_TLS_HANDSHAKES_TLS12
@ CWIST_METRIC_STREAMS_HTTP3
@ CWIST_METRIC_URING_BUFFERS_ACTIVE
@ CWIST_METRIC_VALIDATION_ERRORS
@ CWIST_METRIC_TLS_CONNECTIONS_ACTIVE
@ CWIST_METRIC_REQUEST_DURATION_NS
@ CWIST_METRIC_H2_HEADERS_DROPPED
@ CWIST_METRIC_FLOW_WINDOW_HEALTH
@ CWIST_METRIC_STREAMS_HTTP2
@ CWIST_METRIC_TLS_CIPHERS_OTHER
@ CWIST_METRIC_TLS_CIPHERS_AES256_GCM
@ CWIST_METRIC_TLS_HANDSHAKES_TOTAL
@ CWIST_METRIC_HTTP_CONTINUATION_SHED
@ CWIST_METRIC_URING_SQES_PENDING
@ CWIST_METRIC_TLS_HANDSHAKES_RESUMED
enum cwist_metric_id cwist_metric_id_t
Pre-defined framework metrics.
struct cwist_metrics_registry cwist_metrics_registry_t
Global metrics registry (singleton, lazy-initialised).
enum cwist_metric_type cwist_metric_type_t
Supported Prometheus metric kinds.
HTTP Protocol Definitions and Helpers.
long cwist_http_continuation_shed_count(void)
HTTPS/TLS wrapper interface.
long cwist_https_tls_ciphers_aes128_gcm_total(void)
Handshakes negotiated with TLS_AES_128_GCM_SHA256.
long cwist_https_tls_handshakes_total(void)
Total TLS handshakes that completed (full + resumed).
long cwist_https_tls_ciphers_other_total(void)
Handshakes negotiated with any other cipher.
long cwist_https_tls_handshakes_tls12_total(void)
Handshakes that negotiated TLS 1.2.
long cwist_https_tls_ciphers_chacha20_total(void)
Handshakes negotiated with TLS_CHACHA20_POLY1305_SHA256.
long cwist_https_tls_handshakes_resumed_total(void)
TLS handshakes completed via session resumption/ticket.
long cwist_https_tls_handshakes_tls13_total(void)
Handshakes that negotiated TLS 1.3.
long cwist_https_tls_connections_active(void)
Currently established TLS connections (wrap minus teardown).
long cwist_https_tls_ciphers_aes256_gcm_total(void)
Handshakes negotiated with TLS_AES_256_GCM_SHA384.
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
cwist_http_status_t status_code
cwist_http_header_node * headers
Single metric definition.