Documentation
¶
Index ¶
- Constants
- Variables
- func NewContainerMetricsHandler(querier MetricsQuerier, log logr.Logger) http.Handler
- func NewJVMMetricsHandler(querier JVMMetricsQuerier, log logr.Logger) http.Handler
- func NewServerMux(containerMetricsHandler http.Handler, jvmMetricsHandler http.Handler) *http.ServeMux
- func ParseJVMFlagsWithSources(cmdline string, envJavaOpts map[string]string) (JVMFlagsExtracted, JVMFlagSources, string)
- type Exporter
- type ExporterConfig
- type GPUMetric
- type GPUMetricResponse
- type HTTPClient
- type JVMCollector
- type JVMFlagSources
- type JVMFlagsExtracted
- type JVMMetric
- type JVMMetricsQuerier
- type JavaProcess
- type MetricFamilyMap
- type MetricMapper
- type MetricName
- type MetricsQuerier
- type Scraper
- type Workload
- type WorkloadResolver
- type WorkloadResolverConfig
Constants ¶
const ( KindPod = "Pod" KindJob = "Job" KindCronJob = "CronJob" KindRollout = "Rollout" KindDaemonSet = "DaemonSet" KindDeployment = "Deployment" KindStatefulSet = "StatefulSet" KindReplicaSet = "ReplicaSet" )
Variables ¶
var EnabledMetrics = map[MetricName]struct{}{ MetricStreamingMultiProcessorActive: {}, MetricStreamingMultiProcessorOccupancy: {}, MetricStreamingMultiProcessorTensor: {}, MetricDRAMActive: {}, MetricPCIeTXBytes: {}, MetricPCIeRXBytes: {}, MetricNVLinkTXBytes: {}, MetricNVLinkRXBytes: {}, MetricGraphicsEngineActive: {}, MetricFrameBufferTotal: {}, MetricFrameBufferUsed: {}, MetricFrameBufferFree: {}, MetricPCIeLinkGen: {}, MetricPCIeLinkWidth: {}, MetricGPUTemperature: {}, MetricMemoryTemperature: {}, MetricPowerUsage: {}, MetricGPUUtilization: {}, MetricIntPipeActive: {}, MetricFloat16PipeActive: {}, MetricFloat32PipeActive: {}, MetricFloat64PipeActive: {}, MetricClocksEventReasons: {}, MetricXIDErrors: {}, MetricPowerViolation: {}, MetricThermalViolation: {}, MetricSMClock: {}, MetricMemClock: {}, }
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 NewServerMux ¶
func NewServerMux(containerMetricsHandler http.Handler, jvmMetricsHandler http.Handler) *http.ServeMux
NewServerMux creates the HTTP mux for the nodemon.
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 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.
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 ¶
HTTPClient abstracts *http.Client for testing.
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
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 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 ¶
MetricsQuerier provides on-demand GPU metrics.
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 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 ¶
WorkloadResolverConfig holds configuration for the workload resolver.