Skip to content

Telemetry Guide

kubed-io[bot] edited this page Nov 28, 2026 · 3 revisions

Telemetry Guide

This page says what each signal costs a bare kubed-mcp server in CPU and how to lower that cost with today's settings. It also says how to link a server's profiles to their source on GitHub.

What it costs

CPU is in millicores, a thousandth of a CPU, the m a Kubernetes limit is set in. Each figure is the median of 3 runs, with the lowest and highest in brackets. off has no profiles, cpu samples CPU alone, memory samples allocations alone, and both samples both. cpu and memory are the profile_cpu and profile_memory settings.

config idle (millicores) load (millicores) calls per run runs
off 1 (1–1) 24 (23–25) 300 3
cpu 5 (5–5) 24 (21–32) 300 3
memory 2 (2–2) 27 (26–29) 300 3
both 5 (5–6) 29 (28–30) 300 3

Measured with kubed-mcp 0.4.3.dev3 (a development build on 0.4.2, the library unchanged), Python 3.14.10 and pyroscope-io 1.4.0, on a 16-CPU Kubernetes node, pushing to Pyroscope in the same cluster. Each run is a 15 s warm-up, 60 s idle with no client, then 30 s of load at 10 calls a second. The script serves with uvicorn's access log off. A default QuickMCP server writes one access-log line per call, whatever LOG_LEVEL is, so a server that logs each call pays a little more under load. The profiled rows include the reachability check that profiles turn on, every 10 seconds (TEL-19).

What the samplers cost, idle and under load:

  • Idle, CPU sampling is the cost: it takes the server from 1 to 5 millicores, and allocation sampling from 1 to 2.
  • Under load, the two samplers together add about 5 millicores: both measured 29 (28–30) against 24 (23–25) for off. This measurement can't say which of the two costs more under load. memory measured 27 (26–29) and cpu 24 (21–32): the 3 between them is less than cpu's spread, from 21 to 32.

The rows above come from one session, so they compare with each other. A row from another session doesn't compare directly with them: off measured 24 in this session and 28 in another, below.

OpenTelemetry was measured in a session of its own, so its row sits beside that session's off, not the table above. It exported traces and metrics over OTLP/HTTP to a collector in the same cluster, and no logs, the default.

config idle (millicores) load (millicores) calls per run runs
off 1 (1–1) 28 (26–30) 300 3
otel 1 (1–1) 26 (25–32) 300 3

In that session, otel cost no more than off.

What a real server pays

These figures are a floor for a bare server with one tool, not an estimate for a real one. The CPU sampler's cost grows with the server, with more threads and deeper stacks to sample. On one mcp-kb build in production, measured over an hour each way, turning profile_cpu off took it from 27 millicores to 14, a median of 25 to 12. That is about 13 millicores, against 3 on the bare server from both to memory, since mcp-kb kept sampling allocations. Set a limit from your own server's figures.

Lowering it

The cheaper single switch is turning CPU sampling off:

telemetry:
  profile_cpu: false

or TELEMETRY_PROFILE_CPU=false. It gives up CPU flame graphs and keeps allocation profiles. On the bare server it takes idle from 5 millicores to 2, the memory row. On mcp-kb in production it took 27 millicores to 14.

The other switch is profile_memory: false, or TELEMETRY_PROFILE_MEMORY=false. It gives up allocation profiles and keeps CPU flame graphs.

Under load, neither single switch saves much that the bare-server measurement can show. The two samplers together add about 5 millicores over off, and what turning one of them off saves couldn't be told apart from the spread of the runs.

Two further steps:

  • Profiles off. Leave profiles unset. That is the off row: 1 millicore idle, 24 under load.
  • OpenTelemetry alone. Leave profiles unset and set otel: true. Traces and metrics stay, and in its session they cost no more than off.

pyroscope-io's own options

These are pyroscope-io's own configure arguments, measured with the script's --option. None of them is a kubed-mcp setting. The first row is the main run's both, the baseline. Each row after it is both with one option, run in a session of its own, so its comparison with the baseline crosses sessions and the drift between sessions applies.

