GPU Cluster Logging: Kernel Logs, Loki vs ELK, and Measuring Storage Costs
This article details log collection and analysis for GPU clusters, covering kernel Xid errors, NCCL warnings, and CUDA OOM events. It compares Loki (with Grafana Alloy) and ELK (Filebeat + Elasticsearch) architectures, emphasizes collecting both Kubernetes and bare-metal node logs, explains label design pitfalls, and provides a methodology for measuring actual storage costs rather than guessing.
Reading font

Log Sources in GPU Clusters
GPU failures leave traces in logs before metrics alert. Critical logs include kernel NVRM: Xid errors, NCCL WARN from training pods, and CUDA out of memory from inference processes. These logs reside in three places: node journald (kernel ring buffer, systemd units like kubelet, containerd, nvidia-persistenced, dcgm), container stdout/stderr at /var/log/pods/<ns>_<pod>_<uid>/, and optional application files on hostPath or PVC.
Key log types and locations:
Xid : NVRM: Xid (PCI:...): 79 — Kernel log, journald
Kernel OOM : Out of memory: Killed process — Kernel log, journald
NCCL : NCCL WARN, NCCL INFO — Container stdout
CUDA OOM : CUDA out of memory — Container stdout
Fabric Manager : NVSwitch init failure — journald unit log
Two often-missed points:
Kernel logs must be persisted. If journald.conf has Storage=volatile or auto without /var/log/journal directory, logs vanish on reboot. Verify with journalctl --list-boots showing multiple boots.
NCCL defaults to minimal logging. Set NCCL_DEBUG=WARN in production; temporarily raise to INFO for debugging, but measure log volume increase (see Section 7).
Pre-Deployment Read-Only Checks
Confirm cluster context: kubectl config current-context, kubectl cluster-info.
Verify container log paths: ls /var/log/pods and ls -l /var/log/containers (symlinks to pods).
Check Xid visibility: journalctl -k --since "7 days ago" | grep -E 'NVRM: Xid'.
Detect existing collectors:
kubectl get daemonset -A | grep -Ei 'promtail|alloy|filebeat|fluent|vector|otel'to avoid duplicate collection.
Loki Route: Alloy + Loki
4.1 Label Design Determines Performance
Loki indexes only labels; each unique label set creates a stream. High-cardinality labels cause index bloat and many small chunks in object storage. Do not use as labels: pod name, container ID, GPU UUID, PCI address, training step, request/trace IDs, or any parsed log value unless cardinality is low and stable.
Recommended labels (describe log origin only):
cluster : e.g., gpu-prod — Very few values
namespace : e.g., train, infer — Limited, stable
node : e.g., gpu-node-01 — Matches node count, long-lived
source : e.g., kernel, kubelet, pod — Fixed categories
Pod/container names go into structured metadata (requires TSDB index and v13 schema). Verify label cardinality with logcli series '{}' --since=1h --analyze-labels; growing unique values indicate a label to remove.
4.2 Loki Deployment & Retention
Deploy via official Helm chart. Critical retention config (Compactor defaults to no deletion):
compactor:
working_directory: /var/loki/compactor
retention_enabled: true
retention_delete_delay: 2h
delete_request_store: s3
limits_config:
retention_period: 720h
retention_stream:
- selector: '{source="kernel"}'
priority: 1
period: 2160hretention_enabled: truerequired; otherwise Compactor only compacts. delete_request_store must match chunk storage type.
Retention works only with schema_config.period: 24h. retention_delete_delay provides safety window; never set to 0.
Example keeps kernel logs 90 days (Xid correlates with hardware repairs), others 30 days.
Retention changes are not retroactive ; object storage lifecycle must exceed Loki retention.
4.3 Alloy Collection Config (DaemonSet)
Alloy reads journald (kernel + systemd) and /var/log/pods. Key design points in the provided Alloy config: max_age = "12h": limits initial back-read to avoid write-rate limits or timestamp-too-old rejections.
journald permissions: Alloy user must be in adm and systemd-journal groups; mount /var/log/journal, /run/log/journal, /etc/machine-id with read access. Missing permissions cause silent zero-data collection. unit and level as labels: systemd units are finite per node; drop transient units like run-xxxx.scope if they inflate cardinality.
Pod/container moved to structured metadata via stage.structured_metadata and stage.label_drop. field = "spec.nodeName=" + sys.env("NODE_NAME") restricts each Alloy to its own node, avoiding API Server watch explosion.
4.4 Deployment, Canary, Rollback
Validate config locally: alloy fmt config.alloy.
Canary: label 1-2 nodes ( kubectl label node gpu-node-01 logging-canary=true), run full training cycle, verify no duplicate collection and write rates acceptable.
Risks: Alloy CPU/memory contention (set requests/limits), initial back-read spike on Loki.
Rollback: helm rollback or helm uninstall; existing Loki data unaffected. If migrating from Promtail, run briefly in parallel and distinguish via source or job labels.
4.5 Verification
Three LogQL queries must all return data:
{source="journal", transport="kernel"}
{source="journal", unit="kubelet.service"}
{source="pod", namespace="train"}First empty → check journald mounts/permissions; third empty → check /var/log/pods mount and __path__ construction.
ELK Route: Filebeat + Elasticsearch + Kibana
5.1 Elasticsearch Fundamentals
ES indexes every field by default (inverted index), enabling fast arbitrary keyword search at cost of write-time CPU and index size. Cardinality issue appears as mapping explosion — uncontrolled JSON keys grow mapping until index.mapping.total_fields.limit rejects writes. Mitigate with flattened type or disable dynamic mapping. Logstash not required; Filebeat processors + ES ingest pipelines suffice unless complex routing/buffering needed.
5.2 Filebeat Config (DaemonSet)
Uses filestream input for containers (reads /var/log/containers/*.log symlinks, requires prospector.scanner.symlinks: true) and journald input for system logs. Key settings:
Container parser: cri format, add_kubernetes_metadata with node-scoped matcher.
Journald input: seek: since, since: -12h (like Alloy's max_age).
Static fields: cluster: gpu-prod, source: journal.
Credentials via ES_API_KEY env var from Secret, not ConfigMap.
Pod/container names are ordinary keyword fields in ES — no stream cardinality concern; control total field count instead.
5.3 Index Lifecycle Management (ILM)
Use data streams + ILM. Minimal policy: hot phase rolls over at 50 GB or 1 day (per Elastic's shard sizing guidance), delete phase at 30 days. Snapshot to object storage for longer retention. Verify policy via _ilm/policy/gpu-logs before writing.
5.4 Verification
Check indices:
_cat/indices/*gpu*?v&h=index,docs.count,pri.store.size,store.size. In Kibana Discover, three KQL queries must return results:
source : "journal" and message : "NVRM"
kubernetes.namespace : "train"
cluster : "gpu-prod"GPU Key Log Search & Alerting
6.1 Xid Errors
Xid codes from NVIDIA driver (see official Xid doc). Loki: count per node last hour:
sum by (node) (count_over_time({source="journal", transport="kernel"} |= "NVRM: Xid" [1h]))Extract Xid number via regex (creates temporary labels, not indexed):
sum by (node, xid) (count_over_time({source="journal", transport="kernel"} |= "NVRM: Xid" | regexp `Xid \((?P<pci>[^)]+)\): (?P<xid>\d+)` [1h]))ES: use Query DSL with terms aggregation on host.name; for Xid-number aggregation, extract at ingest via grok/dissect pipeline — ES pays parse cost at write, Loki at query.
6.2 NCCL Errors
{source="pod", namespace="train"} |= "NCCL WARN". Filter by pod via structured metadata: | pod =~ "llm-pretrain-.*". Correlate with kernel logs in same Grafana panel (time-aligned) because NCCL timeouts often stem from GPU drops or network issues visible in journald.
6.3 OOM Types
Host memory OOM : Out of memory: Killed process — Kernel
Container cgroup OOM : oom-kill, Pod status OOMKilled — Kernel + kubelet
VRAM OOM : CUDA out of memory — App stdout
Queries: kernel |~ "Out of memory|oom-kill"; pod |~ "CUDA out of memory|OutOfMemoryError" — validate regex against actual framework error samples.
6.4 Alerting Rules
Loki ruler (Prometheus-style, LogQL expr): alert on any Xid in 10m:
groups:
- name: gpu-logs
rules:
- alert: GPUXidErrorInLogs
expr: |
sum by (node) (
count_over_time(
{source="journal", transport="kernel"} |= "NVRM: Xid" [10m]
)
) > 0
for: 0m
labels:
severity: warning
annotations:
summary: "Xid on {{ $labels.node }}"
description: "Check kernel log on this node."> 0alerts on every Xid; observe first, then differentiate by Xid code or suppress known harmless codes.
If DCGM Exporter already provides DCGM_FI_DEV_XID_ERRORS, deduplicate: metrics for alerting, logs for context (or vice versa).
ES: Kibana Alerting with ES query rule, condition hit count > 0.
Measuring Storage Costs (Not Guessing)
7.1 Measure Raw Log Volume
On representative GPU node with running training job, measure daily increment (read-only):
# Container logs
du -sh /var/log/pods
# journald
journalctl --disk-usageBetter: sample directory size over time (script provided) to capture growth rate; discard negative deltas from kubelet log rotation.
7.2 Measure Ingested Storage
During canary, let 1-2 nodes write for days, then read platform metrics:
Loki: loki_distributor_bytes_received_total (verify exact name via /metrics) vs object storage bucket usage → compression ratio.
ES: _cat/indices → pri.store.size (primary) and store.size (with replicas; replica=1 doubles disk).
7.3 Extrapolate to Full Cluster
daily_stored = sum over node types (node_count * measured_daily_stored_per_node)
total_storage = daily_stored * retention_days * safety_factorSeparate training/inference/CPU nodes — volumes differ wildly. safety_factor covers bursts like temporary NCCL_DEBUG=INFO; derive from observed peak/mean ratio during canary.
ES: account for replicas, merge-time temporary space, and disk watermarks ( cluster.routing.allocation.disk.watermark).
Selection Guide
Primary query pattern : Loki — locate by node/namespace first; ELK — full-text search any keyword
Existing stack : Loki — Grafana + Prometheus; ELK — Elastic stack
Storage : Loki — object storage available; ELK — ample block storage
Analysis needs : Loki — counts, grep, simple aggregations; ELK — complex aggregations, field analysis
Specific considerations:
Team already uses Grafana for DCGM metrics → Loki aligns logs and metrics in same panels for GPU troubleshooting.
Need cross-log analysis like "all tasks containing error code X, aggregated by image version" → ES write-time parsing + field aggregation fits better.
Operational burden differs: Loki requires label cardinality discipline + object storage management; ES requires mapping/shard/JVM/heap/disk watermark tuning. Choose what team can operate.
Uncertain? Run both collectors on 2-3 nodes for a week (Section 7 method), compare real storage usage and query experience.
Common Failures & Troubleshooting
9.1 No Kernel Logs in Loki
Node journald persistence (Section 2): journalctl -k shows kernel logs?
Alloy mounts: /var/log/journal, /run/log/journal, /etc/machine-id?
Alloy user permissions: must read journal; insufficient perms = silent no data. max_age too short?
9.2 Loki Stream Limit / Rate Limit
Check limits_config (names/values per version). On rejection errors in Alloy logs: first run logcli series --analyze-labels, find highest-cardinality label, move to structured metadata or drop. Do not just raise limits — pushes problem to storage/query layer.
9.3 Duplicate Logs
Old + new collectors running simultaneously (Section 3 check command).
Collecting both /var/log/containers and /var/log/pods (same files via symlinks).
Position/registry files not migrated during collector switch → re-read from start.
9.4 ES Write Rejections
Field count exceeds index.mapping.total_fields.limit: identify dynamic-field source, use flattened or drop in pipeline.
Field type conflict (same name, different types): fix via index template.
Disk watermark triggered: index set read-only. Expand disk or delete old indices, then clear read-only per docs — don't just clear without fixing capacity.
9.5 Slow Queries
Loki: wide selector like {source="pod"} scans all data. Add namespace, node, narrow time range first.
ES: leading-wildcard on message ( *xxx) bypasses inverted index. Use phrase match or extract field at ingest.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.