Procházet zdrojové kódy

add node label for deprecation of instance label, don't emit 0 cost on GPU

AjayTripathy před 7 roky
rodič
revize
639a42e56a
1 změnil soubory, kde provedl 14 přidání a 12 odebrání
  1. 14 12
      main.go

+ 14 - 12
main.go

@@ -179,20 +179,22 @@ func (a *Accesses) recordPrices() {
 
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 
-				a.CPUPriceRecorder.WithLabelValues(nodeName).Set(cpuCost)
-				a.RAMPriceRecorder.WithLabelValues(nodeName).Set(ramCost)
-				a.GPUPriceRecorder.WithLabelValues(nodeName).Set(gpuCost)
+				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName).Set(cpuCost)
+				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName).Set(ramCost)
+				if gpu > 0 {
+					a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName).Set(gpuCost)
+				}
 
-				a.NodeTotalPriceRecorder.WithLabelValues(nodeName).Set(totalCost)
+				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName).Set(totalCost)
 
 				namespace := costs.Namespace
 				podName := costs.PodName
 				containerName := costs.Name
 				if len(costs.RAMAllocation) > 0 {
-					a.RAMAllocationRecorder.WithLabelValues(namespace, podName, containerName, nodeName).Set(costs.RAMAllocation[0].Value)
+					a.RAMAllocationRecorder.WithLabelValues(namespace, podName, containerName, nodeName, nodeName).Set(costs.RAMAllocation[0].Value)
 				}
 				if len(costs.CPUAllocation) > 0 {
-					a.CPUAllocationRecorder.WithLabelValues(namespace, podName, containerName, nodeName).Set(costs.CPUAllocation[0].Value)
+					a.CPUAllocationRecorder.WithLabelValues(namespace, podName, containerName, nodeName, nodeName).Set(costs.CPUAllocation[0].Value)
 				}
 			}
 			time.Sleep(time.Minute)
@@ -242,32 +244,32 @@ func main() {
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_cpu_hourly_cost",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
-	}, []string{"instance"})
+	}, []string{"instance", "node"})
 
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_ram_hourly_cost",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
-	}, []string{"instance"})
+	}, []string{"instance", "node"})
 
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_gpu_hourly_cost",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
-	}, []string{"instance"})
+	}, []string{"instance", "node"})
 
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_total_hourly_cost",
 		Help: "node_total_hourly_cost Total node cost per hour",
-	}, []string{"instance"})
+	}, []string{"instance", "node"})
 
 	RAMAllocation := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "container_memory_allocation_bytes",
 		Help: "container_memory_allocation_bytes Bytes of RAM used",
-	}, []string{"namespace", "pod", "container", "instance"})
+	}, []string{"namespace", "pod", "container", "instance", "node"})
 
 	CPUAllocation := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "container_cpu_allocation",
 		Help: "container_cpu_allocation Percent of a single CPU used in a minute",
-	}, []string{"namespace", "pod", "container", "instance"})
+	}, []string{"namespace", "pod", "container", "instance", "node"})
 
 	prometheus.MustRegister(cpuGv)
 	prometheus.MustRegister(ramGv)