|
|
@@ -27,11 +27,14 @@ type KubeNodeCollector struct {
|
|
|
// Describe sends the super-set of all possible descriptors of metrics
|
|
|
// collected by this Collector.
|
|
|
func (nsac KubeNodeCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
|
+ ch <- prometheus.NewDesc("kube_node_status_capacity", "Node resource capacity.", []string{}, nil)
|
|
|
ch <- prometheus.NewDesc("kube_node_status_capacity_memory_bytes", "node capacity memory bytes", []string{}, nil)
|
|
|
ch <- prometheus.NewDesc("kube_node_status_capacity_cpu_cores", "node capacity cpu cores", []string{}, nil)
|
|
|
+ ch <- prometheus.NewDesc("kube_node_status_allocatable", "The allocatable for different resources of a node that are available for scheduling.", []string{}, nil)
|
|
|
+ ch <- prometheus.NewDesc("kube_node_status_allocatable_cpu_cores", "The allocatable cpu cores.", []string{}, nil)
|
|
|
+ ch <- prometheus.NewDesc("kube_node_status_allocatable_memory_bytes", "The allocatable memory in bytes.", []string{}, nil)
|
|
|
ch <- prometheus.NewDesc("kube_node_labels", "all labels for each node prefixed with label_", []string{}, nil)
|
|
|
ch <- prometheus.NewDesc("kube_node_status_condition", "The condition of a cluster node.", []string{}, nil)
|
|
|
- ch <- prometheus.NewDesc("kube_node_status_allocatable", "The allocatable for different resources of a node that are available for scheduling.", []string{}, nil)
|
|
|
}
|
|
|
|
|
|
// Collect is called by the Prometheus registry when collecting metrics.
|
|
|
@@ -40,18 +43,29 @@ func (nsac KubeNodeCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
for _, node := range nodes {
|
|
|
nodeName := node.GetName()
|
|
|
|
|
|
- // k8s.io/apimachinery/pkg/api/resource/amount.go and
|
|
|
- // k8s.io/apimachinery/pkg/api/resource/quantity.go for
|
|
|
- // details on the "amount" API. See
|
|
|
- // https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-types
|
|
|
- // for the units of memory and CPU.
|
|
|
- memoryBytes := node.Status.Capacity.Memory().Value()
|
|
|
- ch <- newKubeNodeStatusCapacityMemoryBytesMetric(nodeName, memoryBytes, "kube_node_status_capacity_memory_bytes", nil, nil)
|
|
|
+ // Node Capacity
|
|
|
+ for resourceName, quantity := range node.Status.Capacity {
|
|
|
+ resource, unit, value := toResourceUnitValue(resourceName, quantity)
|
|
|
+
|
|
|
+ // failed to parse the resource type
|
|
|
+ if resource == "" {
|
|
|
+ log.DedupedWarningf(5, "Failed to parse resource units and quantity for resource: %s", resourceName)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // KSM v1 Emission
|
|
|
+ if resource == "cpu" {
|
|
|
+ ch <- newKubeNodeStatusCapacityCPUCoresMetric("kube_node_status_capacity_cpu_cores", nodeName, value)
|
|
|
+
|
|
|
+ }
|
|
|
+ if resource == "memory" {
|
|
|
+ ch <- newKubeNodeStatusCapacityMemoryBytesMetric("kube_node_status_capacity_memory_bytes", nodeName, value)
|
|
|
+ }
|
|
|
|
|
|
- cpuCores := float64(node.Status.Capacity.Cpu().MilliValue()) / 1000
|
|
|
- ch <- newKubeNodeStatusCapacityCPUCoresMetric(nodeName, cpuCores, "kube_node_status_capacity_cpu_cores", nil, nil)
|
|
|
+ ch <- newKubeNodeStatusCapacityMetric("kube_node_status_capacity", nodeName, resource, unit, value)
|
|
|
+ }
|
|
|
|
|
|
- // allocatable resources
|
|
|
+ // Node Allocatable Resources
|
|
|
for resourceName, quantity := range node.Status.Allocatable {
|
|
|
resource, unit, value := toResourceUnitValue(resourceName, quantity)
|
|
|
|
|
|
@@ -61,6 +75,15 @@ func (nsac KubeNodeCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ // KSM v1 Emission
|
|
|
+ if resource == "cpu" {
|
|
|
+ ch <- newKubeNodeStatusAllocatableCPUCoresMetric("kube_node_status_allocatable_cpu_cores", nodeName, value)
|
|
|
+
|
|
|
+ }
|
|
|
+ if resource == "memory" {
|
|
|
+ ch <- newKubeNodeStatusAllocatableMemoryBytesMetric("kube_node_status_allocatable_memory_bytes", nodeName, value)
|
|
|
+ }
|
|
|
+
|
|
|
ch <- newKubeNodeStatusAllocatableMetric("kube_node_status_allocatable", nodeName, resource, unit, value)
|
|
|
}
|
|
|
|
|
|
@@ -81,6 +104,66 @@ func (nsac KubeNodeCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+// KubeNodeStatusCapacityMetric
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+
|
|
|
+// KubeNodeStatusCapacityMetric is a prometheus.Metric
|
|
|
+type KubeNodeStatusCapacityMetric struct {
|
|
|
+ fqName string
|
|
|
+ help string
|
|
|
+ resource string
|
|
|
+ unit string
|
|
|
+ node string
|
|
|
+ value float64
|
|
|
+}
|
|
|
+
|
|
|
+// Creates a new KubeNodeStatusCapacityMetric, implementation of prometheus.Metric
|
|
|
+func newKubeNodeStatusCapacityMetric(fqname, node, resource, unit string, value float64) KubeNodeStatusCapacityMetric {
|
|
|
+ return KubeNodeStatusCapacityMetric{
|
|
|
+ fqName: fqname,
|
|
|
+ help: "kube_node_status_capacity node capacity",
|
|
|
+ node: node,
|
|
|
+ resource: resource,
|
|
|
+ unit: unit,
|
|
|
+ value: value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Desc returns the descriptor for the Metric. This method idempotently
|
|
|
+// returns the same descriptor throughout the lifetime of the Metric.
|
|
|
+func (kpcrr KubeNodeStatusCapacityMetric) Desc() *prometheus.Desc {
|
|
|
+ l := prometheus.Labels{
|
|
|
+ "node": kpcrr.node,
|
|
|
+ "resource": kpcrr.resource,
|
|
|
+ "unit": kpcrr.unit,
|
|
|
+ }
|
|
|
+ return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
|
|
|
+}
|
|
|
+
|
|
|
+// Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
|
|
|
+func (kpcrr KubeNodeStatusCapacityMetric) Write(m *dto.Metric) error {
|
|
|
+ m.Gauge = &dto.Gauge{
|
|
|
+ Value: &kpcrr.value,
|
|
|
+ }
|
|
|
+
|
|
|
+ m.Label = []*dto.LabelPair{
|
|
|
+ {
|
|
|
+ Name: toStringPtr("node"),
|
|
|
+ Value: &kpcrr.node,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Name: toStringPtr("resource"),
|
|
|
+ Value: &kpcrr.resource,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Name: toStringPtr("unit"),
|
|
|
+ Value: &kpcrr.unit,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
//--------------------------------------------------------------------------
|
|
|
// KubeNodeStatusCapacityMemoryBytesMetric
|
|
|
//--------------------------------------------------------------------------
|
|
|
@@ -89,23 +172,19 @@ func (nsac KubeNodeCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
// a duplicate of the deprecated kube-state-metrics metric
|
|
|
// kube_node_status_capacity_memory_bytes
|
|
|
type KubeNodeStatusCapacityMemoryBytesMetric struct {
|
|
|
- fqName string
|
|
|
- help string
|
|
|
- labelNames []string
|
|
|
- labelValues []string
|
|
|
- bytes int64
|
|
|
- node string
|
|
|
+ fqName string
|
|
|
+ help string
|
|
|
+ bytes float64
|
|
|
+ node string
|
|
|
}
|
|
|
|
|
|
// Creates a new KubeNodeStatusCapacityMemoryBytesMetric, implementation of prometheus.Metric
|
|
|
-func newKubeNodeStatusCapacityMemoryBytesMetric(node string, bytes int64, fqname string, labelNames []string, labelValues []string) KubeNodeStatusCapacityMemoryBytesMetric {
|
|
|
+func newKubeNodeStatusCapacityMemoryBytesMetric(fqname string, node string, bytes float64) KubeNodeStatusCapacityMemoryBytesMetric {
|
|
|
return KubeNodeStatusCapacityMemoryBytesMetric{
|
|
|
- fqName: fqname,
|
|
|
- labelNames: labelNames,
|
|
|
- labelValues: labelValues,
|
|
|
- help: "kube_node_status_capacity_memory_bytes Node Capacity Memory Bytes",
|
|
|
- bytes: bytes,
|
|
|
- node: node,
|
|
|
+ fqName: fqname,
|
|
|
+ help: "kube_node_status_capacity_memory_bytes Node Capacity Memory Bytes",
|
|
|
+ node: node,
|
|
|
+ bytes: bytes,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -113,30 +192,21 @@ func newKubeNodeStatusCapacityMemoryBytesMetric(node string, bytes int64, fqname
|
|
|
// returns the same descriptor throughout the lifetime of the Metric.
|
|
|
func (nam KubeNodeStatusCapacityMemoryBytesMetric) Desc() *prometheus.Desc {
|
|
|
l := prometheus.Labels{"node": nam.node}
|
|
|
- return prometheus.NewDesc(nam.fqName, nam.help, nam.labelNames, l)
|
|
|
+ return prometheus.NewDesc(nam.fqName, nam.help, []string{}, l)
|
|
|
}
|
|
|
|
|
|
// Write encodes the Metric into a "Metric" Protocol Buffer data
|
|
|
// transmission object.
|
|
|
func (nam KubeNodeStatusCapacityMemoryBytesMetric) Write(m *dto.Metric) error {
|
|
|
- h := float64(nam.bytes)
|
|
|
m.Gauge = &dto.Gauge{
|
|
|
- Value: &h,
|
|
|
+ Value: &nam.bytes,
|
|
|
}
|
|
|
-
|
|
|
- var labels []*dto.LabelPair
|
|
|
- for i := range nam.labelNames {
|
|
|
- labels = append(labels, &dto.LabelPair{
|
|
|
- Name: &nam.labelNames[i],
|
|
|
- Value: &nam.labelValues[i],
|
|
|
- })
|
|
|
+ m.Label = []*dto.LabelPair{
|
|
|
+ {
|
|
|
+ Name: toStringPtr("node"),
|
|
|
+ Value: &nam.node,
|
|
|
+ },
|
|
|
}
|
|
|
- n := "node"
|
|
|
- labels = append(labels, &dto.LabelPair{
|
|
|
- Name: &n,
|
|
|
- Value: &nam.node,
|
|
|
- })
|
|
|
- m.Label = labels
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -148,23 +218,19 @@ func (nam KubeNodeStatusCapacityMemoryBytesMetric) Write(m *dto.Metric) error {
|
|
|
// a duplicate of the deprecated kube-state-metrics metric
|
|
|
// kube_node_status_capacity_memory_bytes
|
|
|
type KubeNodeStatusCapacityCPUCoresMetric struct {
|
|
|
- fqName string
|
|
|
- help string
|
|
|
- labelNames []string
|
|
|
- labelValues []string
|
|
|
- cores float64
|
|
|
- node string
|
|
|
+ fqName string
|
|
|
+ help string
|
|
|
+ cores float64
|
|
|
+ node string
|
|
|
}
|
|
|
|
|
|
// Creates a new KubeNodeStatusCapacityCPUCoresMetric, implementation of prometheus.Metric
|
|
|
-func newKubeNodeStatusCapacityCPUCoresMetric(node string, cores float64, fqname string, labelNames []string, labelValues []string) KubeNodeStatusCapacityCPUCoresMetric {
|
|
|
+func newKubeNodeStatusCapacityCPUCoresMetric(fqname string, node string, cores float64) KubeNodeStatusCapacityCPUCoresMetric {
|
|
|
return KubeNodeStatusCapacityCPUCoresMetric{
|
|
|
- fqName: fqname,
|
|
|
- labelNames: labelNames,
|
|
|
- labelValues: labelValues,
|
|
|
- help: "kube_node_status_capacity_cpu_cores Node Capacity CPU Cores",
|
|
|
- cores: cores,
|
|
|
- node: node,
|
|
|
+ fqName: fqname,
|
|
|
+ help: "kube_node_status_capacity_cpu_cores Node Capacity CPU Cores",
|
|
|
+ cores: cores,
|
|
|
+ node: node,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -172,30 +238,21 @@ func newKubeNodeStatusCapacityCPUCoresMetric(node string, cores float64, fqname
|
|
|
// returns the same descriptor throughout the lifetime of the Metric.
|
|
|
func (nam KubeNodeStatusCapacityCPUCoresMetric) Desc() *prometheus.Desc {
|
|
|
l := prometheus.Labels{"node": nam.node}
|
|
|
- return prometheus.NewDesc(nam.fqName, nam.help, nam.labelNames, l)
|
|
|
+ return prometheus.NewDesc(nam.fqName, nam.help, []string{}, l)
|
|
|
}
|
|
|
|
|
|
// Write encodes the Metric into a "Metric" Protocol Buffer data
|
|
|
// transmission object.
|
|
|
func (nam KubeNodeStatusCapacityCPUCoresMetric) Write(m *dto.Metric) error {
|
|
|
- h := nam.cores
|
|
|
m.Gauge = &dto.Gauge{
|
|
|
- Value: &h,
|
|
|
+ Value: &nam.cores,
|
|
|
}
|
|
|
-
|
|
|
- var labels []*dto.LabelPair
|
|
|
- for i := range nam.labelNames {
|
|
|
- labels = append(labels, &dto.LabelPair{
|
|
|
- Name: &nam.labelNames[i],
|
|
|
- Value: &nam.labelValues[i],
|
|
|
- })
|
|
|
+ m.Label = []*dto.LabelPair{
|
|
|
+ {
|
|
|
+ Name: toStringPtr("node"),
|
|
|
+ Value: &nam.node,
|
|
|
+ },
|
|
|
}
|
|
|
- n := "node"
|
|
|
- labels = append(labels, &dto.LabelPair{
|
|
|
- Name: &n,
|
|
|
- Value: &nam.node,
|
|
|
- })
|
|
|
- m.Label = labels
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -403,3 +460,99 @@ func (kpcrr KubeNodeStatusAllocatableMetric) Write(m *dto.Metric) error {
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+// KubeNodeStatusAllocatableCPUCoresMetric
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+
|
|
|
+// KubeNodeStatusAllocatableCPUCoresMetric is a prometheus.Metric
|
|
|
+type KubeNodeStatusAllocatableCPUCoresMetric struct {
|
|
|
+ fqName string
|
|
|
+ help string
|
|
|
+ resource string
|
|
|
+ unit string
|
|
|
+ node string
|
|
|
+ value float64
|
|
|
+}
|
|
|
+
|
|
|
+// Creates a new KubeNodeStatusAllocatableCPUCoresMetric, implementation of prometheus.Metric
|
|
|
+func newKubeNodeStatusAllocatableCPUCoresMetric(fqname, node string, value float64) KubeNodeStatusAllocatableCPUCoresMetric {
|
|
|
+ return KubeNodeStatusAllocatableCPUCoresMetric{
|
|
|
+ fqName: fqname,
|
|
|
+ help: "kube_node_status_allocatable_cpu_cores node allocatable cpu cores",
|
|
|
+ node: node,
|
|
|
+ value: value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Desc returns the descriptor for the Metric. This method idempotently
|
|
|
+// returns the same descriptor throughout the lifetime of the Metric.
|
|
|
+func (kpcrr KubeNodeStatusAllocatableCPUCoresMetric) Desc() *prometheus.Desc {
|
|
|
+ l := prometheus.Labels{
|
|
|
+ "node": kpcrr.node,
|
|
|
+ }
|
|
|
+ return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
|
|
|
+}
|
|
|
+
|
|
|
+// Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
|
|
|
+func (kpcrr KubeNodeStatusAllocatableCPUCoresMetric) Write(m *dto.Metric) error {
|
|
|
+ m.Gauge = &dto.Gauge{
|
|
|
+ Value: &kpcrr.value,
|
|
|
+ }
|
|
|
+
|
|
|
+ m.Label = []*dto.LabelPair{
|
|
|
+ {
|
|
|
+ Name: toStringPtr("node"),
|
|
|
+ Value: &kpcrr.node,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+// KubeNodeStatusAllocatableMemoryBytesMetric
|
|
|
+//--------------------------------------------------------------------------
|
|
|
+
|
|
|
+// KubeNodeStatusAllocatableMemoryBytesMetric is a prometheus.Metric
|
|
|
+type KubeNodeStatusAllocatableMemoryBytesMetric struct {
|
|
|
+ fqName string
|
|
|
+ help string
|
|
|
+ resource string
|
|
|
+ unit string
|
|
|
+ node string
|
|
|
+ value float64
|
|
|
+}
|
|
|
+
|
|
|
+// Creates a new KubeNodeStatusAllocatableMemoryBytesMetric, implementation of prometheus.Metric
|
|
|
+func newKubeNodeStatusAllocatableMemoryBytesMetric(fqname, node string, value float64) KubeNodeStatusAllocatableMemoryBytesMetric {
|
|
|
+ return KubeNodeStatusAllocatableMemoryBytesMetric{
|
|
|
+ fqName: fqname,
|
|
|
+ help: "kube_node_status_allocatable_memory_bytes node allocatable memory in bytes",
|
|
|
+ node: node,
|
|
|
+ value: value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Desc returns the descriptor for the Metric. This method idempotently
|
|
|
+// returns the same descriptor throughout the lifetime of the Metric.
|
|
|
+func (kpcrr KubeNodeStatusAllocatableMemoryBytesMetric) Desc() *prometheus.Desc {
|
|
|
+ l := prometheus.Labels{
|
|
|
+ "node": kpcrr.node,
|
|
|
+ }
|
|
|
+ return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
|
|
|
+}
|
|
|
+
|
|
|
+// Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
|
|
|
+func (kpcrr KubeNodeStatusAllocatableMemoryBytesMetric) Write(m *dto.Metric) error {
|
|
|
+ m.Gauge = &dto.Gauge{
|
|
|
+ Value: &kpcrr.value,
|
|
|
+ }
|
|
|
+
|
|
|
+ m.Label = []*dto.LabelPair{
|
|
|
+ {
|
|
|
+ Name: toStringPtr("node"),
|
|
|
+ Value: &kpcrr.node,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|