llama.cpp server-task.cpp to_metrics() - the hand-built counter/gauge tables
Fields
sources/w3m-llamacpp-metrics-handbuilt-typingNotes
server_task_result_metrics::to_metrics() in tools/server/server-task.cpp on master, read 2026-10-04 at line 1532 onward. Two std::vector<metric_item> literals - counters (10 entries) and gauges (5 entries) - then a single add_items lambda emitting '# HELP llamacpp:' + name, '# TYPE llamacpp:' + name + ' ' + type, and the value, with the whole counters vector typed 'counter' and the gauges vector typed 'gauge'. Because the type is attached per-VECTOR, each metric's Prometheus TYPE is unambiguous from the source. A thirteenth series, llamacpp:spec_decode_num_accepted_tokens_per_pos_total{position="N"}, is emitted by hand only when metrics.n_accepted_per_pos is non-empty, i.e. only when speculative decoding has run. Verbatim metric names from the two tables: counters prompt_tokens_total, prompt_tokens_cached_total, prompt_seconds_total, tokens_predicted_total, tokens_predicted_seconds_total, n_decode_total, n_tokens_max, spec_decode_num_draft_tokens_total, spec_decode_num_accepted_tokens_total, spec_decode_num_drafts_total; gauges prompt_tokens_seconds, predicted_tokens_seconds, requests_processing, requests_deferred, n_busy_slots_per_decode.
Cross-references
This record references no other records.