|
|
@@ -576,588 +576,6 @@ func (pds *PrometheusDataSource) MetaData() map[string]string {
|
|
|
// InstantMetricsQuerier
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
-func (pds *PrometheusDataSource) QueryRAMUsage(window string, offset string) source.QueryResultsChan {
|
|
|
- const ramUsageQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- sum_over_time(container_memory_working_set_bytes{container!="", container!="POD", instance!="", %s}[%s] %s), "node", "$1", "instance", "(.+)"
|
|
|
- ), "container_name", "$1", "container", "(.+)"
|
|
|
- ), "pod_name", "$1", "pod", "(.+)"
|
|
|
- )
|
|
|
- ) by (namespace, container_name, pod_name, node, %s)`
|
|
|
- // env.GetPromClusterFilter(), window, offset, env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryRAMUsage := fmt.Sprintf(ramUsageQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryRAMUsage)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryCPUUsage(window string, offset string) source.QueryResultsChan {
|
|
|
- const cpuUsageQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- rate(
|
|
|
- container_cpu_usage_seconds_total{container!="", container!="POD", instance!="", %s}[%s] %s
|
|
|
- ), "node", "$1", "instance", "(.+)"
|
|
|
- ), "container_name", "$1", "container", "(.+)"
|
|
|
- ), "pod_name", "$1", "pod", "(.+)"
|
|
|
- )
|
|
|
- ) by (namespace, container_name, pod_name, node, %s)`
|
|
|
- // env.GetPromClusterFilter(), window, offset, env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryCPUUsage := fmt.Sprintf(cpuUsageQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryCPUUsage)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInZoneRequests(window string, offset string) source.QueryResultsChan {
|
|
|
- const zoneNetworkUsageQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="false", sameZone="false", sameRegion="true", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), window, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryZoneNetworkUsage := fmt.Sprintf(zoneNetworkUsageQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryZoneNetworkUsage)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInRegionRequests(window string, offset string) source.QueryResultsChan {
|
|
|
- const regionNetworkUsageQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="false", sameZone="false", sameRegion="false", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), window, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryRegionNetworkUsage := fmt.Sprintf(regionNetworkUsageQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryRegionNetworkUsage)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInternetRequests(window string, offset string) source.QueryResultsChan {
|
|
|
- const internetNetworkUsageQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="true", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), window, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryInternetNetworkUsage := fmt.Sprintf(internetNetworkUsageQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryInternetNetworkUsage)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNormalization(window string, offset string) source.QueryResultsChan {
|
|
|
- const normalizationQuery = `max(count_over_time(kube_pod_container_resource_requests{resource="memory", unit="byte", %s}[%s] %s))`
|
|
|
- // env.GetPromClusterFilter(), window, offset)
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryNormalization := fmt.Sprintf(normalizationQuery, cfg.ClusterFilter, window, offset)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryNormalization)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryHistoricalCPUCost(window string, offset string) source.QueryResultsChan {
|
|
|
- const historicalCPUCostQuery = `avg(avg_over_time(node_cpu_hourly_cost{%s}[%s] %s)) by (node, instance, %s)`
|
|
|
- // env.GetPromClusterFilter(), window, offsetStr, env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryHistoricalCPUCost := fmt.Sprintf(historicalCPUCostQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryHistoricalCPUCost)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryHistoricalRAMCost(window string, offset string) source.QueryResultsChan {
|
|
|
- const historicalRAMCostQuery = `avg(avg_over_time(node_ram_hourly_cost{%s}[%s] %s)) by (node, instance, %s)`
|
|
|
- // env.GetPromClusterFilter(), window, offsetStr, env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryHistoricalRAMCost := fmt.Sprintf(historicalRAMCostQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryHistoricalRAMCost)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryHistoricalGPUCost(window string, offset string) source.QueryResultsChan {
|
|
|
- const historicalGPUCostQuery = `avg(avg_over_time(node_gpu_hourly_cost{%s}[%s] %s)) by (node, instance, %s)`
|
|
|
- // env.GetPromClusterFilter(), window, offsetStr, env.GetPromClusterLabel())
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryHistoricalGPUCost := fmt.Sprintf(historicalGPUCostQuery, cfg.ClusterFilter, window, offset, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryHistoricalGPUCost)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryHistoricalPodLabels(window string, offset string) source.QueryResultsChan {
|
|
|
- const historicalPodLabelsQuery = `kube_pod_labels{%s}[%s] %s`
|
|
|
- // env.GetPromClusterFilter(), window, offset
|
|
|
-
|
|
|
- if offset != "" && !strings.Contains(offset, "offset") {
|
|
|
- offset = fmt.Sprintf("offset %s", offset)
|
|
|
- }
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- queryHistoricalPodLabels := fmt.Sprintf(historicalPodLabelsQuery, cfg.ClusterFilter, window, offset)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataContextName)
|
|
|
- return ctx.Query(queryHistoricalPodLabels)
|
|
|
-}
|
|
|
-
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-// RangeMetricsQuerier
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryRAMRequestsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const ramRequestsQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- sum_over_time(kube_pod_container_resource_requests{resource="memory", unit="byte", container!="",container!="POD", node!="", %s}[%s] %s)
|
|
|
- , "container_name","$1","container","(.+)"
|
|
|
- ), "pod_name","$1","pod","(.+)"
|
|
|
- )
|
|
|
- ) by (namespace,container_name,pod_name,node,%s)`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryRAMRequests := fmt.Sprintf(ramRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryRAMRequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryRAMUsageOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const ramUsageQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- sum_over_time(container_memory_working_set_bytes{container!="", container!="POD", instance!="", %s}[%s] %s), "node", "$1", "instance", "(.+)"
|
|
|
- ), "container_name", "$1", "container", "(.+)"
|
|
|
- ), "pod_name", "$1", "pod", "(.+)"
|
|
|
- )
|
|
|
- ) by (namespace, container_name, pod_name, node, %s)`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryRAMUsage := fmt.Sprintf(ramUsageQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryRAMUsage, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryRAMAllocationOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- // ramAllocationByteHoursQuery yields the total byte-hour RAM allocation over the given
|
|
|
- // window, aggregated by container.
|
|
|
- // [line 3] sum_over_time(each byte) = [byte*scrape] by metric
|
|
|
- // [line 4] (scalar(avg(prometheus_target_interval_length_seconds)) = [seconds/scrape] / 60 / 60 = [hours/scrape] by container
|
|
|
- // [lines 2,4] sum(") by unique container key and multiply [byte*scrape] * [hours/scrape] for byte*hours
|
|
|
- // [lines 1,5] relabeling
|
|
|
- const ramAllocationByteHoursQuery = `
|
|
|
- label_replace(label_replace(
|
|
|
- sum(
|
|
|
- sum_over_time(container_memory_allocation_bytes{container!="",container!="POD", node!="", %s}[%s])
|
|
|
- ) by (namespace,container,pod,node,%s) * %f / 60 / 60
|
|
|
- , "container_name","$1","container","(.+)"), "pod_name","$1","pod","(.+)")`
|
|
|
- // env.GetPromClusterFilter(), resStr, env.GetPromClusterLabel(), scrapeIntervalSeconds)
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- scrapeIntervalSeconds := cfg.ScrapeInterval.Seconds()
|
|
|
-
|
|
|
- queryRAMAllocationByteHours := fmt.Sprintf(ramAllocationByteHoursQuery, cfg.ClusterFilter, resStr, cfg.ClusterLabel, scrapeIntervalSeconds)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryRAMAllocationByteHours, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryCPURequestsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const cpuRequestsQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- sum_over_time(kube_pod_container_resource_requests{resource="cpu", unit="core", container!="",container!="POD", node!="", %s}[%s] %s)
|
|
|
- , "container_name","$1","container","(.+)"
|
|
|
- ), "pod_name","$1","pod","(.+)"
|
|
|
- )
|
|
|
- ) by (namespace,container_name,pod_name,node,%s)`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryCPURequests := fmt.Sprintf(cpuRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryCPURequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryCPUUsageOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const cpuUsageQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- rate(
|
|
|
- container_cpu_usage_seconds_total{container!="", container!="POD", instance!="", %s}[%s] %s
|
|
|
- ), "node", "$1", "instance", "(.+)"
|
|
|
- ), "container_name", "$1", "container", "(.+)"
|
|
|
- ), "pod_name", "$1", "pod", "(.+)"
|
|
|
- )
|
|
|
- ) by (namespace, container_name, pod_name, node, %s)`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryCPUUsage := fmt.Sprintf(cpuUsageQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryCPUUsage, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryCPUAllocationOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- // cpuAllocationQuery yields the total VCPU-hour CPU allocation over the given
|
|
|
- // window, aggregated by container.
|
|
|
- // [line 3] sum_over_time(each VCPU*mins in window) = [VCPU*scrape] by metric
|
|
|
- // [line 4] (scalar(avg(prometheus_target_interval_length_seconds)) = [seconds/scrape] / 60 / 60 = [hours/scrape] by container
|
|
|
- // [lines 2,4] sum(") by unique container key and multiply [VCPU*scrape] * [hours/scrape] for VCPU*hours
|
|
|
- // [lines 1,5] relabeling
|
|
|
- const cpuAllocationQuery = `
|
|
|
- label_replace(label_replace(
|
|
|
- sum(
|
|
|
- sum_over_time(container_cpu_allocation{container!="",container!="POD", node!="", %s}[%s])
|
|
|
- ) by (namespace,container,pod,node,%s) * %f / 60 / 60
|
|
|
- , "container_name","$1","container","(.+)"), "pod_name","$1","pod","(.+)")`
|
|
|
- // env.GetPromClusterFilter(), resStr, env.GetPromClusterLabel(), scrapeIntervalSeconds)
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- scrapeIntervalSeconds := cfg.ScrapeInterval.Seconds()
|
|
|
-
|
|
|
- queryCPUAllocation := fmt.Sprintf(cpuAllocationQuery, cfg.ClusterFilter, resStr, cfg.ClusterLabel, scrapeIntervalSeconds)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryCPUAllocation, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryGPURequestsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const gpuRequestsQuery = `avg(
|
|
|
- label_replace(
|
|
|
- label_replace(
|
|
|
- sum_over_time(kube_pod_container_resource_requests{resource="nvidia_com_gpu", container!="",container!="POD", node!="", %s}[%s] %s),
|
|
|
- "container_name","$1","container","(.+)"
|
|
|
- ), "pod_name","$1","pod","(.+)"
|
|
|
- )
|
|
|
- ) by (namespace,container_name,pod_name,node,%s)`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryGPURequests := fmt.Sprintf(gpuRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryGPURequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPVRequestsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const pvRequestsQuery = `avg(avg(kube_persistentvolumeclaim_info{volumename != "", %s}) by (persistentvolumeclaim, storageclass, namespace, volumename, %s, kubernetes_node)
|
|
|
- *
|
|
|
- on (persistentvolumeclaim, namespace, %s, kubernetes_node) group_right(storageclass, volumename)
|
|
|
- sum(kube_persistentvolumeclaim_resource_requests_storage_bytes{%s}) by (persistentvolumeclaim, namespace, %s, kubernetes_node, kubernetes_name)) by (persistentvolumeclaim, storageclass, namespace, %s, volumename, kubernetes_node)`
|
|
|
- // env.GetPromClusterFilter(), env.GetPromClusterLabel(), env.GetPromClusterLabel(), env.GetPromClusterFilter(), env.GetPromClusterLabel(), env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
-
|
|
|
- queryPVRequests := fmt.Sprintf(pvRequestsQuery, cfg.ClusterFilter, cfg.ClusterLabel, cfg.ClusterLabel, cfg.ClusterFilter, cfg.ClusterLabel, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPVRequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPVCAllocationOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- // pvcAllocationQuery yields the total byte-hour PVC allocation over the given window.
|
|
|
- // sum_over_time(each byte) = [byte*scrape] by metric *(scalar(avg(prometheus_target_interval_length_seconds)) = [seconds/scrape] / 60 / 60 = [hours/scrape] by pod
|
|
|
- const pvcAllocationQuery = `sum(sum_over_time(pod_pvc_allocation{%s}[%s])) by (%s, namespace, pod, persistentvolume, persistentvolumeclaim) * %f/60/60`
|
|
|
- // env.GetPromClusterFilter(), resStr, env.GetPromClusterLabel(), scrapeIntervalSeconds)
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- scrapeIntervalSeconds := cfg.ScrapeInterval.Seconds()
|
|
|
-
|
|
|
- queryPVCAllocation := fmt.Sprintf(pvcAllocationQuery, cfg.ClusterFilter, resStr, cfg.ClusterLabel, scrapeIntervalSeconds)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPVCAllocation, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPVHourlyCostOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const pvHourlyCostQuery = `avg_over_time(pv_hourly_cost{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr)
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryPVHourlyCost := fmt.Sprintf(pvHourlyCostQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPVHourlyCost, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInZoneOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const netZoneRequestsQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="false", sameZone="false", sameRegion="true", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNetZoneRequests := fmt.Sprintf(netZoneRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNetZoneRequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInRegionOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const netRegionRequestsQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="false", sameZone="false", sameRegion="false", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNetRegionRequests := fmt.Sprintf(netRegionRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNetRegionRequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNetworkInternetOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const netInternetRequestsQuery = `sum(increase(kubecost_pod_network_egress_bytes_total{internet="true", %s}[%s] %s)) by (namespace,pod_name,%s) / 1024 / 1024 / 1024`
|
|
|
- // env.GetPromClusterFilter(), resStr, "", env.GetPromClusterLabel())
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNetInternetRequests := fmt.Sprintf(netInternetRequestsQuery, cfg.ClusterFilter, resStr, "", cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNetInternetRequests, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNamespaceLabelsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const namespaceLabelsQuery = `avg_over_time(kube_namespace_labels{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNamespaceLabels := fmt.Sprintf(namespaceLabelsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNamespaceLabels, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNamespaceAnnotationsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const namespaceAnnotationsQuery = `avg_over_time(kube_namespace_annotations{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNamespaceAnnotations := fmt.Sprintf(namespaceAnnotationsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNamespaceAnnotations, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPodLabelsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const podLabelsQuery = `avg_over_time(kube_pod_labels{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryPodLabels := fmt.Sprintf(podLabelsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPodLabels, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPodAnnotationsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const podAnnotationsQuery = `avg_over_time(kube_pod_annotations{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryPodAnnotations := fmt.Sprintf(podAnnotationsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPodAnnotations, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryServiceLabelsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const serviceLabelsQuery = `avg_over_time(service_selector_labels{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryServiceLabels := fmt.Sprintf(serviceLabelsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryServiceLabels, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryDeploymentLabelsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const deploymentLabelsQuery = `avg_over_time(deployment_match_labels{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryDeploymentLabels := fmt.Sprintf(deploymentLabelsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryDeploymentLabels, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryStatefulsetLabelsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const statefulsetLabelsQuery = `avg_over_time(statefulSet_match_labels{%s}[%s])`
|
|
|
- // env.GetPromClusterFilter(), resStr
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryStatefulsetLabels := fmt.Sprintf(statefulsetLabelsQuery, cfg.ClusterFilter, resStr)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryStatefulsetLabels, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPodJobsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const podJobsQuery = `sum(kube_pod_owner{owner_kind="Job", %s}) by (namespace,pod,owner_name,%s)`
|
|
|
- // env.GetPromClusterFilter(), env.GetPromClusterLabel()
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
-
|
|
|
- queryPodJobs := fmt.Sprintf(podJobsQuery, cfg.ClusterFilter, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPodJobs, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryPodDaemonsetsOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const podDaemonsetsQuery = `sum(kube_pod_owner{owner_kind="DaemonSet", %s}) by (namespace,pod,owner_name,%s)`
|
|
|
- // env.GetPromClusterFilter(), env.GetPromClusterLabel()
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
-
|
|
|
- queryPodDaemonsets := fmt.Sprintf(podDaemonsetsQuery, cfg.ClusterFilter, cfg.ClusterLabel)
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryPodDaemonsets, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-func (pds *PrometheusDataSource) QueryNormalizationOverTime(start, end time.Time, resolution time.Duration) source.QueryResultsChan {
|
|
|
- const normalizationQuery = `max(count_over_time(kube_pod_container_resource_requests{resource="memory", unit="byte", %s}[%s] %s))`
|
|
|
- // env.GetPromClusterFilter(), resStr, "")
|
|
|
-
|
|
|
- cfg := pds.promConfig
|
|
|
-
|
|
|
- resolution = snapResolutionMinute(resolution)
|
|
|
- resMins := int64(resolution.Minutes())
|
|
|
- resStr := formatResolutionMinutes(resMins)
|
|
|
-
|
|
|
- queryNormalization := fmt.Sprintf(normalizationQuery, cfg.ClusterFilter, resStr, "")
|
|
|
- ctx := pds.promContexts.NewNamedContext(ComputeCostDataRangeContextName)
|
|
|
- return ctx.QueryRange(queryNormalization, start, end, resolution)
|
|
|
-}
|
|
|
-
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-// ClusterMetricsQuerier
|
|
|
-//--------------------------------------------------------------------------
|
|
|
-
|
|
|
func (pds *PrometheusDataSource) QueryPVCost(start, end time.Time) source.QueryResultsChan {
|
|
|
const pvCostQuery = `avg(avg_over_time(pv_hourly_cost{%s}[%s])) by (%s, persistentvolume,provider_id)`
|
|
|
|