Documentation

Kubernetes Measure Definitions

Prerequisites/troubleshooting lack of K8s metrics in Ternary:

It is important to note that we use Google's native Cloud Monitoring to gather Kubernetes metrics. It is enabled by default on GKE clusters. If you do not have it enabled, you will need to enable it for Ternary to ingest your Kubernetes cluster, namespace, workload and pod metrics.

Another issue we have seen, if Cloud Monitoring is enabled and we are still not seeing metrics, is permissions related issues in publishing the metrics to the GCP console in Cloud Monitoring. For example, if you use a custom service account and not the default Compute Engine service account the absence of metrics could be explained by missing roles such as roles/logging.logWriter, roles/monitoring.metricWriter, roles/stackdriver.resourceMetdata.writer. You can check if Kubernetes metrics are being published by navigating to the Metrics Explorer in the GCP console and replicating this query:

  • Metric: Kubernetes Container - CPU Usage time
  • Filters: project_id=your_project_id
  • groupingFunction: Sum
  • groupByLabels:
    • cluster_name
    • node_name
    • top_level_controller_name
    • top_level_controller_type
    • container_name
    • location
    • namespace_name
    • pod_name
  • perSeriesAligner: Rate
  • alignmentPeriod: 1h

If this query returns no results the issue may be in Cloud Monitoring metrics for Kubernetes being published to the GCP console.

Kubernetes Container Measure Definition

MetricDefinition
limitCPUCoresCore-Days
limitMemoryBytesByte-Days
requestCPUCoresk8s_container.request_cpu_cores / 24.0 = requestCPUCores in Core-Days
requestCPUCost(requestCPUCores) * (CPU USD Price) = Dollars
requestMemoryBytesk8s_container.request_memory_bytes / 24.0 = requestMemoryBytes in Byte-Days
requestMemoryCostk8s_container.request_memory_bytes * k8s_node_detail.ram_usd_price / 1073741824.0 = requestMemoryCost in USD

(There are 1073741824.0 bytes per GiB)
totalRequestCostrequestMemoryCost + requestCPUCost = totalRequestCost in USD
totalWasteCostrequestMemoryCost + requestCPUCost - usedCPUCost - usedMemoryCost = totalWasteCost in USD
usedCPUCoresk8s_container.used_cpu_cores / 24.0 = usedCPUCores in Core-Days
usedCPUCostk8s_container.used_cpu_cores * k8s_node_detail.cpu_usd_price = usedCPUCost in USD
usedMemoryBytesk8s_container.used_memory_bytes / 24.0 = usedMemoryBytes in Byte-Days
usedMemoryCostk8s_container.used_memory_bytes * k8s_node_detail.ram_usd_price / 1073741824.0 = usedMemoryCost in USD
wasteCPUsrequestCPUCores - usedCPUCores = wasteCPUs in Core-Days
wasteMemoryBytesrequestMemoryBytes - usedMemoryBytes = wasteMemoryBytes in Byte-Days
wasteCPUCostrequestCPUCost - usedCPUCost = wasteCPUCost in USD
wasteMemoryCostrequestMemoryCost - usedMemoryCost = wasteMemoryCost in USD

Kubernetes Node Measure Definition

MetricDefinition
allocatableCPUUtilizationallocatable_cpu_utilization / 24.0 = allocatableCPUUtilization
allocatableMemoryUtilizationallocatable_memory_utilization / 24.0 = allocatableMemoryUtilization
CPUCoreUsageTimecpu_core_usage_time / 24.0 = CPUCoreUsageTime in Core-Days
totalCosttotalMemoryCost + totalCPUCost = totalCost in USD
totalCPUCoresk8s_node.total_cpu_cores / 24.0 = totalCPUCores in Core-Days
totalCPUCostk8s_node.total_cpu_cores * k8s_node_detail.cpu_usd_price = totalCPUCost in USD
totalMemoryCostk8s_node.total_memory_bytes * k8s_node_detail.ram_usd_price / 1073741824.0 = totalMemoryCost in USD
totalMemoryBytesk8s_node.total_memory_bytes / 24.0 = totalMemoryBytes in Byte-Days
usedMemoryBytesused_memory_bytes / 24.0 = usedMemoryBytes in Byte-Days
wasteCPUstotalCPUCores - CPUCoreUsagetime = wasteCPUs in Core-Days
wasteMemoryBytestotalMemorybytes - usedMemoryBytes = wasteMemoryBytes in Bytes