nodemon

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinGPURefreshInterval     = 5 * time.Second
	DefaultGPURefreshInterval = 10 * time.Second
)

Bounds for the GPU snapshot refresh interval. Refreshing faster than DCGM updates (DCGM_EXPORTER_INTERVAL, 5s by default) yields no new data; the upper bound keeps the snapshot fresh enough for the container collector, which polls /container/metrics every ~10s.

View Source
const (
	KindPod         = "Pod"
	KindJob         = "Job"
	KindCronJob     = "CronJob"
	KindRollout     = "Rollout"
	KindDaemonSet   = "DaemonSet"
	KindDeployment  = "Deployment"
	KindStatefulSet = "StatefulSet"
	KindReplicaSet  = "ReplicaSet"
)
View Source
const DefaultScanHandlerTimeout = 2500 * time.Millisecond

DefaultScanHandlerTimeout is the fallback per-request time budget for the scan-heavy handlers (JVM and combined runtime metrics), used when a non-positive timeout is passed to their constructors. It exists to avoid a slow /proc walk or binary version-sniff stalling the HTTP server / readiness probes.

View Source
const SnapshotSchemaVersion = 1

Variables

EnabledMetrics is the set of DCGM metrics to scrape and process.

Functions

func NewContainerMetricsHandler

func NewContainerMetricsHandler(querier MetricsQuerier, log logr.Logger) http.Handler

NewContainerMetricsHandler creates an HTTP handler for GET /container/metrics.

func NewContainerSnapshotHandler added in v0.1.5

func NewContainerSnapshotHandler(
	containers ContainerSnapshotQuerier,
	runtime RuntimeSnapshotQuerier,
	log logr.Logger,
) http.Handler

NewContainerSnapshotHandler serves cache-only container and runtime snapshot responses.

func NewJVMMetricsHandler added in v0.0.78

func NewJVMMetricsHandler(querier JVMMetricsQuerier, log logr.Logger, timeout time.Duration) http.Handler

NewJVMMetricsHandler creates an HTTP handler for GET /container/jvm-metrics. Supports ?container=, ?pod=, ?namespace=, ?node= query filters. timeout bounds how long a single request may take before returning whatever partial data is available; a non-positive value falls back to DefaultScanHandlerTimeout.

func NewNodeMetricsHandler added in v0.0.82

func NewNodeMetricsHandler(querier UnifiedQuerier, log logr.Logger) http.Handler

NewNodeMetricsHandler creates an HTTP handler for GET /node/metrics.

func NewNodeSnapshotHandler added in v0.1.5

func NewNodeSnapshotHandler(
	node NodeSnapshotQuerier,
	gpu GPUSnapshotQuerier,
	log logr.Logger,
) http.Handler

NewNodeSnapshotHandler serves cache-only node and GPU snapshot responses.

func NewPVCMetricsHandler added in v0.0.82

func NewPVCMetricsHandler(querier UnifiedQuerier, log logr.Logger) http.Handler

NewPVCMetricsHandler creates an HTTP handler for GET /pvc/metrics. Supports query parameter: namespace.

func NewRuntimeMetricsHandler added in v0.0.97

func NewRuntimeMetricsHandler(querier RuntimeMetricsQuerier, log logr.Logger, timeout time.Duration) http.Handler

NewRuntimeMetricsHandler creates an HTTP handler for GET /container/runtime-metrics, the combined JVM + Node.js endpoint backed by a single /proc walk. Supports the same ?container=, ?pod=, ?namespace=, ?node= query filters as the legacy /container/jvm-metrics endpoint, applied to both slices. timeout bounds how long a single request may take; a non-positive value falls back to DefaultScanHandlerTimeout.

func NewServerMux

func NewServerMux(containerMetricsHandler http.Handler, jvmMetricsHandler http.Handler, runtimeMetricsHandler http.Handler) *http.ServeMux

NewServerMux creates the HTTP mux for the nodemon.

func NewUnifiedContainerHandler added in v0.0.82

func NewUnifiedContainerHandler(querier UnifiedQuerier, log logr.Logger) http.Handler

NewUnifiedContainerHandler creates an HTTP handler for GET /v2/container/metrics. Supports query parameters: namespace, pod, container.

func ParseJVMFlagsWithSources added in v0.0.78

func ParseJVMFlagsWithSources(cmdline string, envJavaOpts map[string]string) (JVMFlagsExtracted, JVMFlagSources, string)

ParseJVMFlagsWithSources extracts sizing-related JVM flags and also returns where each value came from.

We cannot observe the final JVM argument list directly (env-injected options don’t appear in /proc/<pid>/cmdline), so this is best-effort:

  • cmdline is treated as highest precedence
  • env vars are applied in the following precedence order: JDK_JAVA_OPTIONS, JAVA_TOOL_OPTIONS, JAVA_OPTS (matching real JVM last-occurrence-wins semantics — see the comment at the application loop)

The returned effectiveCmdline is the cmdline plus the env options appended as tokens for observability.

Types

type CAdvisorContainerMetrics added in v0.0.82

type CAdvisorContainerMetrics struct {
	Namespace string
	Pod       string
	Container string

	// Network rates (per second)
	NetworkRxPacketsPerSec float64
	NetworkTxPacketsPerSec float64
	NetworkRxErrorsPerSec  float64
	NetworkTxErrorsPerSec  float64
	NetworkRxDropsPerSec   float64
	NetworkTxDropsPerSec   float64

	// Disk I/O rates (per second)
	DiskReadBytesPerSec  float64
	DiskWriteBytesPerSec float64
	DiskReadOpsPerSec    float64
	DiskWriteOpsPerSec   float64

	// CPU throttle (ratio 0-1)
	CPUThrottleFraction float64

	// Memory gauges carried through directly from cAdvisor (not rates).
	// container_memory_cache is page cache; container_memory_swap is swapped-out
	// (non-resident) memory. Both are absent from the kubelet stats/summary API.
	MemoryCacheBytes uint64
	MemorySwapBytes  uint64
}

CAdvisorContainerMetrics holds rate-computed metrics from cAdvisor for a single container.

type CAdvisorScraper added in v0.0.82

type CAdvisorScraper struct {
	// contains filtered or unexported fields
}

CAdvisorScraper fetches the kubelet /metrics/cadvisor endpoint and computes per-second rates for CPU throttle, disk I/O, and network counters.

func NewCAdvisorScraper added in v0.0.82

func NewCAdvisorScraper(baseURL string, httpClient HTTPClient, log logr.Logger) *CAdvisorScraper

NewCAdvisorScraper constructs a CAdvisorScraper that will scrape baseURL + "/metrics/cadvisor".

func (*CAdvisorScraper) Scrape added in v0.0.82

Scrape fetches cAdvisor metrics, computes rates, and returns per-container results. The first call returns an empty slice because no baseline has been established for rate computation yet.

type CPUStats added in v0.0.82

type CPUStats struct {
	Time                 time.Time `json:"time"`
	UsageNanoCores       *uint64   `json:"usageNanoCores"`
	UsageCoreNanoSeconds *uint64   `json:"usageCoreNanoSeconds"`
}

