metrics

package
v0.0.0-...-71e741c Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricFamilyCpu        MetricFamily = "cpu"
	MetricFamilyFilesystem              = "filesystem"
	MetricFamilyMemory                  = "memory"
	MetricFamilyNetwork                 = "network"
	MetricFamilyGeneral                 = "general"
)
View Source
const (
	CustomMetricPrefix = "custom/"
)

Variables

View Source
var (
	LabelMetricSetType = LabelDescriptor{
		Key:         "type",
		Description: "Type of the metrics set (container, pod, namespace, node, cluster)",
	}
	MetricSetTypeSystemContainer  = "sys_container"
	MetricSetTypePodContainer     = "pod_container"
	MetricSetTypePod              = "pod"
	MetricSetTypeNamespace        = "ns"
	MetricSetTypeNode             = "node"
	MetricSetTypeCluster          = "cluster"
	MetricSetTypePersistentVolume = "persistent_volume"

	LabelCluster = LabelDescriptor{
		Key:         "cluster",
		Description: "The name of the kubernetes cluster",
	}
	LabelPodId = LabelDescriptor{
		Key:         "pod_id",
		Description: "The unique ID of the pod",
	}
	LabelPodName = LabelDescriptor{
		Key:         "pod_name",
		Description: "The name of the pod",
	}
	LabelNamespaceName = LabelDescriptor{
		Key:         "namespace_name",
		Description: "The name of the namespace",
	}
	LabelWorkloadName = LabelDescriptor{
		Key:         "workload_name",
		Description: "Workload name, derived from top level Deployment or DaemonSet",
	}
	LabelWorkloadKind = LabelDescriptor{
		Key:         "workload_kind",
		Description: "Workload Kind, derived from top level Deployment or DaemonSet",
	}
	LabelDesired = LabelDescriptor{
		Key:         "desired",
		Description: "The desired number for the Pod",
	}
	LabelAvailable = LabelDescriptor{
		Key:         "available",
		Description: "The available number for the Pod",
	}
	LabelReason = LabelDescriptor{
		Key:         "reason",
		Description: "The failure reason for the Pod",
	}
	LabelMessage = LabelDescriptor{
		Key:         "message",
		Description: "The failure message for the Pod",
	}
	LabelPodNamespaceUID = LabelDescriptor{
		Key:         "namespace_id",
		Description: "The UID of namespace of the pod",
	}
	LabelContainerName = LabelDescriptor{
		Key:         "container_name",
		Description: "User-provided name of the container or full container name for system containers",
	}
	LabelLabels = LabelDescriptor{
		Key:         "labels",
		Description: "Comma-separated list of user-provided labels",
	}
	LabelNodename = LabelDescriptor{
		Key:         "nodename",
		Description: "nodename where the container ran",
	}
	LabelNodeRole = LabelDescriptor{
		Key:         "node_role",
		Description: "Node role worker or control-plane",
	}
	LabelHostname = LabelDescriptor{
		Key:         "hostname",
		Description: "Hostname where the container ran",
	}
	LabelResourceID = LabelDescriptor{
		Key:         "resource_id",
		Description: "Identifier(s) specific to a metric",
	}
	LabelHostID = LabelDescriptor{
		Key:         "host_id",
		Description: "Identifier specific to a host. Set by cloud provider or user",
	}
	LabelContainerBaseImage = LabelDescriptor{
		Key:         "container_base_image",
		Description: "User-defined image name that is run inside the container",
	}
	// The label is populated only for GCM
	LabelCustomMetricName = LabelDescriptor{
		Key:         "custom_metric_name",
		Description: "User-defined name of the exported custom metric",
	}
	LabelGCEResourceID = LabelDescriptor{
		Key:         "resource_id",
		Description: "Resource id for nodes specific for GCE.",
	}
	LabelGCEResourceType = LabelDescriptor{
		Key:         "resource_type",
		Description: "Resource types for nodes specific for GCE.",
	}
	LabelNodeSchedulable = LabelDescriptor{
		Key:         "schedulable",
		Description: "Node schedulable status.",
	}
	LabelVolumeName = LabelDescriptor{
		Key:         "volume_name",
		Description: "The name of the volume.",
	}
	LabelPVCName = LabelDescriptor{
		Key:         "pvc_name",
		Description: "The name of the persistent volume claim.",
	}
	LabelAcceleratorMake = LabelDescriptor{
		Key:         "make",
		Description: "Make of the accelerator (nvidia, amd, google etc.)",
	}
	LabelAcceleratorModel = LabelDescriptor{
		Key:         "model",
		Description: "Model of the accelerator (tesla-p100, tesla-k80 etc.)",
	}
	LabelAcceleratorID = LabelDescriptor{
		Key:         "accelerator_id",
		Description: "ID of the accelerator",
	}
)

