nodemon

package
v0.0.82 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindPod         = "Pod"
	KindJob         = "Job"
	KindCronJob     = "CronJob"
	KindRollout     = "Rollout"
	KindDaemonSet   = "DaemonSet"
	KindDeployment  = "Deployment"
	KindStatefulSet = "StatefulSet"
	KindReplicaSet  = "ReplicaSet"
)

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 NewJVMMetricsHandler added in v0.0.78

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

NewJVMMetricsHandler creates an HTTP handler for GET /container/jvm-metrics. Supports ?container=, ?pod=, ?namespace=, ?node= query filters.

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 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 NewServerMux

func NewServerMux(containerMetricsHandler http.Handler, jvmMetricsHandler 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: JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, JAVA_OPTS

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
}

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 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 (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"`

	// 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 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 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, k8sClient kubernetes.Interface, log logr.Logger) *JVMCollector

NewJVMCollector creates a JVMCollector. procRoot defaults to "/proc".

func (*JVMCollector) QueryJVMMetrics added in v0.0.78

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

QueryJVMMetrics returns JVM metrics for all discovered Java containers on this node.

func (*JVMCollector) Start added in v0.0.78

func (c *JVMCollector) Start() error

Start creates a node-scoped pod informer and waits for the cache to sync. Must be called exactly once before serving HTTP requests.

func (*JVMCollector) Stop added in v0.0.78

func (c *JVMCollector) Stop()

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

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 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 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 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 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 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 *Exporter,
	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) QueryNodeMetrics added in v0.0.82

func (u *UnifiedExporter) QueryNodeMetrics() *NodeMetricsResponse

QueryNodeMetrics implements UnifiedQuerier.

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