Skip to content

server : add Prometheus histogram for request context sizes - #27012

Open
boxcee wants to merge 1 commit into
ggml-org:masterfrom
boxcee:feat/context-size-histogram
Open

boxcee wants to merge 1 commit into
ggml-org:masterfrom
boxcee:feat/context-size-histogram

Conversation

@boxcee

@boxcee boxcee commented Aug 13, 2026 •

Copy link
Copy Markdown

Overview

Adds a standard Prometheus histogram metric llamacpp:request_context_tokens to the /metrics endpoint, recording the distribution of context sizes (in tokens) across completed requests. Closes #27011.

Changes:

  • New --metrics-ctx-buckets B1,B2,... CLI flag to configure bucket boundaries (default: 1024,4096,8192,16384,32768,65536,131072,262144; env: LLAMA_ARG_METRICS_CTX_BUCKETS)
  • Histogram fields and recording logic on server_metrics in server-common.h
  • Prometheus output in server_task_result_metrics::to_metrics(), labeled with model_name and model_alias
  • Only emitted when --metrics is enabled (existing gate)

Example output:

# HELP llamacpp:request_context_tokens Distribution of context sizes (in tokens) across completed requests
# TYPE llamacpp:request_context_tokens histogram
llamacpp:request_context_tokens_bucket{model_name="qwen3",model_alias="qwen3",le="1024"} 3
llamacpp:request_context_tokens_bucket{model_name="qwen3",model_alias="qwen3",le="4096"} 8
...
llamacpp:request_context_tokens_bucket{model_name="qwen3",model_alias="qwen3",le="+Inf"} 17
llamacpp:request_context_tokens_sum{model_name="qwen3",model_alias="qwen3"} 683947
llamacpp:request_context_tokens_count{model_name="qwen3",model_alias="qwen3"} 17

Additional information

Test plan (all verified locally on an RTX 3090 with Muse-Glimmer-30B):

  • Server starts, /metrics returns histogram with correct cumulative buckets
  • Bucket counts increment correctly after requests
  • --metrics-ctx-buckets overrides defaults
  • Labels match --alias / model name
  • No output when --metrics is not set

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Claude Opus 4.6 was used to assist with conflict resolution during rebase onto latest master (upstream refactored server_metrics into server-common.h and Prometheus formatting into to_metrics()). All code was manually reviewed and tested before submission.

@boxcee
boxcee requested review from a team as code owners August 13, 2026 11:49
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Hi @boxcee, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 13, 2026
@github-actions
github-actions Bot marked this pull request as draft August 13, 2026 12:01
@github-actions github-actions Bot added documentation Improvements or additions to documentation server and removed draft PR will be changed to draft by github-actions bot labels Aug 13, 2026
@boxcee
boxcee marked this pull request as ready for review August 15, 2026 07:23
@boxcee
boxcee force-pushed the feat/context-size-histogram branch from 401fc90 to 7aafbd1 Compare September 27, 2026 09:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server : add Prometheus histogram for request context sizes

1 participant