Metrics computed based on cluster state using Kubernetes API.

AllAggregations is the set of all supported aggregations

View Source
var MetricAcceleratorDutyCycle = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "accelerator/duty_cycle",
		Description: "Percent of time over the past sample period (10s) during which the accelerator was actively processing",
		Labels:      acceleratorLabels,
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		if len(stat.Accelerators) == 0 {
			return false
		}

		return true
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Accelerators))
		for _, ac := range stat.Accelerators {
			result = append(result, LabeledValue{
				Name: "accelerator/duty_cycle",
				Labels: map[string]string{
					LabelAcceleratorMake.Key:  ac.Make,
					LabelAcceleratorModel.Key: ac.Model,
					LabelAcceleratorID.Key:    ac.ID,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(ac.DutyCycle),
				},
			})
		}
		return result
	},
}
View Source
var MetricAcceleratorMemoryTotal = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "accelerator/memory_total",
		Description: "Total accelerator memory (in bytes)",
		Labels:      acceleratorLabels,
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		if len(stat.Accelerators) == 0 {
			return false
		}

		return true
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Accelerators))
		for _, ac := range stat.Accelerators {
			result = append(result, LabeledValue{
				Name: "accelerator/memory_total",
				Labels: map[string]string{
					LabelAcceleratorMake.Key:  ac.Make,
					LabelAcceleratorModel.Key: ac.Model,
					LabelAcceleratorID.Key:    ac.ID,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(ac.MemoryTotal),
				},
			})
		}
		return result
	},
}
View Source
var MetricAcceleratorMemoryUsed = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "accelerator/memory_used",
		Description: "Total accelerator memory allocated (in bytes)",
		Labels:      acceleratorLabels,
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		if len(stat.Accelerators) == 0 {
			return false
		}

		return true
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Accelerators))
		for _, ac := range stat.Accelerators {
			result = append(result, LabeledValue{
				Name: "accelerator/memory_used",
				Labels: map[string]string{
					LabelAcceleratorMake.Key:  ac.Make,
					LabelAcceleratorModel.Key: ac.Model,
					LabelAcceleratorID.Key:    ac.ID,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(ac.MemoryUsed),
				},
			})
		}
		return result
	},
}
View Source
var MetricContainerStatus = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "status",
		Description: "Container status",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricCpuLimit = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/limit",
		Description: "CPU hard limit in millicores.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricCpuLoad = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/load",
		Description: "CPU load",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasCpu
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Cpu.LoadAverage)}
	},
}
View Source
var MetricCpuRequest = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/request",
		Description: "CPU request (the guaranteed amount of resources) in millicores. This metric is Kubernetes specific.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}

Definition of Additional Metrics.

View Source
var MetricCpuUsage = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/usage",
		Description: "Cumulative CPU usage on all cores",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Nanoseconds,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasCpu
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Cpu.Usage.Total)}
	},
}
View Source
var MetricCpuUsageCores = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/usage_millicores",
		Description: "Cumulative CPU usage on all cores averaged over time window",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Millicores,
	},
}
View Source
var MetricCpuUsageRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/usage_rate",
		Description: "CPU usage on all cores in millicores",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}

Definition of Rate Metrics.

