nodemon

package
v0.0.98 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 33 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 NewRuntimeMetricsHandler added in v0.0.97

func NewRuntimeMetricsHandler(querier RuntimeMetricsQuerier, log logr.Logger) 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.

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
}

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, 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) 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.

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 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, log logr.Logger) *PodContainerIndex

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

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) QueryRuntimeMetrics added in v0.0.97

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

QueryRuntimeMetrics returns JVM and generic-runtime metrics for all discovered containers on this node, from a single /proc walk.

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