CPUStats holds CPU usage metrics. Pointer fields are omitted by kubelet when unavailable.

type CachedGPUExporter added in v0.1.5

type CachedGPUExporter struct {
	// contains filtered or unexported fields
}

CachedGPUExporter wraps a MetricsQuerier (the DCGM-scraping *Exporter) with a single periodically-refreshed snapshot. It exists to collapse what used to be many independent DCGM scrapes — the background collection loop plus a fresh scrape+parse on every /container/metrics request — into exactly one scrape+parse per interval. The full DCGM parse is the nodemon's dominant heap allocation on GPU nodes, so removing overlapping/per-request parses is the primary defence against OOM at the 256Mi cap.

QueryMetrics is a non-blocking read of the last snapshot, so it is safe to call from any number of concurrent HTTP handlers without triggering work.

func NewCachedGPUExporter added in v0.1.5

func NewCachedGPUExporter(source MetricsQuerier, interval time.Duration, log logr.Logger) *CachedGPUExporter

NewCachedGPUExporter wraps source with a snapshot cache. interval is clamped to at least MinGPURefreshInterval; a non-positive interval selects the default.

func (*CachedGPUExporter) QueryGPUSnapshot added in v0.1.5

func (c *CachedGPUExporter) QueryGPUSnapshot() (*NodeGPUSummary, SnapshotSectionStatus)

QueryGPUSnapshot returns the cached node-level GPU summary and its publication state without scraping DCGM.

func (*CachedGPUExporter) QueryMetrics added in v0.1.5

func (c *CachedGPUExporter) QueryMetrics(_ context.Context) ([]GPUMetric, error)

QueryMetrics returns the most recent snapshot without scraping, or nil once the snapshot has aged past the staleness threshold. It satisfies MetricsQuerier so it drops in wherever the raw *Exporter was used, and the unified exporter's per-container GPU merge reads through it — so returning nil when stale is what stops the container path from emitting arbitrarily-old GPU values during a sustained DCGM outage (a gap, matching a live scrape's failure, rather than frozen last-good data). The error return is always nil: staleness is a nil result plus a log, not a per-reader error.

func (*CachedGPUExporter) Refresh added in v0.1.5

func (c *CachedGPUExporter) Refresh(ctx context.Context)

Refresh performs one DCGM scrape+parse via the wrapped source and atomically swaps in the new snapshot. On error it keeps the previous snapshot (serving slightly stale data beats serving nothing) and, once refreshes have been failing for gpuStalenessFactor intervals, logs a staleness warning so the gap is visible rather than silent.

func (*CachedGPUExporter) Start added in v0.1.5

func (c *CachedGPUExporter) Start(ctx context.Context)

Start runs an initial refresh and then refreshes on a ticker until ctx is cancelled. Call it once in its own goroutine.

type CgroupReader added in v0.1.2

type CgroupReader struct {
	// contains filtered or unexported fields
}

CgroupReader reads cgroup counters directly from the cgroup filesystem (mounted read-only into the nodemon pod) and resolves each container cgroup to its {namespace,pod,container} identity via the shared PodContainerIndex.

The identity join does NOT require hostPID: the index is populated from pod.Status.ContainerStatuses via a node-scoped Pod informer, not from /proc.

A nil reader, or one with a nil index, yields nil from Collect — callers treat that as "no cgroup signals this cycle" and emit zeros.

func NewCgroupReader added in v0.1.2

func NewCgroupReader(index *PodContainerIndex, log logr.Logger) *CgroupReader

NewCgroupReader creates a CgroupReader rooted at the conventional cgroup mount point. index resolves container IDs to pod identity and must be started by the caller.

func (*CgroupReader) Collect added in v0.1.2

func (r *CgroupReader) Collect() map[string]CgroupSignals

Collect walks the cgroup filesystem and returns per-container signals keyed by "namespace/pod/container" — the same key nodemon's cAdvisor/GPU indexes use, so the exporter can merge them by lookup. Returns nil when the reader or its index is unavailable, or the cgroup root is absent (non-Linux hosts).

type CgroupSignals added in v0.1.2

type CgroupSignals struct {
	CfsPeriods             int64
	CfsThrottledPeriods    int64
	CfsThrottledUsec       int64
	MemoryEventsMax        int64
	CPUPressureSomeUsec    int64
	MemoryPressureSomeUsec int64
	MemoryPressureFullUsec int64
}

CgroupSignals holds the runtime-agnostic cgroup counters for a single container. All are cumulative kernel counters (a window rate is last-first), matching how the metrics pipeline treats counter columns.

type ContainerMetricsResponse added in v0.0.82

type ContainerMetricsResponse struct {
	NodeName  string    `json:"node_name"`
	Namespace string    `json:"namespace"`
	Pod       string    `json:"pod"`
	Container string    `json:"container"`
	Timestamp time.Time `json:"timestamp"`

	// From stats/summary
	CPUUsageNanoCores uint64 `json:"cpu_usage_nanocores"`
	MemoryWorkingSet  uint64 `json:"memory_working_set_bytes"`
	MemoryUsageBytes  uint64 `json:"memory_usage_bytes"`
	MemoryRSSBytes    uint64 `json:"memory_rss_bytes"`
	NetworkRxBytes    uint64 `json:"network_rx_bytes"`
	NetworkTxBytes    uint64 `json:"network_tx_bytes"`

	// From cAdvisor (gauges). Absent from stats/summary.
	MemoryCacheBytes uint64 `json:"memory_cache_bytes"`
	MemorySwapBytes  uint64 `json:"memory_swap_bytes"`

	// From cAdvisor (rates)
	NetworkRxPacketsPerSec float64 `json:"network_rx_packets_per_sec"`
	NetworkTxPacketsPerSec float64 `json:"network_tx_packets_per_sec"`
	NetworkRxErrorsPerSec  float64 `json:"network_rx_errors_per_sec"`
	NetworkTxErrorsPerSec  float64 `json:"network_tx_errors_per_sec"`
	NetworkRxDropsPerSec   float64 `json:"network_rx_drops_per_sec"`
	NetworkTxDropsPerSec   float64 `json:"network_tx_drops_per_sec"`
	DiskReadBytesPerSec    float64 `json:"disk_read_bytes_per_sec"`
	DiskWriteBytesPerSec   float64 `json:"disk_write_bytes_per_sec"`
	DiskReadOpsPerSec      float64 `json:"disk_read_ops_per_sec"`
	DiskWriteOpsPerSec     float64 `json:"disk_write_ops_per_sec"`
	CPUThrottleFraction    float64 `json:"cpu_throttle_fraction"`

	// Runtime-aware cgroup signals (Plane 0), read directly from /sys/fs/cgroup.
	// Cumulative Int64 kernel counters (window rate = last-first).
	CfsPeriods             int64 `json:"cfs_periods,omitempty"`
	CfsThrottledPeriods    int64 `json:"cfs_throttled_periods,omitempty"`
	CfsThrottledUsec       int64 `json:"cfs_throttled_usec,omitempty"`
	MemoryEventsMax        int64 `json:"memory_events_max,omitempty"`
	CPUPressureSomeUsec    int64 `json:"cpu_pressure_some_usec,omitempty"`
	MemoryPressureSomeUsec int64 `json:"memory_pressure_some_usec,omitempty"`
	MemoryPressureFullUsec int64 `json:"memory_pressure_full_usec,omitempty"`

	// From GPU (optional)
	GPUUtilization   float64 `json:"gpu_utilization,omitempty"`
	GPUMemoryUsedMiB float64 `json:"gpu_memory_used_mib,omitempty"`
	GPUMemoryFreeMiB float64 `json:"gpu_memory_free_mib,omitempty"`
	GPUPowerWatts    float64 `json:"gpu_power_watts,omitempty"`
	GPUTemperature   float64 `json:"gpu_temperature_celsius,omitempty"`
}