View Source
var MetricDiskIORead = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "disk/io_read_bytes",
		Description: "Cumulative number of bytes read over disk",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasDiskIo
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.DiskIo.IoServiceBytes))
		for _, ioServiceBytesPerPartition := range stat.DiskIo.IoServiceBytes {
			resourceIDKey := ioServiceBytesPerPartition.Device
			if resourceIDKey == "" {
				resourceIDKey = fmt.Sprintf("%d:%d", ioServiceBytesPerPartition.Major, ioServiceBytesPerPartition.Minor)
			}

			var value uint64
			if v, exists := ioServiceBytesPerPartition.Stats["Read"]; exists {
				value = v
			}

			result = append(result, LabeledValue{
				Name: "disk/io_read_bytes",
				Labels: map[string]string{
					LabelResourceID.Key: resourceIDKey,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(value),
				},
			})
		}
		return result
	},
}
View Source
var MetricDiskIOReadRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "disk/io_read_bytes_rate",
		Description: "Rate of bytes read over disk in bytes per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
		Labels:      metricLabels,
	},
}
View Source
var MetricDiskIOWrite = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "disk/io_write_bytes",
		Description: "Cumulative number of bytes write over disk",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasDiskIo
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.DiskIo.IoServiceBytes))
		for _, ioServiceBytesPerPartition := range stat.DiskIo.IoServiceBytes {
			resourceIDKey := ioServiceBytesPerPartition.Device
			if resourceIDKey == "" {
				resourceIDKey = fmt.Sprintf("%d:%d", ioServiceBytesPerPartition.Major, ioServiceBytesPerPartition.Minor)
			}

			var value uint64
			if v, exists := ioServiceBytesPerPartition.Stats["Write"]; exists {
				value = v
			}

			result = append(result, LabeledValue{
				Name: "disk/io_write_bytes",
				Labels: map[string]string{
					LabelResourceID.Key: resourceIDKey,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(value),
				},
			})
		}
		return result
	},
}
View Source
var MetricDiskIOWriteRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "disk/io_write_bytes_rate",
		Description: "Rate of bytes written over disk in bytes per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
		Labels:      metricLabels,
	},
}
View Source
var MetricEphemeralStorageLimit = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/limit",
		Description: "ephemeral storage hard limit in bytes.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
}
View Source
var MetricEphemeralStorageRequest = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/request",
		Description: "ephemeral storage request (the guaranteed amount of resources) in bytes. This metric is Kubernetes specific.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
}
View Source
var MetricEphemeralStorageUsage = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/usage",
		Description: "Ephemeral storage usage",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
}
View Source
var MetricFilesystemAvailable = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "filesystem/available",
		Description: "The number of available bytes remaining in a the filesystem",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasFilesystem
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Filesystem))
		for _, fs := range stat.Filesystem {
			result = append(result, LabeledValue{
				Name: "filesystem/available",
				Labels: map[string]string{
					LabelResourceID.Key: fs.Device,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(fs.Available),
				},
			})
		}
		return result
	},
}
View Source
var MetricFilesystemInodes = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "filesystem/inodes",
		Description: "Total number of inodes on a filesystem",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasFilesystem
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := []LabeledValue{}
		for _, fs := range stat.Filesystem {
			if fs.HasInodes {
				result = append(result, LabeledValue{
					Name: "filesystem/inodes",
					Labels: map[string]string{
						LabelResourceID.Key: fs.Device,
					},
					Value: Value{
						ValueType: ValueInt64,
						IntValue:  int64(fs.Inodes),
					},
				})
			}
		}
		return result
	},
}
View Source
var MetricFilesystemInodesFree = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "filesystem/inodes_free",
		Description: "Free number of inodes on a filesystem",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasFilesystem
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := []LabeledValue{}
		for _, fs := range stat.Filesystem {
			if fs.HasInodes {
				result = append(result, LabeledValue{
					Name: "filesystem/inodes_free",
					Labels: map[string]string{
						LabelResourceID.Key: fs.Device,
					},
					Value: Value{
						ValueType: ValueInt64,
						IntValue:  int64(fs.InodesFree),
					},
				})
			}
		}
		return result
	},
}
View Source
var MetricFilesystemLimit = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "filesystem/limit",
		Description: "The total size of filesystem in bytes",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasFilesystem
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Filesystem))
		for _, fs := range stat.Filesystem {
			result = append(result, LabeledValue{
				Name: "filesystem/limit",
				Labels: map[string]string{
					LabelResourceID.Key: fs.Device,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(fs.Limit),
				},
			})
		}
		return result
	},
}
View Source
var MetricFilesystemUsage = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "filesystem/usage",
		Description: "Total number of bytes consumed on a filesystem",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
		Labels:      metricLabels,
	},
	HasLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) bool {
		return spec.HasFilesystem
	},
	GetLabeledMetric: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []LabeledValue {
		result := make([]LabeledValue, 0, len(stat.Filesystem))
		for _, fs := range stat.Filesystem {
			result = append(result, LabeledValue{
				Name: "filesystem/usage",
				Labels: map[string]string{
					LabelResourceID.Key: fs.Device,
				},
				Value: Value{
					ValueType: ValueInt64,
					IntValue:  int64(fs.Usage),
				},
			})
		}
		return result
	},
}
View Source
var MetricMemoryCache = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/cache",
		Description: "Cache memory",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.Cache)}
	},
}
View Source
var MetricMemoryLimit = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/limit",
		Description: "Memory hard limit in bytes.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
}
View Source
var MetricMemoryMajorPageFaults = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/major_page_faults",
		Description: "Number of major page faults",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.ContainerData.Pgmajfault)}
	},
}
View Source
var MetricMemoryMajorPageFaultsRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/major_page_faults_rate",
		Description: "Rate of major page faults in counts per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricMemoryPageFaults = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/page_faults",
		Description: "Number of page faults",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.ContainerData.Pgfault)}
	},
}
View Source
var MetricMemoryPageFaultsRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/page_faults_rate",
		Description: "Rate of page faults in counts per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricMemoryRSS = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/rss",
		Description: "RSS memory",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.RSS)}
	},
}
View Source
var MetricMemoryRequest = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/request",
		Description: "Memory request (the guaranteed amount of resources) in bytes. This metric is Kubernetes specific.",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
}
View Source
var MetricMemoryUsage = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/usage",
		Description: "Total memory usage",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.Usage)}
	},
}
View Source
var MetricMemoryWorkingSet = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/working_set",
		Description: "Total working set usage. Working set is the memory being used and not easily dropped by the kernel",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasMemory
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(stat.Memory.WorkingSet)}
	},
}
View Source
var MetricNetworkRx = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/rx",
		Description: "Cumulative number of bytes received over the network",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasNetwork
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		var rxBytes uint64 = 0
		for _, interfaceStat := range stat.Network.Interfaces {
			rxBytes += interfaceStat.RxBytes
		}
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(rxBytes),
		}
	},
}
View Source
var MetricNetworkRxErrors = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/rx_errors",
		Description: "Cumulative number of errors while receiving over the network",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasNetwork
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		var rxErrors uint64 = 0
		for _, interfaceStat := range stat.Network.Interfaces {
			rxErrors += interfaceStat.RxErrors
		}
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(rxErrors),
		}
	},
}
View Source
var MetricNetworkRxErrorsRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/rx_errors_rate",
		Description: "Rate of errors sending over the network in errors per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNetworkRxRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/rx_rate",
		Description: "Rate of bytes received over the network in bytes per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNetworkTx = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/tx",
		Description: "Cumulative number of bytes sent over the network",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Bytes,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasNetwork
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		var txBytes uint64 = 0
		for _, interfaceStat := range stat.Network.Interfaces {
			txBytes += interfaceStat.TxBytes
		}
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(txBytes),
		}
	},
}
View Source
var MetricNetworkTxErrors = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/tx_errors",
		Description: "Cumulative number of errors while sending over the network",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Count,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return spec.HasNetwork
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		var txErrors uint64 = 0
		for _, interfaceStat := range stat.Network.Interfaces {
			txErrors += interfaceStat.TxErrors
		}
		return Value{
			ValueType: ValueInt64,
			IntValue:  int64(txErrors),
		}
	},
}
View Source
var MetricNetworkTxErrorsRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/tx_errors_rate",
		Description: "Rate of errors transmitting over the network in errors per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNetworkTxRate = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "network/tx_rate",
		Description: "Rate of bytes transmitted over the network in bytes per second",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeCondition = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "status/condition",
		Description: "Node conditions",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricNodeCpuAllocatable = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/node_allocatable",
		Description: "Cpu allocatable of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeCpuCapacity = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/node_capacity",
		Description: "Cpu capacity of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeCpuReservation = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/node_reservation",
		Description: "Share of cpu that is reserved on the node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeCpuUtilization = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "cpu/node_utilization",
		Description: "Cpu utilization as a share of node capacity",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeEphemeralStorageAllocatable = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/node_allocatable",
		Description: "Ephemeral storage allocatable of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeEphemeralStorageCapacity = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/node_capacity",
		Description: "Ephemeral storage capacity of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeEphemeralStorageReservation = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/node_reservation",
		Description: "Share of ephemeral storage that is reserved on the node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeEphemeralStorageUtilization = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "ephemeral_storage/node_utilization",
		Description: "Ephemeral storage utilization as a share of storage capacity",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeMemoryAllocatable = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/node_allocatable",
		Description: "Memory allocatable of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeMemoryCapacity = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/node_capacity",
		Description: "Memory capacity of a node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeMemoryReservation = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/node_reservation",
		Description: "Share of memory that is reserved on the node",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricNodeMemoryUtilization = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "memory/node_utilization",
		Description: "Memory utilization as a share of memory capacity",
		Type:        Gauge,
		ValueType:   ValueFloat,
		Units:       Count,
	},
}
View Source
var MetricPodContainerCount = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "pod_container/count",
		Description: "Count of pod containers",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricPodCount = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "pod/count",
		Description: "Count of pods",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}