config idle (millicores) load (millicores) calls per run runs
both 5 (5–6) 29 (28–30) 300 3
both sample_rate=20 3 (2–3) 30 (29–33) 300 3
both upload_interval=60 5 (5–5) 28 (24–34) 300 3
both mem_heap_sample_size=4194304 5 (5–5) 31 (30–31) 300 3

What each trades away, against pyroscope-io's default:

  • sample_rate, default 100: fewer CPU samples a second, so coarser CPU profiles.
  • upload_interval, default 10, which QuickMCP also passes: profiles arrive later and in bigger pushes.
  • mem_heap_sample_size, default 524288 (512 KiB): one allocation sample per that many bytes, so coarser allocation profiles.

Only sample_rate=20 moved anything: idle from 5 to 3. The knob sessions had no off row, but idle didn't drift between the two sessions that had one (1 in each), so 5 to 3 is likely real, though it crosses sessions. None moved the cost under load beyond the drift.

Measuring it again

From a checkout, with the telemetry extra installed (pip install -e .[telemetry]):

TELEMETRY_PROFILES=<pyroscope address> python scripts/profile_cost.py measure --configs off,cpu,memory,both --runs 3
  • It runs on Linux only: it reads each server's CPU time from /proc.
  • It pushes to the Pyroscope it's given, under the service name profile-cost unless OTEL_SERVICE_NAME is set, and never prints the address.
  • The phases default to --warmup 15 --idle 60 --load 30 --rate 10. The run above takes about 25 minutes.
  • --configs otel runs OpenTelemetry as the OTEL_* variables in its environment configure it.
  • --option KEY=VALUE passes one pyroscope-io configure argument to the profiled configurations.

The settings are TEL-2, and what each sampler does is TEL-8, both in the spec's telemetry area.

Source links

With source links, a frame in a Grafana flame graph opens its file at its line on GitHub. That works for the server's own code, kubed-mcp, FastMCP and the standard library (TEL-25, TEL-26). Four steps set it up.

1. Set the build in the image. The image carries the repository and the commit it was built from. Pass the commit as a build argument:

ARG SERVICE_GIT_REF
ENV SERVICE_REPOSITORY=https://github.com/example/server \
    SERVICE_GIT_REF=${SERVICE_GIT_REF}
docker build --build-arg SERVICE_GIT_REF="$(git rev-parse HEAD)" .

Put the ARG in the image's final stage, after its FROM. Declared before FROM, or only in a builder stage, SERVICE_GIT_REF is empty and profiles get no service_git_ref.

2. Write the file in the built image. Commit it at the repository's root:

docker run --rm <image> python -m kubed.mcp.pyroscope --write <distribution> > .pyroscope.yaml

Pyroscope reads it from the repository at service_git_ref, so a file that is only in the image does nothing. <distribution> is the server's own distribution, such as kubed-mcp-kb.

3. Commit it with the change that moves a version. The image built from that change checks clean. Until the file is committed the check fails, which is the point.

4. Check it in CI, in a job after the image builds. The snippet assumes an image job with an image output naming the built image:

source-map:
  needs: image
  runs-on: ubuntu-26.04
  steps:
  - uses: actions/checkout@v7
    with:
      persist-credentials: false
  - name: Check .pyroscope.yaml
    env:
      IMAGE: ${{ needs.image.outputs.image }}
    run: docker run -i --rm "$IMAGE" python -m kubed.mcp.pyroscope --check <distribution> < .pyroscope.yaml

-i is what lets stdin reach the command. --check exits 1 with a diff when the committed file is stale. It exits 2 when it read nothing, which is what a missing -i looks like (TEL-26).

What isn't mapped: other distributions' frames, such as pydantic's or uvicorn's, show no source. A package below src/ in its repository isn't mapped either. Both are in the spec's "Not now". In an image without a venv, site-packages sits inside the standard library's directory. Those frames fall under the standard library's prefix and open a path cpython doesn't have. The refs kubed-mcp, FastMCP and the standard library map to are TEL-27.

On Grafana's side, the Pyroscope datasource needs the GitHub integration's session cookie kept, or every lookup after sign-in fails. That is the deployment's setting, not the server's.

Clone this wiki locally