xtcp2 serves gRPC, on a listener configured for it, with three services: one to read and change daemon configuration at runtime, one to stream live TCP records, and one to inspect and administer the embedded link monitor. gRPC server reflection is enabled, so tools like the vendored grpcurl can introspect the API without the .proto files.
For protection defaults, read/admin credential setup, TTL/UDS tradeoffs, and recommended deployments, see the listener security guide. No gRPC listener runs by default; listeners are authenticated by default, and the server and built-in clients do not provide native TLS.
- The server
- ConfigService
- Runtime operator control
- XTCPFlatRecordService
- LinkMonitorService
- The xtcp2ctl control CLI
- The xtcp2client binary
- Using grpcurl
- Access control
- Configuration
- See also
pkg/xtcp/grpc_server.go serves each listener whose classes are grpc-read and/or grpc-admin (listeners), with gRPC health and reflection. A grpc-admin listener registers all three services; a grpc-read listener registers read-only versions whose admin RPCs answer Unimplemented, whatever the credential. The clients' default, and the documented place, is a Unix socket:
xtcp2 -listener name=grpc,serves=grpc-read+grpc-admin,address=/run/xtcp2/grpc.sock,tokenFile=/run/secrets/xtcp2-read,adminTokenFile=/run/secrets/xtcp2-adminEach service has its own implementation file:
pkg/xtcp/grpc_configService.go—ConfigService.pkg/xtcp/grpc_flatRecordService.go—XTCPFlatRecordService.pkg/linkmonitor/linkmonitorgrpc—LinkMonitorService, shared with standalone go-link-monitor;pkg/xtcp/linkmonitor.goembeds it.
Defined in proto/xtcp_config/v1/xtcp_config.proto, this service lets you inspect and modify the running daemon's configuration:
| RPC | Purpose | Disruption | Access |
|---|---|---|---|
Get(GetRequest) → GetResponse |
Return the current XtcpConfig (S3 credentials and listener auth secrets redacted). |
none | read |
SetPollFrequency(SetPollFrequencyRequest) → SetPollFrequencyResponse |
Change the poll frequency + timeout live. | none (hot) | admin |
TriggerPoll(TriggerPollRequest) → TriggerPollResponse |
Trigger a single poll immediately, without changing the cadence. | none (hot) | admin |
TriggerPollBurst(TriggerPollBurstRequest) → TriggerPollBurstResponse |
Schedule count polls spaced interval apart (e.g. a socket snapshot every 10s for a minute). |
none (hot) | admin |
SetS3Upload(SetS3UploadRequest) → SetS3UploadResponse |
Change the s3parquet staleness-flush timer and/or byte cap live. | none (hot) | admin |
SetEnvelopeFlush(SetEnvelopeFlushRequest) → SetEnvelopeFlushResponse |
Change the protobufList envelope flush row and/or byte caps live. | none (hot) | admin |
Set(SetRequest) → SetResponse |
Apply a full new XtcpConfig via a soft restart (see below). |
brief (soft restart) | admin |
Configuration changes are validated with buf.validate CEL constraints declared in the proto (for example, the poll timeout must be shorter than the poll frequency), so invalid updates are rejected at the RPC boundary.
There are two tiers of runtime change, so pick the least disruptive one that does the job:
Hot changes (no restart, no data loss). SetPollFrequency, TriggerPoll, TriggerPollBurst, SetS3Upload, and SetEnvelopeFlush take effect on a running daemon immediately. The burst RPC is the incident tool: "take a socket snapshot every 10s for a minute" is TriggerPollBurst{count: 6, interval: 10s}. The polled records flow to whatever destination is configured (and to any connected PollFlatRecords stream). interval must exceed the daemon's poll_timeout so each poll completes before the next fires; the handler rejects a too-short interval. SetEnvelopeFlush raises or lowers the in-flight protobufList envelope caps (row count and/or uncompressed bytes) that decide when a batch is flushed; a 0 field is left unchanged, and the change applies to the next appended record. Raising the byte cap increases the daemon's peak in-flight memory, so keep it well under the container's memory limit.
Soft restart (Set). Everything else — which record fields are exported, string metadata like tag/location/hostname, the marshaller, the destination — is baked in at startup, so changing it goes through Set, which re-execs the daemon in place. This avoids redeploying the container: same PID, same container, new config carried across a syscall.Exec. The gRPC/metrics/health endpoints blip for a few seconds while it re-initializes and Prometheus counters reset (rate() tolerates resets). Buffered records are flushed before the re-exec, so no data is lost. The profilers (-profile.mode=cpu, the Pyroscope agent) are stopped before it too: a running CPU profile's ITIMER_PROF survives execve, and its SIGPROF would kill the new image before the Go runtime installs a handler.
The intended flow is read → edit → apply:
Getreturns the full running config as JSON (S3 credentials come back blank — they're redacted).- Edit the JSON: flip an
enabledDeserializersentry (e.g. turnbbron temporarily), settagto an incident ticket, changelocation, etc. Setthe edited config. Because empty credential fields are treated as unchanged, the redacted round-trip preserves the daemon's S3 keys.
Exported field groups are controlled by the enabledDeserializers map — each key toggles a whole INET_DIAG attribute group (info = the tcp_info struct, bbr = the BBR fields, plus vegas, cong, meminfo, skmem, dctcp, cgroup, …). Setting a key to false disables that group; the full key list is what the daemon's -deserializers flag accepts. Individual fields within a group are all-or-nothing except for the CSV/TSV csvColumns selector.
Security. Listener authentication can protect the gRPC and Prometheus/health/pprof surfaces with raw bearer tokens or HMAC UTC-minute tokens, optionally split into a read credential and an admin credential (see Access control). Every
ConfigServiceresponse redacts S3 credentials and both listener auth blocks. For local-only operation, combine authentication with a restrictive UDS mode; theuds-securitymicroVM lifecycle test exercises this combination.
Defined in proto/xtcp_flat_record/v1/xtcp_flat_record.proto:
| RPC | Shape | Purpose | Access |
|---|---|---|---|
FlatRecords(FlatRecordsRequest) → stream FlatRecordsResponse |
server streaming | The daemon pushes records to the client as it collects them. | read |
PollFlatRecords(stream PollFlatRecordsRequest) → stream PollFlatRecordsResponse |
bidirectional streaming | The client drives collection on demand, triggering a poll per request. | admin |
Defined in proto/linkmonitor/v1/linkmonitor.proto and implemented once in pkg/linkmonitor/linkmonitorgrpc, so xtcp2 and standalone go-link-monitor serve the same API (design).
| RPC | Purpose | Access |
|---|---|---|
GetStatus |
Health (running, ready, collection healthy, baseline ready), link counts current/expected/delta, baseline time and write errors, last resync, control generations. | read |
ListInterfaces |
Per-device identity, eligibility, checks (speed, width, duplex, RDMA readiness) and transitions; filter by exact names or eligible_only. |
read |
ListCollectors |
Per-device and host collector support, success, freshness, errors and discontinuities. | read |
Rebaseline |
Record the current up-link count as the expected count. reason is required (≤512 bytes); wait (≤60s) blocks until the save completes. |
admin |
Resync |
Run a full link resync now; same shape as Rebaseline. |
admin |
ReviewErrors / AcknowledgeErrors |
Reserved for the error ledger; currently Unimplemented. |
read / admin |
The service is always registered. When the daemon runs without the embedded monitor, every call returns FailedPrecondition ("link monitor disabled"). Every admin call is logged with the RPC, reason, peer and result.
Embedding. -linkMonitor (config link_monitor.enable, field 250, on by default) starts the monitor for the daemon's lifetime, adds its problem summary to xtcp2's /metrics and serves go-link-monitor's detail paths on the Prometheus listener (design). A soft restart re-execs the daemon, so the monitor follows a Set like every other field. The baseline file is locked: an embedded and a standalone monitor must use different files. When the embedded monitor can't use its file (locked, corrupt or over 64 KiB) it is marked down and xtcp2 runs on: GetStatus reports running=false, Rebaseline and Resync return Unavailable, and the detail paths answer 503. SIGUSR1 (systemctl reload xtcp2) rebaselines, like Rebaseline.
| Flag | Environment | Default | Purpose |
|---|---|---|---|
-linkMonitor |
LINK_MONITOR |
true |
Run the embedded link monitor. |
-linkMonitorBaselineFile |
LINK_MONITOR_BASELINE_FILE |
/var/lib/xtcp2/link-monitor-baseline.json |
Baseline file. |
-linkMonitorSettle |
LINK_MONITOR_SETTLE |
30s |
How long link state must hold before the first baseline. |
-linkMonitorLearnDeadline |
LINK_MONITOR_LEARN_DEADLINE |
5m |
If no baseline is learned by then, use the visible up count as a provisional, in-memory one (baseline_provisional 1); 0 waits forever. |
-linkMonitorResync |
LINK_MONITOR_RESYNC |
1h |
Full resync interval. |
-linkMonitorStatsInterval |
LINK_MONITOR_STATS_INTERVAL |
15s |
Statistics collection interval. |
-linkMonitorStatsInclude, -linkMonitorStatsExclude |
LINK_MONITOR_STATS_INCLUDE, LINK_MONITOR_STATS_EXCLUDE |
.*, ^$ |
Interfaces whose statistics are collected. |
-linkMonitorNetstatFields |
LINK_MONITOR_NETSTAT_FIELDS |
.* |
Host protocol fields collected. |
-linkMonitorMaxSpeedExceptions |
LINK_MONITOR_MAX_SPEED_EXCEPTIONS |
— | Comma-separated selectors exempt from the max-speed check. |
-linkMonitorMetricsCoreInclude, -linkMonitorMetricsCoreExclude |
LINK_MONITOR_METRICS_CORE_INCLUDE, LINK_MONITOR_METRICS_CORE_EXCLUDE |
—, — | Anchored metric-name patterns registered on /metrics instead of the summary; an empty include with an exclude means the core set. |
-linkMonitorMetricsAll |
LINK_MONITOR_METRICS_ALL |
false |
Register every link monitor metric on /metrics instead of the summary. |
-linkMonitorCollectionMode |
LINK_MONITOR_COLLECTION_MODE |
on-demand |
poll collects everything each stats interval; on-demand polls errors and state each watch interval and settings each slow interval, and collects the rest when a detail path is scraped. |
-linkMonitorWatchInterval |
LINK_MONITOR_WATCH_INTERVAL |
1m |
On demand: error and state polling interval. |
-linkMonitorSlowInterval |
LINK_MONITOR_SLOW_INTERVAL |
5m |
On demand: settings and RDMA capability polling interval. |
-linkMonitorOnDemandTTL |
LINK_MONITOR_ON_DEMAND_TTL |
15s |
On demand: how long collected detail is reused; 0 collects on every scrape. |
-linkMonitorOnDemandWait |
LINK_MONITOR_ON_DEMAND_WAIT |
5s |
On demand: longest a detail scrape waits for fresh data; must be under 10 s. |
-linkMonitorErrorsWindow |
LINK_MONITOR_ERRORS_WINDOW |
3m |
How long an error increase stays a problem. |
-linkMonitorFlapWindow |
LINK_MONITOR_FLAP_WINDOW |
3m |
How long a flap stays a problem. |
-linkMonitorErrorsClasses |
LINK_MONITOR_ERRORS_CLASSES |
link,rdma |
Error classes that raise problems (link, rdma, drop); set but empty means none. |
-linkMonitorErrorsExclude |
LINK_MONITOR_ERRORS_EXCLUDE |
— | Error counter names never raised. |
-linkMonitorMetricsCategories |
LINK_MONITOR_METRICS_CATEGORIES |
all | Categories served under <promPath>/<category>; set but empty serves none. |
-linkMonitorMetricsInterfacePaths |
LINK_MONITOR_METRICS_INTERFACE_PATHS |
true |
Per-interface paths under each category and the all-metrics path. |
-linkMonitorMetricsAllPath |
LINK_MONITOR_METRICS_ALL_PATH |
/metrics-all |
Full link monitor collector; set but empty disables it. |
-linkMonitorIPPaths |
LINK_MONITOR_IP_PATHS |
false |
Serve the read-only /ip and /i paths; they expose host addresses. |
-linkMonitorIPMaxBytes |
LINK_MONITOR_IP_MAX_BYTES |
33554432 |
Largest /ip response, capped at 1 GiB. |
A link_monitor block in a config file with collection_mode unset keeps the library default, poll; the flags, env vars, OCI images and NixOS module all select on-demand. With the default summary exposure a /metrics scrape never collects. The detail paths refresh only what they serve, reusing data younger than the TTL and waiting at most -linkMonitorOnDemandWait. With -linkMonitorMetricsAll or a core pattern, each /metrics scrape first refreshes the whole monitor.
cmd/xtcp2ctl is the operator control CLI — a thin wrapper over ConfigService for changing a running daemon without redeploying. (Where xtcp2client reads records, xtcp2ctl changes settings.) Everything it does is equally reachable with grpcurl; it just makes the common actions one-liners.
nix build .#xtcp2ctl
alias xtcp2ctl=./result/bin/xtcp2ctl # all commands accept -target / -port
# Inspect the running config (S3 creds redacted)
xtcp2ctl get
# Hot changes — take effect immediately, no restart
xtcp2ctl set-poll-frequency -frequency 30s -timeout 5s
xtcp2ctl trigger-poll
xtcp2ctl poll-burst -count 6 -interval 10s # snapshot every 10s for a minute
xtcp2ctl set-s3 -flush-interval 5s # flush buffered snapshots to S3 promptly
xtcp2ctl set-s3 -threshold-bytes 1048576 # or lower the byte cap
xtcp2ctl set-envelope-flush -threshold-rows 20000 # raise the envelope row cap
xtcp2ctl set-envelope-flush -threshold-bytes 1572864 # or the byte cap (watch memory)Incident workflow — enable BBR detail + tag with a ticket (soft restart):
# 1. capture the current config
xtcp2ctl get > cfg.json
# 2. edit cfg.json: turn bbr on and stamp a tag. enabledDeserializers wraps a
# nested "enabled" map, so the path is .enabledDeserializers.enabled.<key>.
jq '.enabledDeserializers.enabled.bbr = true | .tag = "INC-1234"' cfg.json > cfg.new.json
# 3. apply — daemon soft-restarts in place (same container), gRPC/metrics blip briefly
xtcp2ctl reconfigure -file cfg.new.json
# (reads stdin when -file is "-" or omitted)| Command | Key flags | Tier |
|---|---|---|
get |
none | |
set-poll-frequency |
-frequency, -timeout |
hot |
trigger-poll |
hot | |
poll-burst |
-count, -interval |
hot |
set-s3 |
-flush-interval, -threshold-bytes (at least one) |
hot |
set-envelope-flush |
-threshold-bytes, -threshold-rows (at least one) |
hot |
reconfigure |
-file (- = stdin) |
soft restart |
link status|interfaces|collectors |
-format text|json; interfaces: -name, -eligible-only |
none |
link rebaseline|resync |
-reason (required), -wait |
hot |
link takes the common flags before its subcommand, so the subcommand's own flags stay separate: xtcp2ctl link -unixSocket /run/xtcp2/grpc.sock rebaseline -reason "cabling fixed" -wait 30s. It allows 75s per call, so the 60s maximum -wait fits.
cmd/xtcp2client is the reference client. By default it connects and listens (server-streaming) for records; with -poll it uses the bidirectional PollFlatRecords RPC and triggers a poll every -pollFrequency.
nix build .#xtcp2client
# Listen mode: stream records the daemon collects on its own schedule, from
# /run/xtcp2/grpc.sock
XTCP2_GRPC_AUTH_TOKEN_FILE=/run/secrets/xtcp2-read ./result/bin/xtcp2client
# Over TCP
./result/bin/xtcp2client -network tcp -target 127.0.0.1 -port 8889
# Poll mode: drive collection from the client, as JSON
./result/bin/xtcp2client -poll -pollFrequency 2s -json| Flag | Default | Purpose |
|---|---|---|
-network |
unix |
gRPC transport network: unix or tcp. |
-unixSocket |
/run/xtcp2/grpc.sock |
Socket path when -network unix. |
-target |
localhost |
Target hostname when -network tcp. |
-port |
8889 |
Target gRPC port when -network tcp. |
-poll |
false |
Use PollFlatRecords (client-driven) instead of FlatRecords. |
-pollFrequency |
— | Poll interval in poll mode. |
-workers |
10 |
Concurrent stream workers. |
-json |
false |
JSON output. |
-d |
11 |
Debug verbosity. |
Because reflection is on, the vendored grpcurl (cmd/grpcurl) can list and call methods directly. The examples assume a TCP listener on 127.0.0.1:8889 and a token in $TOKEN (-H "authorization: Bearer $TOKEN", left out below); for the socket, add -unix and give /run/xtcp2/grpc.sock as the address:
grpcurl -plaintext 127.0.0.1:8889 list
grpcurl -plaintext 127.0.0.1:8889 xtcp_config.v1.ConfigService/Get
# Hot changes
grpcurl -plaintext -d '{"poll_frequency":"30s","poll_timeout":"5s"}' \
127.0.0.1:8889 xtcp_config.v1.ConfigService/SetPollFrequency
grpcurl -plaintext -d '{}' 127.0.0.1:8889 xtcp_config.v1.ConfigService/TriggerPoll
grpcurl -plaintext -d '{"count":6,"interval":"10s"}' \
127.0.0.1:8889 xtcp_config.v1.ConfigService/TriggerPollBurst
grpcurl -plaintext -d '{"s3_flush_interval":"5s"}' \
127.0.0.1:8889 xtcp_config.v1.ConfigService/SetS3Upload
grpcurl -plaintext -d '{"envelope_flush_threshold_rows":20000}' \
127.0.0.1:8889 xtcp_config.v1.ConfigService/SetEnvelopeFlush
# Soft restart: Get → edit → Set the whole config
grpcurl -plaintext 127.0.0.1:8889 xtcp_config.v1.ConfigService/Get \
| jq '.config.enabledDeserializers.enabled.bbr = true | .config.tag = "INC-1234"' \
| grpcurl -plaintext -d @ 127.0.0.1:8889 xtcp_config.v1.ConfigService/Setxtcp2ctl (above) wraps these same calls with flag-based ergonomics.
Each RPC carries an access class, declared as the (xtcp_auth.v1.access) method option in the proto (proto/xtcp_auth/v1/xtcp_auth.proto). XTCPFlatRecordService is also ClickHouse's format schema, so its two classes are declared in pkg/xtcp/grpc_access.go instead. A method with no class is treated as admin, and a test fails the build if any registered method lacks an explicit one. Health checking and server reflection are read.
Per listener:
| Configured credentials | Read RPCs, /metrics, health |
Admin RPCs, /debug/pprof/ |
|---|---|---|
| read only | read credential | read credential, on a listener serving only admin classes |
| read + admin | read or admin credential | admin credential only |
none (auth=disabled, UDS or loopback) |
open | refused at startup without an admin credential |
Once an admin credential is configured, the read credential becomes read-only: a valid shared credential presented to an admin RPC gets PermissionDenied (HTTP 403), while a missing or wrong credential gets Unauthenticated (HTTP 401) after the failure jitter. The method table is built once at startup; each call does one map lookup.
A listener's own admin credential is adminTokenFile= / adminHmacKeyFile= (and adminAuth=) in its spec; these are the daemon-wide ones, for listeners without:
| Daemon flag | Environment fallback | Purpose |
|---|---|---|
-listenerAdminAuthMode |
LISTENER_ADMIN_AUTH_MODE |
disabled, raw, or hmac-utc-minute. |
-listenerAdminRawToken |
LISTENER_ADMIN_RAW_TOKEN, LISTENER_ADMIN_RAW_TOKEN_FILE |
Admin raw bearer token; never logged. |
-listenerAdminHMACSharedKey |
LISTENER_ADMIN_HMAC_SHARED_KEY, LISTENER_ADMIN_HMAC_SHARED_KEY_FILE |
Admin HMAC shared key; never logged. |
The admin credential shares the HMAC skew and failure jitter of the shared credential. Prefer the _FILE variables so secrets stay out of process listings.
Clients keep their existing -auth-* flags and XTCP2_GRPC_AUTH_TOKEN[_FILE] / XTCP2_GRPC_HMAC_SHARED_KEY[_FILE] variables for the shared credential. xtcp2ctl and xtcp2client also read XTCP2_GRPC_ADMIN_TOKEN[_FILE] and XTCP2_GRPC_ADMIN_HMAC_SHARED_KEY[_FILE]; when set, they send the admin credential to admin RPCs (every xtcp2ctl command except get and link status|interfaces|collectors, and xtcp2client poll mode) and the shared credential everywhere else.
gRPC listeners are -listener entries (listeners). The -grpcPort, -grpcListenNetwork, -grpcListenAddress, -grpcUnixSocketMode and -grpcUnlinkStaleUnixSocket flags (and GRPC_* variables) are deprecated: they still expand to a listener named grpc, serving grpc-admin under the one credential, or grpc-read+grpc-admin when an admin credential is set.
xtcp2 -listener name=grpc,serves=grpc-read+grpc-admin,address=/run/xtcp2/grpc.sock,mode=0660,tokenFile=/run/secrets/xtcp2-read,adminTokenFile=/run/secrets/xtcp2-admin
xtcp2ctl getxtcp2 creates a missing socket directory 0750; own it so only trusted local users can traverse it.
The configuration protobuf carries the listeners as listeners (field 162), with listener_auth, admin_listener_auth and link_monitor (field 250, see LinkMonitorService); ConfigService.Set refuses a listener set startup would refuse. Secret fields in both auth blocks are redacted from every ConfigService response and preserved by ConfigService.Set when omitted from an update. Enforcement is described in Access control.
- Output formats & destinations — the
XtcpFlatRecord/Envelopeschema the stream carries. - Observability — the other side channels (metrics, profiling).