ContainerMetricsResponse is the JSON response for GET /v2/container/metrics.

type ContainerSnapshotQuerier added in v0.1.5

type ContainerSnapshotQuerier interface {
	QueryContainerSnapshot() ([]ContainerMetricsResponse, SnapshotSectionStatus)
}

ContainerSnapshotQuerier reads the last published container snapshot.

type ContainerSnapshotResponse added in v0.1.5

type ContainerSnapshotResponse struct {
	SchemaVersion    int                        `json:"schema_version"`
	ContainerMetrics []ContainerMetricsResponse `json:"container_metrics"`
	RuntimeMetrics   RuntimeMetrics             `json:"runtime_metrics"`
	Sections         ContainerSnapshotSections  `json:"sections"`
}

type ContainerSnapshotSections added in v0.1.5

type ContainerSnapshotSections struct {
	Containers SnapshotSectionStatus `json:"containers"`
	Runtime    SnapshotSectionStatus `json:"runtime"`
}

type ContainerStats added in v0.0.82

type ContainerStats struct {
	Name   string   `json:"name"`
	CPU    CPUStats `json:"cpu"`
	Memory MemStats `json:"memory"`
}

ContainerStats holds CPU and memory metrics for a single container.

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter ties together the scraper, mapper, and DCGM pod discovery.

func NewExporter

func NewExporter(
	cfg ExporterConfig,
	dynClient dynamic.Interface,
	scraper Scraper,
	mapper MetricMapper,
	log logr.Logger,
) *Exporter

NewExporter creates a new GPU metrics exporter.

func (*Exporter) QueryMetrics

func (e *Exporter) QueryMetrics(ctx context.Context) ([]GPUMetric, error)

QueryMetrics scrapes DCGM exporters on demand and returns mapped GPU metrics.

type ExporterConfig

type ExporterConfig struct {
	HTTPListenPort      int
	DCGMHost            string
	DCGMPort            int
	DCGMMetricsEndpoint string
	DCGMLabels          string // label selector, e.g. "app.kubernetes.io/name=dcgm-exporter"
	NodeName            string
}

ExporterConfig holds environment-driven configuration.

type GPUMetric

type GPUMetric struct {
	NodeName      string `json:"node_name"`
	ModelName     string `json:"model_name"`
	Device        string `json:"device"`
	DeviceID      string `json:"device_id"`
	DeviceUUID    string `json:"device_uuid"`
	MIGProfile    string `json:"mig_profile,omitempty"`
	MIGInstanceID string `json:"mig_instance_id,omitempty"`

	Pod          string `json:"pod"`
	Container    string `json:"container"`
	Namespace    string `json:"namespace"`
	WorkloadName string `json:"workload_name,omitempty"`
	WorkloadKind string `json:"workload_kind,omitempty"`

	SMActive             float64 `json:"sm_active"`
	SMOccupancy          float64 `json:"sm_occupancy"`
	TensorActive         float64 `json:"tensor_active"`
	DRAMActive           float64 `json:"dram_active"`
	PCIeTXBytes          float64 `json:"pcie_tx_bytes"`
	PCIeRXBytes          float64 `json:"pcie_rx_bytes"`
	NVLinkTXBytes        float64 `json:"nvlink_tx_bytes"`
	NVLinkRXBytes        float64 `json:"nvlink_rx_bytes"`
	GraphicsEngineActive float64 `json:"graphics_engine_active"`
	FramebufferTotal     float64 `json:"framebuffer_total"`
	FramebufferUsed      float64 `json:"framebuffer_used"`
	FramebufferFree      float64 `json:"framebuffer_free"`
	PCIeLinkGen          float64 `json:"pcie_link_gen"`
	PCIeLinkWidth        float64 `json:"pcie_link_width"`
	Temperature          float64 `json:"temperature"`
	MemoryTemperature    float64 `json:"memory_temperature"`
	PowerUsage           float64 `json:"power_usage"`
	GPUUtilization       float64 `json:"gpu_utilization"`
	IntPipeActive        float64 `json:"int_pipe_active"`
	FP16PipeActive       float64 `json:"fp16_pipe_active"`
	FP32PipeActive       float64 `json:"fp32_pipe_active"`
	FP64PipeActive       float64 `json:"fp64_pipe_active"`
	ClocksEventReasons   float64 `json:"clocks_event_reasons"`
	XIDErrors            float64 `json:"xid_errors"`
	PowerViolation       float64 `json:"power_violation"`
	ThermalViolation     float64 `json:"thermal_violation"`
	SMClock              float64 `json:"sm_clock"`
	MemClock             float64 `json:"mem_clock"`

	Timestamp time.Time `json:"timestamp"`
}

GPUMetric represents a single GPU's metrics for a container.

type GPUMetricResponse

type GPUMetricResponse struct {
	NodeName      string `json:"node_name"`
	ModelName     string `json:"model_name"`
	Device        string `json:"device"`
	DeviceID      string `json:"device_id"`
	DeviceUUID    string `json:"device_uuid"`
	MIGProfile    string `json:"mig_profile,omitempty"`
	MIGInstanceID string `json:"mig_instance_id,omitempty"`

	Pod          string `json:"pod"`
	Container    string `json:"container"`
	Namespace    string `json:"namespace"`
	WorkloadName string `json:"workload_name,omitempty"`
	WorkloadKind string `json:"workload_kind,omitempty"`

	SMActive             float64 `json:"sm_active"`
	SMOccupancy          float64 `json:"sm_occupancy"`
	TensorActive         float64 `json:"tensor_active"`
	DRAMActive           float64 `json:"dram_active"`
	PCIeTXBytes          float64 `json:"pcie_tx_bytes"`
	PCIeRXBytes          float64 `json:"pcie_rx_bytes"`
	NVLinkTXBytes        float64 `json:"nvlink_tx_bytes"`
	NVLinkRXBytes        float64 `json:"nvlink_rx_bytes"`
	GraphicsEngineActive float64 `json:"graphics_engine_active"`
	FramebufferTotal     float64 `json:"framebuffer_total"`
	FramebufferUsed      float64 `json:"framebuffer_used"`
	FramebufferFree      float64 `json:"framebuffer_free"`
	PCIeLinkGen          float64 `json:"pcie_link_gen"`
	PCIeLinkWidth        float64 `json:"pcie_link_width"`
	Temperature          float64 `json:"temperature"`
	MemoryTemperature    float64 `json:"memory_temperature"`
	PowerUsage           float64 `json:"power_usage"`
	GPUUtilization       float64 `json:"gpu_utilization"`
	IntPipeActive        float64 `json:"int_pipe_active"`
	FP16PipeActive       float64 `json:"fp16_pipe_active"`
	FP32PipeActive       float64 `json:"fp32_pipe_active"`
	FP64PipeActive       float64 `json:"fp64_pipe_active"`
	ClocksEventReasons   float64 `json:"clocks_event_reasons"`
	XIDErrors            float64 `json:"xid_errors"`
	PowerViolation       float64 `json:"power_violation"`
	ThermalViolation     float64 `json:"thermal_violation"`
	SMClock              float64 `json:"sm_clock"`
	MemClock             float64 `json:"mem_clock"`

	Timestamp time.Time `json:"timestamp"`
}