Aggregated count metrics

View Source
var MetricPodPhase = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "status/phase",
		Description: "Phase of pods",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricRestartCount = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "restart_count",
		Description: "Number of container restarts",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}
View Source
var MetricUptime = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "uptime",
		Description: "Number of milliseconds since the container was started",
		Type:        Cumulative,
		ValueType:   ValueInt64,
		Units:       Milliseconds,
	},
	HasValue: func(spec *cadvisor.ContainerSpec) bool {
		return !spec.CreationTime.IsZero()
	},
	GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) Value {
		return Value{
			ValueType: ValueInt64,
			IntValue:  time.Since(spec.CreationTime).Nanoseconds() / time.Millisecond.Nanoseconds()}
	},
}

Definition of Standard Metrics.

View Source
var MetricWorkloadStatus = Metric{
	MetricDescriptor: MetricDescriptor{
		Name:        "workload/status",
		Description: "Status of the workload",
		Type:        Gauge,
		ValueType:   ValueInt64,
		Units:       Count,
	},
}

MultiTypedAggregations is the list of aggregations that can be either float or int

Computed based on corresponding StandardMetrics.

View Source
var RateMetricsMapping = map[string]Metric{
	MetricCpuUsage.MetricDescriptor.Name:              MetricCpuUsageRate,
	MetricMemoryPageFaults.MetricDescriptor.Name:      MetricMemoryPageFaultsRate,
	MetricMemoryMajorPageFaults.MetricDescriptor.Name: MetricMemoryMajorPageFaultsRate,
	MetricNetworkRx.MetricDescriptor.Name:             MetricNetworkRxRate,
	MetricNetworkRxErrors.MetricDescriptor.Name:       MetricNetworkRxErrorsRate,
	MetricNetworkTx.MetricDescriptor.Name:             MetricNetworkTxRate,
	MetricNetworkTxErrors.MetricDescriptor.Name:       MetricNetworkTxErrorsRate,
	MetricDiskIORead.MetricDescriptor.Name:            MetricDiskIOReadRate,
	MetricDiskIOWrite.MetricDescriptor.Name:           MetricDiskIOWriteRate}

