Просмотр исходного кода

Merge pull request #355 from kubecost/bolt/node-metric-labels

Add Region and UsageType to Node Metrics
Matt Bolt 6 лет назад
Родитель
Сommit
c8246d36f1
3 измененных файлов с 14 добавлено и 8 удалено
  1. 1 0
      pkg/cloud/provider.go
  2. 3 0
      pkg/costmodel/costmodel.go
  3. 10 8
      pkg/costmodel/router.go

+ 1 - 0
pkg/cloud/provider.go

@@ -59,6 +59,7 @@ type Node struct {
 	GPUName          string                `json:"gpuName"`
 	GPUName          string                `json:"gpuName"`
 	GPUCost          string                `json:"gpuCost"`
 	GPUCost          string                `json:"gpuCost"`
 	InstanceType     string                `json:"instanceType,omitempty"`
 	InstanceType     string                `json:"instanceType,omitempty"`
+	Region           string                `json:"region,omitempty"`
 	Reserved         *ReservedInstanceData `json:"reserved,omitempty"`
 	Reserved         *ReservedInstanceData `json:"reserved,omitempty"`
 }
 }
 
 

+ 3 - 0
pkg/costmodel/costmodel.go

@@ -1144,6 +1144,9 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 		if newCnode.InstanceType == "" {
 		if newCnode.InstanceType == "" {
 			newCnode.InstanceType = n.Labels[v1.LabelInstanceType]
 			newCnode.InstanceType = n.Labels[v1.LabelInstanceType]
 		}
 		}
+		if newCnode.Region == "" {
+			newCnode.Region = n.Labels[v1.LabelZoneRegion]
+		}
 
 
 		var cpu float64
 		var cpu float64
 		if newCnode.VCPU == "" {
 		if newCnode.VCPU == "" {

+ 10 - 8
pkg/costmodel/router.go

@@ -709,13 +709,15 @@ func (a *Accesses) recordPrices() {
 					}
 					}
 				}
 				}
 				nodeType := node.InstanceType
 				nodeType := node.InstanceType
+				nodeRegion := node.Region
+				nodeUsageType := node.UsageType
 
 
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 
 
-				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(cpuCost)
-				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(ramCost)
-				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(gpuCost)
-				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(totalCost)
+				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(cpuCost)
+				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(ramCost)
+				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(gpuCost)
+				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(totalCost)
 				labelKey := getKeyFromLabelStrings(nodeName, nodeName)
 				labelKey := getKeyFromLabelStrings(nodeName, nodeName)
 				nodeSeen[labelKey] = true
 				nodeSeen[labelKey] = true
 			}
 			}
@@ -968,22 +970,22 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) {
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_cpu_hourly_cost",
 		Name: "node_cpu_hourly_cost",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_ram_hourly_cost",
 		Name: "node_ram_hourly_cost",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_gpu_hourly_cost",
 		Name: "node_gpu_hourly_cost",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_total_hourly_cost",
 		Name: "node_total_hourly_cost",
 		Help: "node_total_hourly_cost Total node cost per hour",
 		Help: "node_total_hourly_cost Total node cost per hour",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 
 	pvGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	pvGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "pv_hourly_cost",
 		Name: "pv_hourly_cost",