GPUMetricResponse is the JSON API contract for the /container/metrics endpoint.

type GPUMigInstance added in v0.1.7

type GPUMigInstance struct {
	DeviceUUID    string `json:"device_uuid"`
	DeviceID      string `json:"device_id"`
	MIGProfile    string `json:"mig_profile"`
	MIGInstanceID string `json:"mig_instance_id"`
	ModelName     string `json:"model_name"`

	TensorActive         float64 `json:"tensor_active"`
	DRAMActive           float64 `json:"dram_active"`
	GraphicsEngineActive float64 `json:"graphics_engine_active"`
	FramebufferUsed      float64 `json:"framebuffer_used"`
	FramebufferTotal     float64 `json:"framebuffer_total"`
}

GPUMigInstance captures per-instance identity and profiling metrics for a single MIG partition, carried through from the GPUMetric row it was built from. DCGM_FI_DEV_GPU_UTIL and SM metrics are excluded since DCGM never populates them on MIG rows; the DCGM_FI_PROF_* family (tensor/DRAM/graphics engine active) and framebuffer used/free ARE reported per instance with real distinct values (confirmed against run-ai/fake-gpu-operator's captured DCGM MIG samples). DCGM_FI_DEV_FB_TOTAL is never reported on MIG rows in those samples, so FramebufferTotal is derived as used+free rather than read from that field.

type GPUSnapshotQuerier added in v0.1.5

type GPUSnapshotQuerier interface {
	QueryGPUSnapshot() (*NodeGPUSummary, SnapshotSectionStatus)
}

GPUSnapshotQuerier reads the last published node GPU summary.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient abstracts *http.Client for testing.

type InterfaceStats added in v0.0.82

type InterfaceStats struct {
	Name    string  `json:"name"`
	RxBytes *uint64 `json:"rxBytes"`
	TxBytes *uint64 `json:"txBytes"`
}

InterfaceStats holds per-interface RX/TX byte counters.

type JVMCollector added in v0.0.78

type JVMCollector struct {
	// contains filtered or unexported fields
}

JVMCollector collects JVM metrics from hsperfdata files via /proc. Requires the pod to run with hostPID: true and as UID 0 to read /proc/<pid>/root/tmp/hsperfdata_*/<nsPid> for other containers.

func NewJVMCollector added in v0.0.78

func NewJVMCollector(nodeName string, index *PodContainerIndex, log logr.Logger) *JVMCollector

NewJVMCollector creates a JVMCollector. index must already be started (or be started concurrently) — JVMCollector only reads from it. procRoot defaults to "/proc".

func (*JVMCollector) Collect added in v0.1.2

func (c *JVMCollector) Collect(ctx context.Context)

Collect performs a single /proc walk, builds JVM metrics, and publishes the result for QueryJVMMetrics to serve. A cycle that produces nothing usable (an error and no metrics) keeps the last good snapshot instead of blanking it — a transient failure would otherwise erase good data for a full refresh interval. The error itself is still published either way, so QueryJVMMetrics reflects that the most recent cycle had a problem.

func (*JVMCollector) QueryJVMMetrics added in v0.0.78

func (c *JVMCollector) QueryJVMMetrics(_ context.Context) ([]JVMMetric, error)

QueryJVMMetrics returns the JVM metrics from the last completed background Collect — see StartCollectionLoop. It never does its own /proc walk, so it's safe to call on every HTTP request.

func (*JVMCollector) StartCollectionLoop added in v0.1.2

func (c *JVMCollector) StartCollectionLoop(ctx context.Context, interval time.Duration)

StartCollectionLoop runs Collect immediately, then on every tick. Call in a goroutine. ctx is expected to be long-lived (cancelled only at shutdown), so each individual cycle gets its own bounded sub-context — otherwise a slow or stuck cycle (e.g. a wedged hsperfdata read) would run forever, permanently freezing the cache and preventing any future tick from ever running, since the loop is single-threaded.

type JVMFlagSources added in v0.0.78

type JVMFlagSources struct {
	XmsBytes            string `json:"xms_bytes,omitempty"`
	XmxBytes            string `json:"xmx_bytes,omitempty"`
	MaxRamPercentage    string `json:"max_ram_percentage,omitempty"`
	UseContainerSupport string `json:"use_container_support,omitempty"`
}

JVMFlagSources describes where each extracted JVM flag value came from. This is best-effort; precedence rules are implemented in ParseJVMFlagsWithSources.

type JVMFlagsExtracted added in v0.0.78

type JVMFlagsExtracted struct {
	XmsBytes            *int64   `json:"xms_bytes,omitempty"`
	XmxBytes            *int64   `json:"xmx_bytes,omitempty"`
	MaxRamPercentage    *float64 `json:"max_ram_percentage,omitempty"`
	UseContainerSupport *bool    `json:"use_container_support,omitempty"`
}

JVMFlagsExtracted holds JVM flags parsed from the process cmdline and/or env.

func ParseJVMFlags added in v0.0.78

func ParseJVMFlags(cmdline string) JVMFlagsExtracted

ParseJVMFlags parses JVM memory and container-awareness flags from a process cmdline string.

NOTE: This is *best-effort* parsing for the few flags we care about for sizing.

type JVMMetric added in v0.0.78

type JVMMetric struct {
	NodeName    string `json:"node_name"`
	Pod         string `json:"pod"`
	Namespace   string `json:"namespace"`
	Container   string `json:"container"`
	ContainerID string `json:"container_id"`
	PidHost     int    `json:"pid_host"`
	PidNS       int    `json:"pid_ns"`

	JavaCommand string `json:"java_command,omitempty"`
	JavaVersion string `json:"java_version,omitempty"`

	HeapSizeBytes    int64 `json:"heap_size_bytes"`
	HeapUsedBytes    int64 `json:"heap_used_bytes"`
	HeapMaxSizeBytes int64 `json:"heap_max_size_bytes"`

	GCTimeSecondsTotal            map[string]float64 `json:"gc_time_seconds_total"`
	SafepointTimeSecondsTotal     float64            `json:"safepoint_time_seconds_total"`
	SafepointSyncTimeSecondsTotal float64            `json:"safepoint_sync_time_seconds_total"`

	FlagsExtracted JVMFlagsExtracted `json:"flags_extracted"`
	FlagSources    JVMFlagSources    `json:"flag_sources,omitempty"`
	// RawCmdline is the effective command line including env-injected options
	// (JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, JAVA_OPTS). Note: this may contain
	// sensitive values if secrets are passed via JVM system properties or env vars.
	RawCmdline string    `json:"raw_cmdline,omitempty"`
	Timestamp  time.Time `json:"timestamp"`
}

JVMMetric holds per-container JVM metrics extracted from hsperfdata.

type JVMMetricsQuerier added in v0.0.78

type JVMMetricsQuerier interface {
	QueryJVMMetrics(ctx context.Context) ([]JVMMetric, error)
}

JVMMetricsQuerier provides on-demand JVM metrics.

type JavaProcess added in v0.0.78

type JavaProcess struct {
	PidHost     int
	PidNS       int
	ContainerID string

	CmdLine string
	// EnvJavaOpts includes any env-injected Java options found in /proc/<pid>/environ.
	// Keys are env var names (JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, JAVA_OPTS).
	EnvJavaOpts map[string]string

	HsperfDataPath string
}

JavaProcess holds info about a discovered Java process running inside a Kubernetes container.

type MemStats added in v0.0.82

type MemStats struct {
	Time            time.Time `json:"time"`
	AvailableBytes  *uint64   `json:"availableBytes"`
	UsageBytes      *uint64   `json:"usageBytes"`
	WorkingSetBytes *uint64   `json:"workingSetBytes"`
	RSSBytes        *uint64   `json:"rssBytes"`
	PageFaults      *uint64   `json:"pageFaults"`
	MajorPageFaults *uint64   `json:"majorPageFaults"`
}

MemStats holds memory usage metrics. Pointer fields are omitted by kubelet when unavailable.

type MetricFamilyMap

type MetricFamilyMap map[string]*dto.MetricFamily

MetricFamilyMap maps a Prometheus metric name to its parsed metric family.

type MetricMapper

type MetricMapper interface {
	MapToGPUMetrics(ctx context.Context, metrics []MetricFamilyMap) []GPUMetric
}

MetricMapper maps scraped DCGM metric families into structured GPU metrics.

func NewMapper

func NewMapper(nodeName string, resolver WorkloadResolver, log logr.Logger) MetricMapper

NewMapper creates a new MetricMapper.

type MetricName

type MetricName = string

MetricName identifies a DCGM metric by its Prometheus metric name.

const (
	MetricStreamingMultiProcessorActive    MetricName = "DCGM_FI_PROF_SM_ACTIVE"
	MetricStreamingMultiProcessorOccupancy MetricName = "DCGM_FI_PROF_SM_OCCUPANCY"
	MetricStreamingMultiProcessorTensor    MetricName = "DCGM_FI_PROF_PIPE_TENSOR_ACTIVE"
	MetricDRAMActive                       MetricName = "DCGM_FI_PROF_DRAM_ACTIVE"
	MetricPCIeTXBytes                      MetricName = "DCGM_FI_PROF_PCIE_TX_BYTES"
	MetricPCIeRXBytes                      MetricName = "DCGM_FI_PROF_PCIE_RX_BYTES"
	MetricNVLinkTXBytes                    MetricName = "DCGM_FI_PROF_NVLINK_TX_BYTES"
	MetricNVLinkRXBytes                    MetricName = "DCGM_FI_PROF_NVLINK_RX_BYTES"
	MetricGraphicsEngineActive             MetricName = "DCGM_FI_PROF_GR_ENGINE_ACTIVE"
	MetricFrameBufferTotal                 MetricName = "DCGM_FI_DEV_FB_TOTAL"
	MetricFrameBufferUsed                  MetricName = "DCGM_FI_DEV_FB_USED"
	MetricFrameBufferFree                  MetricName = "DCGM_FI_DEV_FB_FREE"
	MetricPCIeLinkGen                      MetricName = "DCGM_FI_DEV_PCIE_LINK_GEN"
	MetricPCIeLinkWidth                    MetricName = "DCGM_FI_DEV_PCIE_LINK_WIDTH"
	MetricGPUTemperature                   MetricName = "DCGM_FI_DEV_GPU_TEMP"
	MetricMemoryTemperature                MetricName = "DCGM_FI_DEV_MEMORY_TEMP"
	MetricPowerUsage                       MetricName = "DCGM_FI_DEV_POWER_USAGE"
	MetricGPUUtilization                   MetricName = "DCGM_FI_DEV_GPU_UTIL"
	MetricIntPipeActive                    MetricName = "DCGM_FI_PROF_PIPE_INT_ACTIVE"
	MetricFloat16PipeActive                MetricName = "DCGM_FI_PROF_PIPE_FP16_ACTIVE"
	MetricFloat32PipeActive                MetricName = "DCGM_FI_PROF_PIPE_FP32_ACTIVE"
	MetricFloat64PipeActive                MetricName = "DCGM_FI_PROF_PIPE_FP64_ACTIVE"
	MetricClocksEventReasons               MetricName = "DCGM_FI_DEV_CLOCKS_EVENT_REASONS"
	MetricXIDErrors                        MetricName = "DCGM_FI_DEV_XID_ERRORS"
	MetricPowerViolation                   MetricName = "DCGM_FI_DEV_POWER_VIOLATION"
	MetricThermalViolation                 MetricName = "DCGM_FI_DEV_THERMAL_VIOLATION"
	MetricSMClock                          MetricName = "DCGM_FI_DEV_SM_CLOCK"
	MetricMemClock                         MetricName = "DCGM_FI_DEV_MEM_CLOCK"
)

DCGM metric names scraped from the DCGM exporter.

type MetricsQuerier

type MetricsQuerier interface {
	QueryMetrics(ctx context.Context) ([]GPUMetric, error)
}

MetricsQuerier provides on-demand GPU metrics.

type NetworkStats added in v0.0.82

type NetworkStats struct {
	Interfaces []InterfaceStats `json:"interfaces"`
}

NetworkStats holds network interface metrics.

type NodeGPUSummary added in v0.1.5

type NodeGPUSummary struct {
	// GPUCount is the number of distinct physical GPUs (deduped by DeviceUUID).
	// A MIG-partitioned physical GPU reports one DCGM row per MIG instance but
	// shares a single DeviceUUID across them, so this stays accurate whether or
	// not MIG is in use.
	GPUCount float64 `json:"gpu_count"`
	// GPUInstanceCount is the raw number of DCGM-reported rows (whole GPUs plus
	// every MIG instance) — i.e. the schedulable GPU-shaped unit count.
	GPUInstanceCount          float64  `json:"gpu_instance_count"`
	GPUUtilizationAvg         float64  `json:"gpu_utilization_avg"`
	GPUUtilizationMax         float64  `json:"gpu_utilization_max"`
	GPUMemoryUsedTotal        float64  `json:"gpu_memory_used_total"`
	GPUMemoryFreeTotal        float64  `json:"gpu_memory_free_total"`
	GPUMemoryTotalMb          float64  `json:"gpu_memory_total_mb"`
	GPUPowerUsageTotal        float64  `json:"gpu_power_usage_total"`
	GPUTemperatureAvg         float64  `json:"gpu_temperature_avg"`
	GPUTemperatureMax         float64  `json:"gpu_temperature_max"`
	GPUMemoryTemperatureAvg   float64  `json:"gpu_memory_temperature_avg"`
	GPUMemoryTemperatureMax   float64  `json:"gpu_memory_temperature_max"`
	GPUTensorUtilizationAvg   float64  `json:"gpu_tensor_utilization_avg"`
	GPUDramUtilizationAvg     float64  `json:"gpu_dram_utilization_avg"`
	GPUPCIeTxBytesTotal       float64  `json:"gpu_pcie_tx_bytes_total"`
	GPUPCIeRxBytesTotal       float64  `json:"gpu_pcie_rx_bytes_total"`
	GPUGraphicsUtilizationAvg float64  `json:"gpu_graphics_utilization_avg"`
	GPUUsage                  float64  `json:"gpu_usage"`
	GPUModels                 []string `json:"gpu_models"`
	GPUUUIDs                  []string `json:"gpu_uuids"`
	// GPUMigInstances is populated only when the node has MIG-partitioned
	// GPUs — nil/omitted for the overwhelming non-MIG majority.
	GPUMigInstances []GPUMigInstance `json:"gpu_mig_instances,omitempty"`
}

func SummarizeNodeGPU added in v0.1.5

func SummarizeNodeGPU(metrics []GPUMetric) *NodeGPUSummary

SummarizeNodeGPU aggregates per-GPU metrics using the controller's existing node-level metric semantics.

DCGM reports one row per physical GPU, but for a MIG-partitioned GPU it instead reports one row per MIG instance — all sharing the same DeviceUUID as the physical GPU they're carved from (confirmed against real DCGM exposition samples, see snapshot_types_migsim_test.go). Treating every row as an independent GPU inflates GPUCount by the MIG instance count (e.g. 8 physical A100s partitioned into 19 MIG slices previously reported as 22 "GPUs"). DCGM also never populates DCGM_FI_DEV_GPU_UTIL for MIG rows, so including them in the utilization average silently drags it toward zero whenever any MIG partitioning exists on the node.

type NodeMetricsResponse added in v0.0.82

type NodeMetricsResponse struct {
	NodeName  string    `json:"node_name"`
	Timestamp time.Time `json:"timestamp"`

	// Node-level CPU/memory from kubelet stats/summary (includes system processes)
	CPUUsageNanoCores uint64 `json:"cpu_usage_nanocores"`
	MemoryWorkingSet  uint64 `json:"memory_working_set_bytes"`

	// Network rates (per second)
	NetworkRxBytesPerSec   float64 `json:"network_rx_bytes_per_sec"`
	NetworkTxBytesPerSec   float64 `json:"network_tx_bytes_per_sec"`
	NetworkRxPacketsPerSec float64 `json:"network_rx_packets_per_sec"`
	NetworkTxPacketsPerSec float64 `json:"network_tx_packets_per_sec"`
	NetworkRxErrorsPerSec  float64 `json:"network_rx_errors_per_sec"`
	NetworkTxErrorsPerSec  float64 `json:"network_tx_errors_per_sec"`
	NetworkRxDropsPerSec   float64 `json:"network_rx_drops_per_sec"`
	NetworkTxDropsPerSec   float64 `json:"network_tx_drops_per_sec"`

	// Disk I/O rates (per second)
	DiskReadBytesPerSec  float64 `json:"disk_read_bytes_per_sec"`
	DiskWriteBytesPerSec float64 `json:"disk_write_bytes_per_sec"`
	DiskReadOpsPerSec    float64 `json:"disk_read_ops_per_sec"`
	DiskWriteOpsPerSec   float64 `json:"disk_write_ops_per_sec"`

	// GPU aggregates (optional)
	GPUUtilizationAvg   float64 `json:"gpu_utilization_avg,omitempty"`
	GPUMemoryUsedMiBSum float64 `json:"gpu_memory_used_mib_sum,omitempty"`
	GPUPowerWattsSum    float64 `json:"gpu_power_watts_sum,omitempty"`
	GPUTemperatureMax   float64 `json:"gpu_temperature_max_celsius,omitempty"`
}

NodeMetricsResponse is the JSON response for GET /node/metrics.

type NodeSnapshotQuerier added in v0.1.5

type NodeSnapshotQuerier interface {
	QueryNodeSnapshot() (*NodeMetricsResponse, SnapshotSectionStatus)
}

NodeSnapshotQuerier reads the last published node snapshot.

type NodeSnapshotResponse added in v0.1.5

type NodeSnapshotResponse struct {
	SchemaVersion int                  `json:"schema_version"`
	NodeMetrics   *NodeMetricsResponse `json:"node_metrics,omitempty"`
	GPUSummary    *NodeGPUSummary      `json:"gpu_summary,omitempty"`
	Sections      NodeSnapshotSections `json:"sections"`
}

type NodeSnapshotSections added in v0.1.5

type NodeSnapshotSections struct {
	Node SnapshotSectionStatus `json:"node"`
	GPU  SnapshotSectionStatus `json:"gpu"`
}

type NodeStats added in v0.0.82

type NodeStats struct {
	NodeName string       `json:"nodeName"`
	CPU      CPUStats     `json:"cpu"`
	Memory   MemStats     `json:"memory"`
	Network  NetworkStats `json:"network"`
}

NodeStats holds node-level metrics from kubelet stats/summary.

type PVCMetricsResponse added in v0.0.82

type PVCMetricsResponse struct {
	Namespace      string `json:"namespace"`
	Pod            string `json:"pod"`
	PVCName        string `json:"pvc_name"`
	UsedBytes      uint64 `json:"used_bytes"`
	CapacityBytes  uint64 `json:"capacity_bytes"`
	AvailableBytes uint64 `json:"available_bytes"`
}

PVCMetricsResponse is the JSON response for GET /pvc/metrics.

type PVCRef added in v0.0.82

type PVCRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

PVCRef identifies the PersistentVolumeClaim backing a volume.

type PodContainerIndex added in v0.0.97

type PodContainerIndex struct {
	// contains filtered or unexported fields
}

PodContainerIndex maintains a node-scoped containerID -> pod/namespace/container mapping via a Pod informer. It requires hostPID: true to be useful, since the collectors that consult it (JVMCollector, RuntimeCollector) resolve process container IDs from /proc, which is only populated with cross-namespace PIDs when hostPID is enabled.

A single PodContainerIndex is shared across all process-introspection collectors on a node rather than each owning its own Pod watch, since they all need the exact same mapping.

func NewPodContainerIndex added in v0.0.97

func NewPodContainerIndex(
	nodeName string,
	k8sClient kubernetes.Interface,
	expectHostPID bool,
	log logr.Logger,
) *PodContainerIndex

NewPodContainerIndex creates a PodContainerIndex. procRoot defaults to "/proc".

expectHostPID should be true only when the index feeds /proc-walking collectors (JVM/runtime), which require hostPID: true. The cgroup reader resolves identities from container statuses via the k8s API and does NOT need hostPID, so callers that only use the reader pass false to skip the /proc visibility warning.

func (*PodContainerIndex) Lookup added in v0.0.97

func (idx *PodContainerIndex) Lookup(containerID string) (containerInfo, bool)

Lookup returns the pod metadata for a given containerID (hex, no scheme prefix).

func (*PodContainerIndex) Start added in v0.0.97

func (idx *PodContainerIndex) Start() error

Start creates a node-scoped pod informer and waits for the cache to sync. Retries up to 3 times with exponential backoff (5s, 10s, 20s) on transient failures.

func (*PodContainerIndex) Stop added in v0.0.97

func (idx *PodContainerIndex) Stop()

Stop shuts down the informer factory. Safe to call multiple times.

type PodStats added in v0.0.82

type PodStats struct {
	PodRef struct {
		Name      string `json:"name"`
		Namespace string `json:"namespace"`
	} `json:"podRef"`
	Containers  []ContainerStats `json:"containers"`
	Network     NetworkStats     `json:"network"`
	VolumeStats []VolumeStats    `json:"volume"`
}

PodStats holds per-pod resource metrics.

type RateCalculator added in v0.0.82

type RateCalculator struct {
	// contains filtered or unexported fields
}

RateCalculator converts monotonically-increasing counter observations into per-second rates. It is safe for concurrent use.

func NewRateCalculator added in v0.0.82

func NewRateCalculator() *RateCalculator

NewRateCalculator returns an initialised RateCalculator.

func (*RateCalculator) EvictOlderThan added in v0.0.82

func (rc *RateCalculator) EvictOlderThan(maxAge time.Duration)

EvictOlderThan removes entries whose last observation timestamp is older than maxAge relative to the current wall-clock time. This prevents unbounded memory growth for short-lived workloads.

func (*RateCalculator) Rate added in v0.0.82

func (rc *RateCalculator) Rate(entity, metric string, value float64, ts time.Time) float64

Rate records a counter value and returns the per-second rate since the last observation for the same (entity, metric) pair.

Returns 0 on:

  • first call for a key (no baseline yet)
  • counter reset (current value < previous value)
  • zero elapsed time between observations

type RuntimeCollector added in v0.0.97

type RuntimeCollector struct {
	// contains filtered or unexported fields
}

RuntimeCollector performs a single /proc walk per query and builds metrics for every discovered runtime. This backs the combined /container/runtime-metrics endpoint, which the zxporter collector polls once per cycle.

func NewRuntimeCollector added in v0.0.97

func NewRuntimeCollector(nodeName string, index *PodContainerIndex, log logr.Logger) *RuntimeCollector

NewRuntimeCollector creates a RuntimeCollector. index must already be started (or be started concurrently) — RuntimeCollector only reads from it. procRoot defaults to "/proc".

func (*RuntimeCollector) Collect added in v0.1.2

func (c *RuntimeCollector) Collect(ctx context.Context)

Collect performs a single /proc walk, builds JVM and generic-runtime metrics, and publishes the result for QueryRuntimeMetrics to serve. A cycle that produces nothing usable (an error and no metrics of either kind) keeps the last good snapshot instead of blanking it — a transient failure would otherwise erase good data for a full refresh interval. The error itself is still published either way, so QueryRuntimeMetrics reflects that the most recent cycle had a problem.

func (*RuntimeCollector) QueryRuntimeMetrics added in v0.0.97

func (c *RuntimeCollector) QueryRuntimeMetrics(_ context.Context) (RuntimeMetrics, error)

QueryRuntimeMetrics returns the JVM and generic-runtime metrics from the last completed background Collect — see StartCollectionLoop. It never does its own /proc walk, so it's safe to call on every HTTP request.

func (*RuntimeCollector) QueryRuntimeSnapshot added in v0.1.5

func (c *RuntimeCollector) QueryRuntimeSnapshot() (RuntimeMetrics, SnapshotSectionStatus)

QueryRuntimeSnapshot returns the last published runtime payload and its collection state without walking /proc.

func (*RuntimeCollector) StartCollectionLoop added in v0.1.2

func (c *RuntimeCollector) StartCollectionLoop(ctx context.Context, interval time.Duration)

StartCollectionLoop runs Collect immediately, then on every tick. Call in a goroutine. ctx is expected to be long-lived (cancelled only at shutdown), so each individual cycle gets its own bounded sub-context — otherwise a slow or stuck cycle (e.g. a wedged hsperfdata read) would run forever, permanently freezing the cache and preventing any future tick from ever running, since the loop is single-threaded.

type RuntimeMetrics added in v0.0.97

type RuntimeMetrics struct {
	JVM      []JVMMetric            `json:"jvm"`
	Runtimes []RuntimeProcessMetric `json:"runtimes"`
}

RuntimeMetrics bundles the process-introspection metrics collected in a single /proc walk, across every supported runtime. JVM has its own bucket because its payload is hsperfdata-backed heap metrics + flag extraction; every other runtime (Node.js, .NET, Go, GraalVM native-image, Python, Ruby, Deno, Bun) is existence + best-effort version and shares the generic shape.

type RuntimeMetricsQuerier added in v0.0.97

type RuntimeMetricsQuerier interface {
	QueryRuntimeMetrics(ctx context.Context) (RuntimeMetrics, error)
}

RuntimeMetricsQuerier provides on-demand combined JVM + Node.js metrics.

type RuntimeProcess added in v0.0.97

type RuntimeProcess struct {
	Kind        processKind
	Runtime     string
	PidHost     int
	PidNS       int
	ContainerID string
	CmdLine     string

	// PidDir is /proc/<pid> on procRoot, retained so the collector can resolve
	// the version without re-walking /proc.
	PidDir string
}

RuntimeProcess is a discovered generic-runtime process prior to version resolution (which the collector layer caches per container), the analog of JavaProcess for the probed/table-detected runtimes.

type RuntimeProcessMetric added in v0.0.97

type RuntimeProcessMetric struct {
	// Runtime is the detected runtime name: "dotnet" | "go" |
	// "graalvm-native-image" | "python" | "ruby" | "deno" | "bun".
	Runtime string `json:"runtime"`

	NodeName    string `json:"node_name"`
	Pod         string `json:"pod"`
	Namespace   string `json:"namespace"`
	Container   string `json:"container"`
	ContainerID string `json:"container_id"`
	PidHost     int    `json:"pid_host"`
	PidNS       int    `json:"pid_ns"`

	// Version is best-effort and passive (env var, /proc/<pid>/maps, embedded
	// build info, or a read-only binary scan depending on the runtime). Empty if
	// nothing resolves — the process is still reported as a detected workload.
	Version       string `json:"version,omitempty"`
	VersionSource string `json:"version_source,omitempty"` // "env" | "maps" | "exe-path" | "comm" | "buildinfo" | "binary-scan"

	RawCmdline string    `json:"raw_cmdline,omitempty"`
	Timestamp  time.Time `json:"timestamp"`
}

RuntimeProcessMetric holds per-container detection for the generic runtimes (.NET, Go, GraalVM native-image, Python, Ruby, Deno, Bun) — everything beyond JVM and Node.js, which have their own dedicated metric types for historical and payload-shape reasons. Scoped to existence + version, same as Node.js.

type RuntimeSnapshotQuerier added in v0.1.5

type RuntimeSnapshotQuerier interface {
	QueryRuntimeSnapshot() (RuntimeMetrics, SnapshotSectionStatus)
}

RuntimeSnapshotQuerier reads the last published process-runtime snapshot.

type Scraper

type Scraper interface {
	Scrape(ctx context.Context, urls []string) ([]MetricFamilyMap, error)
}

Scraper fetches and parses Prometheus-format metrics from DCGM exporter endpoints.

func NewScraper

func NewScraper(httpClient HTTPClient, log logr.Logger) Scraper

NewScraper creates a new DCGM metrics scraper.

type SnapshotSectionState added in v0.1.5

type SnapshotSectionState string
const (
	SnapshotStateReady    SnapshotSectionState = "ready"
	SnapshotStateStale    SnapshotSectionState = "stale"
	SnapshotStateNotReady SnapshotSectionState = "not_ready"
	SnapshotStateDisabled SnapshotSectionState = "disabled"
)

type SnapshotSectionStatus added in v0.1.5

type SnapshotSectionStatus struct {
	State       SnapshotSectionState `json:"state"`
	CollectedAt *time.Time           `json:"collected_at,omitempty"`
}

type StatsPoller added in v0.0.82

type StatsPoller struct {
	// contains filtered or unexported fields
}

StatsPoller fetches the kubelet /stats/summary endpoint and parses the response.

func NewStatsPoller added in v0.0.82

func NewStatsPoller(baseURL string, httpClient HTTPClient, log logr.Logger) *StatsPoller

NewStatsPoller creates a new StatsPoller targeting the given kubelet base URL.

func (*StatsPoller) Poll added in v0.0.82

func (p *StatsPoller) Poll(ctx context.Context) (*StatsSummary, error)

Poll fetches and parses /stats/summary from the kubelet. Uses a 10-second timeout.

type StatsSummary added in v0.0.82

type StatsSummary struct {
	Pods []PodStats `json:"pods"`
	Node NodeStats  `json:"node"`
}

StatsSummary is the top-level response from the kubelet /stats/summary endpoint.

type UnifiedExporter added in v0.0.82

type UnifiedExporter struct {
	// contains filtered or unexported fields
}

UnifiedExporter combines stats/summary, cAdvisor, and GPU data into the unified response types consumed by the HTTP handlers. It implements UnifiedQuerier.

func NewUnifiedExporter added in v0.0.82

func NewUnifiedExporter(
	statsPoller *StatsPoller,
	cadvisorScraper *CAdvisorScraper,
	gpuExporter MetricsQuerier,
	cgroupReader *CgroupReader,
	nodeName string,
	log logr.Logger,
) *UnifiedExporter

NewUnifiedExporter creates a UnifiedExporter.

func (*UnifiedExporter) Collect added in v0.0.82

func (u *UnifiedExporter) Collect(ctx context.Context)

Collect fetches from all sources and updates cached results.

func (*UnifiedExporter) QueryContainerMetrics added in v0.0.82

func (u *UnifiedExporter) QueryContainerMetrics() []ContainerMetricsResponse

QueryContainerMetrics implements UnifiedQuerier.

func (*UnifiedExporter) QueryContainerSnapshot added in v0.1.5

func (u *UnifiedExporter) QueryContainerSnapshot() ([]ContainerMetricsResponse, SnapshotSectionStatus)

QueryContainerSnapshot returns the currently published container metrics and collection metadata without polling any source.

func (*UnifiedExporter) QueryNodeMetrics added in v0.0.82

func (u *UnifiedExporter) QueryNodeMetrics() *NodeMetricsResponse

QueryNodeMetrics implements UnifiedQuerier.

func (*UnifiedExporter) QueryNodeSnapshot added in v0.1.5

func (u *UnifiedExporter) QueryNodeSnapshot() (*NodeMetricsResponse, SnapshotSectionStatus)

QueryNodeSnapshot returns the currently published node metrics and collection metadata without polling any source.

func (*UnifiedExporter) QueryPVCMetrics added in v0.0.82

func (u *UnifiedExporter) QueryPVCMetrics() []PVCMetricsResponse

QueryPVCMetrics implements UnifiedQuerier.

func (*UnifiedExporter) StartCollectionLoop added in v0.0.82

func (u *UnifiedExporter) StartCollectionLoop(ctx context.Context, interval time.Duration)

StartCollectionLoop runs periodic collection. Call in a goroutine.

type UnifiedQuerier added in v0.0.82

type UnifiedQuerier interface {
	QueryContainerMetrics() []ContainerMetricsResponse
	QueryNodeMetrics() *NodeMetricsResponse
	QueryPVCMetrics() []PVCMetricsResponse
}

UnifiedQuerier provides merged metrics from all sources.

type VolumeStats added in v0.0.82

type VolumeStats struct {
	Name           string  `json:"name"`
	PVCRef         *PVCRef `json:"pvcRef,omitempty"`
	UsedBytes      *uint64 `json:"usedBytes"`
	CapacityBytes  *uint64 `json:"capacityBytes"`
	AvailableBytes *uint64 `json:"availableBytes"`
}

VolumeStats holds PVC/volume usage metrics.

type Workload

type Workload struct {
	Name      string
	Namespace string
	Kind      string
}

Workload represents a resolved Kubernetes workload.

type WorkloadResolver

type WorkloadResolver interface {
	FindWorkloadForPod(
		ctx context.Context,
		name, namespace string,
	) (kind, workloadName string, err error)
}

WorkloadResolver resolves the top-level owning workload for a pod.

func NewWorkloadResolver

func NewWorkloadResolver(
	dynClient dynamic.Interface,
	cfg WorkloadResolverConfig,
	log logr.Logger,
) WorkloadResolver

NewWorkloadResolver creates a WorkloadResolver that uses the K8s dynamic client to walk owner references and find the top-level owning workload. Supports LRU caching and label-based workload name resolution.

type WorkloadResolverConfig

type WorkloadResolverConfig struct {
	LabelKeys []string
	CacheSize int
}

WorkloadResolverConfig holds configuration for the workload resolver.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL