|
|
@@ -40,23 +40,27 @@ type ClusterInfoCollector struct {
|
|
|
// collected by this Collector.
|
|
|
func (cic ClusterInfoCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
|
disabledMetrics := cic.metricsConfig.GetDisabledMetricsMap()
|
|
|
-
|
|
|
- if _, ok := disabledMetrics["kube_pod_annotations"]; !ok {
|
|
|
- ch <- prometheus.NewDesc("kubecost_cluster_info", "Kubecost Cluster Info", []string{}, nil)
|
|
|
+ if _, disabled := disabledMetrics["kube_pod_annotations"]; disabled {
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ ch <- prometheus.NewDesc("kubecost_cluster_info", "Kubecost Cluster Info", []string{}, nil)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Collect is called by the Prometheus registry when collecting metrics.
|
|
|
func (cic ClusterInfoCollector) Collect(ch chan<- prometheus.Metric) {
|
|
|
disabledMetrics := cic.metricsConfig.GetDisabledMetricsMap()
|
|
|
+ if _, disabled := disabledMetrics["kube_pod_annotations"]; disabled {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- if _, ok := disabledMetrics["kube_pod_annotations"]; !ok {
|
|
|
- clusterInfo := cic.ClusterInfo.GetClusterInfo()
|
|
|
- labels := prom.MapToLabels(clusterInfo)
|
|
|
+ clusterInfo := cic.ClusterInfo.GetClusterInfo()
|
|
|
+ labels := prom.MapToLabels(clusterInfo)
|
|
|
+
|
|
|
+ m := newClusterInfoMetric("kubecost_cluster_info", labels)
|
|
|
+ ch <- m
|
|
|
|
|
|
- m := newClusterInfoMetric("kubecost_cluster_info", labels)
|
|
|
- ch <- m
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
@@ -138,11 +142,11 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
|
|
|
disabledMetrics := metricsConfig.GetDisabledMetricsMap()
|
|
|
var toRegisterGV []*prometheus.GaugeVec
|
|
|
- var toRegisterGage []prometheus.Gauge
|
|
|
+ var toRegisterGauge []prometheus.Gauge
|
|
|
|
|
|
metricsInit.Do(func() {
|
|
|
|
|
|
- if _, ok := disabledMetrics["node_cpu_hourly_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["node_cpu_hourly_cost"]; !disabled {
|
|
|
cpuGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "node_cpu_hourly_cost",
|
|
|
Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
|
|
|
@@ -150,7 +154,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, cpuGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["node_ram_hourly_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["node_ram_hourly_cost"]; !disabled {
|
|
|
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",
|
|
|
@@ -158,7 +162,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, ramGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["node_gpu_hourly_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["node_gpu_hourly_cost"]; !disabled {
|
|
|
gpuGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "node_gpu_hourly_cost",
|
|
|
Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
|
|
|
@@ -166,7 +170,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, gpuGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["node_gpu_count"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["node_gpu_count"]; !disabled {
|
|
|
gpuCountGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "node_gpu_count",
|
|
|
Help: "node_gpu_count count of gpu on this node",
|
|
|
@@ -174,7 +178,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, gpuCountGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["pv_hourly_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["pv_hourly_cost"]; !disabled {
|
|
|
pvGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "pv_hourly_cost",
|
|
|
Help: "pv_hourly_cost Cost per GB per hour on a persistent disk",
|
|
|
@@ -182,7 +186,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, pvGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_node_is_spot"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_node_is_spot"]; !disabled {
|
|
|
spotGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "kubecost_node_is_spot",
|
|
|
Help: "kubecost_node_is_spot Cloud provider info about node preemptibility",
|
|
|
@@ -190,7 +194,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, spotGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["node_total_hourly_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["node_total_hourly_cost"]; !disabled {
|
|
|
totalGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "node_total_hourly_cost",
|
|
|
Help: "node_total_hourly_cost Total node cost per hour",
|
|
|
@@ -198,7 +202,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, totalGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["container_memory_allocation_bytes"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["container_memory_allocation_bytes"]; !disabled {
|
|
|
ramAllocGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "container_memory_allocation_bytes",
|
|
|
Help: "container_memory_allocation_bytes Bytes of RAM used",
|
|
|
@@ -206,7 +210,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, ramAllocGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["container_cpu_allocation"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["container_cpu_allocation"]; !disabled {
|
|
|
cpuAllocGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "container_cpu_allocation",
|
|
|
Help: "container_cpu_allocation Percent of a single CPU used in a minute",
|
|
|
@@ -214,7 +218,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, cpuAllocGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["container_gpu_allocation"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["container_gpu_allocation"]; !disabled {
|
|
|
gpuAllocGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "container_gpu_allocation",
|
|
|
Help: "container_gpu_allocation GPU used",
|
|
|
@@ -222,7 +226,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, gpuAllocGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["pod_pvc_allocation"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["pod_pvc_allocation"]; !disabled {
|
|
|
pvAllocGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "pod_pvc_allocation",
|
|
|
Help: "pod_pvc_allocation Bytes used by a PVC attached to a pod",
|
|
|
@@ -230,31 +234,31 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, pvAllocGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_network_zone_egress_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_network_zone_egress_cost"]; !disabled {
|
|
|
networkZoneEgressCostG = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
Name: "kubecost_network_zone_egress_cost",
|
|
|
Help: "kubecost_network_zone_egress_cost Total cost per GB egress across zones",
|
|
|
})
|
|
|
- toRegisterGage = append(toRegisterGage, networkZoneEgressCostG)
|
|
|
+ toRegisterGauge = append(toRegisterGauge, networkZoneEgressCostG)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_network_region_egress_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_network_region_egress_cost"]; !disabled {
|
|
|
networkRegionEgressCostG = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
Name: "kubecost_network_region_egress_cost",
|
|
|
Help: "kubecost_network_region_egress_cost Total cost per GB egress across regions",
|
|
|
})
|
|
|
- toRegisterGage = append(toRegisterGage, networkRegionEgressCostG)
|
|
|
+ toRegisterGauge = append(toRegisterGauge, networkRegionEgressCostG)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_network_internet_egress_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_network_internet_egress_cost"]; !disabled {
|
|
|
networkInternetEgressCostG = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
Name: "kubecost_network_internet_egress_cost",
|
|
|
Help: "kubecost_network_internet_egress_cost Total cost per GB of internet egress.",
|
|
|
})
|
|
|
- toRegisterGage = append(toRegisterGage, networkInternetEgressCostG)
|
|
|
+ toRegisterGauge = append(toRegisterGauge, networkInternetEgressCostG)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_cluster_management_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_cluster_management_cost"]; !disabled {
|
|
|
clusterManagementCostGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
Name: "kubecost_cluster_management_cost",
|
|
|
Help: "kubecost_cluster_management_cost Hourly cost paid as a cluster management fee.",
|
|
|
@@ -262,7 +266,7 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
toRegisterGV = append(toRegisterGV, clusterManagementCostGv)
|
|
|
}
|
|
|
|
|
|
- if _, ok := disabledMetrics["kubecost_load_balancer_cost"]; !ok {
|
|
|
+ if _, disabled := disabledMetrics["kubecost_load_balancer_cost"]; !disabled {
|
|
|
lbCostGv = prometheus.NewGaugeVec(prometheus.GaugeOpts{ // no differentiation between ELB and ALB right now
|
|
|
Name: "kubecost_load_balancer_cost",
|
|
|
Help: "kubecost_load_balancer_cost Hourly cost of load balancer",
|
|
|
@@ -271,11 +275,11 @@ func initCostModelMetrics(clusterCache clustercache.ClusterCache, provider cloud
|
|
|
}
|
|
|
|
|
|
// Register cost-model metrics for emission
|
|
|
- for i := range toRegisterGV {
|
|
|
- prometheus.MustRegister(toRegisterGV[i])
|
|
|
+ for _, gv := range toRegisterGV {
|
|
|
+ prometheus.MustRegister(gv)
|
|
|
}
|
|
|
- for i := range toRegisterGage {
|
|
|
- prometheus.MustRegister(toRegisterGage[i])
|
|
|
+ for _, g := range toRegisterGauge {
|
|
|
+ prometheus.MustRegister(g)
|
|
|
}
|
|
|
|
|
|
// General Metric Collectors
|
|
|
@@ -329,6 +333,10 @@ func NewCostModelMetricsEmitter(promClient promclient.Client, clusterCache clust
|
|
|
log.Infof("Failed to get metrics config before init: %s", err)
|
|
|
}
|
|
|
|
|
|
+ if len(metricsConfig.DisabledMetrics) > 0 {
|
|
|
+ log.Infof("Starting metrics init with disabled metrics: %v", metricsConfig.DisabledMetrics)
|
|
|
+ }
|
|
|
+
|
|
|
// init will only actually execute once to register the custom gauges
|
|
|
initCostModelMetrics(clusterCache, provider, clusterInfo, metricsConfig)
|
|
|
|