Maps from resource name to the metric that tracks container resource request on that resource. The name of the metric is ResourceName/request where ResourceName is the name of the resource requested in container resource requests.

Provided by Kubelet/cadvisor.

Functions

func GcmLabels

func GcmLabels() map[string]LabelDescriptor

func GcmNodeAutoscalingLabels

func GcmNodeAutoscalingLabels() map[string]LabelDescriptor

func IsNodeAutoscalingMetric

func IsNodeAutoscalingMetric(name string) bool

Types

type AggregationType

type AggregationType string
var (
	AggregationTypeAverage      AggregationType = "average"
	AggregationTypeMaximum      AggregationType = "max"
	AggregationTypeMinimum      AggregationType = "min"
	AggregationTypeMedian       AggregationType = "median"
	AggregationTypeCount        AggregationType = "count"
	AggregationTypePercentile50 AggregationType = "50-perc"
	AggregationTypePercentile95 AggregationType = "95-perc"
	AggregationTypePercentile99 AggregationType = "99-perc"
)

type AggregationValue

type AggregationValue struct {
	Count *uint64

	Aggregations map[AggregationType]Value
}

AggregationValue is a description of aggregated Values over time

type AsHistoricalSource

type AsHistoricalSource interface {
	// Historical returns the historical data access interface for this sink
	Historical() HistoricalSource
}

AsHistoricalSource represents sinks which support a historical access interface

type Batch

type Batch struct {
	Timestamp time.Time
	Sets      map[ResourceKey]*Set
	Metrics   []wf.Metric
}

Batch contains sets of metrics tied to specific k8s resources and other more general wavefront points

func (*Batch) Points

func (b *Batch) Points() int

type ConfigurableSourceProvider

type ConfigurableSourceProvider interface {
	Configure(interval, timeout time.Duration)
}

type DefaultSourceProvider

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

DefaultSourceProvider handle the common providers configuration

func (*DefaultSourceProvider) CollectionInterval

func (sp *DefaultSourceProvider) CollectionInterval() time.Duration

CollectionInterval return the provider collection interval configuration

func (*DefaultSourceProvider) Configure

func (sp *DefaultSourceProvider) Configure(interval, timeout time.Duration)

Configure the 'collectionInterval' and 'timeout' values

func (*DefaultSourceProvider) Timeout

func (sp *DefaultSourceProvider) Timeout() time.Duration

Timeout return the provider timeout configuration

type HistoricalKey

type HistoricalKey struct {
	// ObjectType specifies which type of object this is for (pod, namespace, etc)
	// It should be one of the MetricSetType* labels.
	ObjectType string

	// NodeName is used for node and system-container metrics
	NodeName string
	// NamespaceName is used for namespace, pod, and pod-container metrics
	NamespaceName string
	// PodName is used for pod and pod-container metrics
	PodName string
	// ContainerName is used for system-container and pod-container metrics
	ContainerName string
	// PodId may be used in place of the combination of PodName and NamespaceName for pod and pod-container metrics
	PodId string
}

HistoricalKey is an identifier pointing to a particular object. Is is composed of an object type (pod, namespace, container, etc) as well as a series of fields which identify that object.

func (*HistoricalKey) String

func (key *HistoricalKey) String() string

type HistoricalSource

type HistoricalSource interface {
	// GetMetric retrieves the given metric for one or more objects (specified by metricKeys) of
	// the same type, within the given time interval.  A start time of zero indicates no starting bound,
	// while an end time of zero indicates no ending bound.
	GetMetric(metricName string, metricKeys []HistoricalKey, start, end time.Time) (map[HistoricalKey][]TimestampedMetricValue, error)

	// GetLabeledMetric retrieves the given labeled metric.  Otherwise, it functions identically to GetMetric.
	GetLabeledMetric(metricName string, labels map[string]string, metricKeys []HistoricalKey, start, end time.Time) (map[HistoricalKey][]TimestampedMetricValue, error)

	// GetAggregation fetches the given aggregations for one or more objects (specified by metricKeys) of
	// the same type, within the given time interval, calculated over a series of buckets.  The start time,
	// end time, and bucket size may be zero.  A start time of zero indicates no starting bound, while and
	// end time of zero indicates no ending bound (effectively meaning up to the latest metrics, but not metrics
	// from the future).  A bucket size of zero indicates that only a single bucket spanning the entire specified
	// time range should be returned.
	GetAggregation(metricName string, aggregations []AggregationType, metricKeys []HistoricalKey, start, end time.Time, bucketSize time.Duration) (map[HistoricalKey][]TimestampedAggregationValue, error)

	// GetLabeledAggregation fetches a the given aggregations for a labeled metric instead of a normal metric.
	// Otherwise, it functions identically to GetAggregation.
	GetLabeledAggregation(metricName string, labels map[string]string, aggregations []AggregationType, metricKeys []HistoricalKey, start, end time.Time, bucketSize time.Duration) (map[HistoricalKey][]TimestampedAggregationValue, error)

	// GetMetricNames retrieves the available metric names for the given object
	GetMetricNames(metricKey HistoricalKey) ([]string, error)

	// GetNodes retrieves the list of nodes in the cluster
	GetNodes() ([]string, error)
	// GetNamespaces retrieves the list of namespaces in the cluster
	GetNamespaces() ([]string, error)
	// GetPodsFromNamespace retrieves the list of pods in a given namespace
	GetPodsFromNamespace(namespace string) ([]string, error)
	// GetSystemContainersFromNode retrieves the list of free containers for a given node
	GetSystemContainersFromNode(node string) ([]string, error)
}

HistoricalSource allows for retrieval of historical metrics and aggregations from sinks

type LabelDescriptor

type LabelDescriptor struct {
	// Key to use for the label.
	Key string `json:"key,omitempty"`

	// Description of the label.
	Description string `json:"description,omitempty"`
}

func CommonLabels

func CommonLabels() []LabelDescriptor

func ContainerLabels

func ContainerLabels() []LabelDescriptor

func MetricLabels

func MetricLabels() []LabelDescriptor

func PodLabels

func PodLabels() []LabelDescriptor

func SupportedLabels

func SupportedLabels() []LabelDescriptor

type LabeledValue

type LabeledValue struct {
	Name   string
	Labels map[string]string
	Value
}

LabeledValue is a metric value that is either a float64 or an int64 and that has it's own name and values

func (*LabeledValue) GetValue

func (l *LabeledValue) GetValue() interface{}

type Metric

type Metric struct {
	MetricDescriptor

	// Returns whether this metric is present.
	HasValue func(*cadvisor.ContainerSpec) bool

	// Returns a slice of internal point objects that contain metric values and associated labels.
	GetValue func(*cadvisor.ContainerSpec, *cadvisor.ContainerStats) Value

	// Returns whether this metric is present.
	HasLabeledMetric func(*cadvisor.ContainerSpec, *cadvisor.ContainerStats) bool

	// Returns a slice of internal point objects that contain metric values and associated labels.
	GetLabeledMetric func(*cadvisor.ContainerSpec, *cadvisor.ContainerStats) []LabeledValue
}

Metric represents a resource usage stat metric.

type MetricDescriptor

type MetricDescriptor struct {
	// The unique name of the metric.
	Name string `json:"name,omitempty"`

	// Description of the metric.
	Description string `json:"description,omitempty"`

	// Descriptor of the labels specific to this metric.
	Labels []LabelDescriptor `json:"labels,omitempty"`

	// Type and value of metric data.
	Type      Type      `json:"type,omitempty"`
	ValueType ValueType `json:"value_type,omitempty"`
	Units     Unit      `json:"units,omitempty"`
}

type MetricFamily

type MetricFamily string

func MetricFamilyForName

func MetricFamilyForName(metricName string) MetricFamily

type Processor

type Processor interface {
	Name() string
	Process(*Batch) (*Batch, error)
}

Processor should not store any references to anything in *Batch because it is assumed that Processor does not own that memory. Other components are free to mutably update *Batch after Process is run.

type ProviderFactory

type ProviderFactory interface {
	Name() string
	Build(cfg interface{}) (SourceProvider, error)
}

type ProviderHandler

type ProviderHandler interface {
	AddProvider(provider SourceProvider)
	DeleteProvider(name string)
}

ProviderHandler is an interface for dynamically adding and removing MetricSourceProviders

type ResourceKey

type ResourceKey string

ResourceKey is used to group metric sets by a specific k8s resource. A ResourceKey should be treated as an opaque identifier. A ResourceKey should not be serialized as its format is not public.

func ClusterKey

func ClusterKey() ResourceKey

func NamespaceKey

func NamespaceKey(namespace string) ResourceKey

func NodeContainerKey

func NodeContainerKey(node, container string) ResourceKey

func NodeKey

func NodeKey(node string) ResourceKey

func PodContainerKey

func PodContainerKey(namespace, podName, containerName string) ResourceKey

func PodKey

func PodKey(namespace, podName string) ResourceKey

func WorkloadStatusPodKey

func WorkloadStatusPodKey(namespace, podName string) ResourceKey

func (ResourceKey) Append

func (s ResourceKey) Append(t ResourceKey) ResourceKey

func (ResourceKey) String

func (s ResourceKey) String() string

type ResourceKeys

type ResourceKeys []ResourceKey

func (ResourceKeys) Len

func (s ResourceKeys) Len() int

func (ResourceKeys) Less

func (s ResourceKeys) Less(i, j int) bool

func (ResourceKeys) Swap

func (s ResourceKeys) Swap(i, j int)

type Set

type Set struct {
	// CollectionStartTime is a time since when the metrics are collected for this entity.
	// It is affected by events like entity (e.g. pod) creation, entity restart (e.g. for container),
	// Kubelet restart.
	CollectionStartTime time.Time
	// EntityCreateTime is a time of entity creation and persists through entity restarts and
	// Kubelet restarts.
	EntityCreateTime time.Time
	ScrapeTime       time.Time
	Values           map[string]Value
	Labels           map[string]string
	LabeledValues    []LabeledValue
}

Set is a collection of metrics tied to a specific resource

func (*Set) FindLabels

func (s *Set) FindLabels(name string) (map[string]string, bool)

FindLabels returns the labels for a given metric name

func (*Set) Points

func (s *Set) Points() int

type Sink

type Sink interface {
	// Export data to the external storage. The function should be synchronous/blocking and finish only
	// after the given Batch was written. This will allow sink manager to push data only to these
	// sinks that finished writing the previous data.
	Export(*Batch)
}

Sink exports metric batches

type Source

type Source interface {
	AutoDiscovered() bool
	Name() string
	Scrape() (*Batch, error)
	Cleanup()
}

Source produces metric batches

func NewErrorDecorator

func NewErrorDecorator(src Source, errFunc func(err error) error) Source

NewErrorDecorator creates a MetricSource that transforms Scrape errors

type SourceProvider

type SourceProvider interface {
	GetMetricsSources() []Source
	Name() string
	CollectionInterval() time.Duration
	Timeout() time.Duration
}

SourceProvider produces metric sources

type TimestampedAggregationValue

type TimestampedAggregationValue struct {
	// Timestamp is the start time of the bucket
	Timestamp time.Time

	// BucketSize is the duration of the bucket
	BucketSize time.Duration

	AggregationValue
}

TimestampedAggregationValue is an aggregation value with an associated timestamp and bucket size

type TimestampedMetricValue

type TimestampedMetricValue struct {
	Value
	Timestamp time.Time
}

TimestampedMetricValue is a metric value with an associated timestamp

type Type

type Type int8
const (
	Cumulative Type = iota
	Gauge
	Delta
)

func (*Type) String

func (t *Type) String() string

type Unit

type Unit int8
const (
	Count Unit = iota
	Bytes
	Milliseconds
	Nanoseconds
	Millicores
)

func (Unit) String

func (u Unit) String() string

type Value

type Value struct {
	IntValue   int64
	FloatValue float64
	ValueType  ValueType
}

Value represents a metric value that is either a float64 or an int64

func (*Value) GetValue

func (v *Value) GetValue() interface{}

func (*Value) IsZeroValue

func (v *Value) IsZeroValue() bool

type ValueType

type ValueType int8

ValueType is used to discriminate whether a Value is an int64 or a float64

const (
	ValueInt64 ValueType = iota
	ValueFloat
)

func (*ValueType) String

func (valueType *ValueType) String() string

Jump to

Keyboard shortcuts

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