Queries Used in the Kubernetes Solution
The queries are used to extract the metrics, events, topology, and analysis data to display in various panels available in the Kubernetes solution. Some of the log based queries like the ones for Kube System, OS health, Events, Workloads Summary, Node Summary, and Pod Summary must be run in the Log Explorer and the other queries are metrics based which must be run in the Metric Explorer.
Topics:
- Queries for the Right Panel Widgets
- Queries for the Events Table
- Queries for the Cluster Topology and Details Tables
Queries for the Right Panel Widgets
-
Widget title: Kube System
Tabs: Cluster
Filters: None
Scope: Log Explorer
Query:
'Component Type' in ('Kubernetes System', 'Kubernetes Control Plane') and Component != null | link Time, Component, cluster() | rename 'Cluster Sample' as 'Error Sample' | eval Error = if(length('Error Sample') > 50, substr('Error Sample', 0, 50) || ' ...', substr('Error Sample', 0, 50)) | classify correlate = -*, Error Component as Trend | timestats name = 'All Issues' sum(Count) as 'Issue Trend' | timestats name = 'Potential Issues' sum(Count) as Issues by Component, Error | fields -'Potential Issue', -Error
-
Widget title: OS health
Tabs: Cluster, Node
Filters: None
Scope: Log Explorer
Query:
'Component Type' = 'Linux System' and Component != null and (Label = null or (Label != null and 'Problem Priority' != null)) | link includenulls = true Time, Node, Component, Label, cluster() | stats max('Problem Priority') as 'Problem Priority' | where 'Problem Priority' != null or 'Potential Issue' = '1' | eval Error = if(length('Cluster Sample') > 30, substr('Cluster Sample', 0, 30) || ' ...', substr('Cluster Sample', 0, 30)) | classify correlate = -*, Error, Label Component as Trend | timestats name = 'All Issues' sum(Count) as 'Issue Trend' | timestats name = 'Issues Trend' sum(Count) as Issues by Component, Error, Label, Node | fields -'Potential Issue', -Error
-
Widget title: CPU Cores (Used/Allocatable)
Tabs: Cluster, Workload, Node, Pod
Filters: Namespace, Workload, Node
Scope: Metric Explorer
Query:
clusterCPUUtilization[1m]{clusterName = "k8s_solution_development"}.mean()
For an example query with filters, see Network Bandwidth widget query.
-
Widget title: Memory (Used/Allocatable)
Tabs: Cluster, Workload, Node, Pod
Filters: Namespace, Workload, Node
Scope: Metric Explorer
Query:
clusterMemoryUtilization[1m]{clusterName = "k8s_solution_development"}.mean()
For an example query with filters, see Network Bandwidth widget query.
-
Widget title: CPU Cores used
Tabs: Cluster, Workload, Node, Pod
Filters: Namespace, Workload, Node
Scope: Metric Explorer
Query:
podCpuUsage[1m]{clusterName = "oke-cw22-ll", namespace = "kube-system", nodeName = "192.0.2.1", podName =~"coredns*"}.mean().grouping().sum()
-
Widget title: Network Bandwidth
Tabs: Cluster, Workload, Node, Pod
Filters: Namespace, Workload, Node
Scope: Metric Explorer
Query:
container_network_receive_bytes_total[5m]{clusterName = "oke-cw22-ll", namespace=~"*", nodeName=~"*", pod=~"kube-proxy*" }.groupBy(interface).rate().filter(x=>x>=0)
container_network_transmit_bytes_total[5m]{clusterName = "oke-cw22-ll", namespace=~"*", nodeName=~"*", pod=~"kube-proxy*" }.groupBy(interface).rate().filter(x=>x>=0)
-
Widget title: API Server Request Duration
Tabs: Cluster, Workload, Node, Pod
Filters: None
Scope: Metric Explorer
Query:
apiserver_request_duration_seconds_sum[5m]{clusterName = "oke-cw22-ll",verb=~"LIST|GET|PUT|POST|PATCH|DELETE|APPLY"}.groupBy(verb).sum() / apiserver_request_duration_seconds_count[5m]{clusterName = "oke-cw22-ll",verb=~"LIST|GET|PUT|POST|PATCH|DELETE|APPLY"}.groupBy(verb).sum()
-
Widget title: etcd Request Duration
Tabs: Cluster
Filters: None
Scope: Metric Explorer
Query:
etcd_request_duration_seconds_sum[5m]{clusterName = "oke-cw22-ll"}.groupBy(le).sum()/etcd_request_duration_seconds_count[5m]{clusterName = "oke-cw22-ll"}.groupBy(le).sum()
-
Widget title: API Server Requests
Tabs: Cluster
Filters: None
Scope: Metric Explorer
Query:
apiserver_request_total[5m]{clusterName = "oke-cw22-ll"}.groupBy(code).rate().filter(x=>x>=0)
-
Widget title: API Response Size
Tabs: Cluster
Filters: None
Scope: Metric Explorer
Query:
apiserver_response_sizes_sum[5m]{clusterName = "oke-cw22-ll"}.groupBy(verb).sum() / apiserver_response_sizes_count[5m]{clusterName= "oke-cw22-ll"}.groupBy(verb).sum()
-
Widget title: API Request Execution Duration
Tabs: Cluster
Filters: None
Scope: Metric Explorer
Query:
apiserver_request_duration_seconds_sum[5m]{clusterName = "oke-cw22-ll", verb=~"LIST|GET|PUT|POST|PATCH|DELETE|APPLY"}.groupBy(verb).sum() / apiserver_request_duration_seconds_count[5m]{clusterName = "oke-cw22-ll", verb=~"LIST|GET|PUT|POST|PATCH|DELETE|APPLY"}.groupBy(verb).sum()
Queries for the Events Table
Tabs: Cluster, Workload, Node, Pod
Filters: Namespace
Scope: Log Explorer
Query:
'Log Source' = 'Kubernetes Event Object Logs' and 'Kubernetes Event Action' != deleted
| eval Object = 'Involved Object Kind' || ' - ' || 'Involved Object Name'
| link includenulls = true Object, 'Event Source Component', Event
| rename 'Event Source Component' as Component
| stats latest('Kubernetes Event Action') as Status, unique(Namespace) as Namespace, latest(Reason) as Reason, latest('Event Description') as Message, unique('Event Type') as Type, earliest('First Event Time') as 'First Event Time', latest('Last Event Time') as 'Last Event Time', latest('Event Count') as 'Event Count'
| eventstats count(Namespace) as Records by Namespace
| eval Age = 'Last Event Time' - 'First Event Time'
| createtable name = 'Namespace Summary' select Namespace, Records
| createtable name = 'Namespace Details' select Namespace, Type, Reason, 'Last Event Time', Age, Message, Object, Component
| sort Namespace, -'Last Event Time'
| fields -Event, -'Start Time', -'End Time', -'First Event Time', -Count
Queries for the Cluster Topology and Details Tables
-
Visualization: Workloads Summary
Tabs: Workload
Filters: Namespace, Workload
Scope: Log Explorer
Query:
'Log Source' in ('Kubernetes DaemonSet Object Logs', 'Kubernetes Deployment Object Logs', 'Kubernetes CronJob Object Logs', 'Kubernetes Job Object Logs', 'Kubernetes StatefulSet Object Logs') | eval Name = if('Log Source' = 'Kubernetes Deployment Object Logs', Deployment, 'Log Source' = 'Kubernetes DaemonSet Object Logs', DaemonSet, 'Log Source' = 'Kubernetes CronJob Object Logs', CronJob, 'Log Source' = 'Kubernetes Job Object Logs', Job, 'Log Source' = 'Kubernetes StatefulSet Object Logs', StatefulSet, null) | link Namespace, 'Log Source', Name | eval Type = if('Log Source' = 'Kubernetes Deployment Object Logs', literal(Deployment), 'Log Source' = 'Kubernetes DaemonSet Object Logs', literal(DaemonSet), 'Log Source' = 'Kubernetes CronJob Object Logs', literal(CronJob), 'Log Source' = 'Kubernetes Job Object Logs', literal(Job), 'Log Source' = 'Kubernetes StatefulSet Object Logs', literal(StatefulSet), null) | addfields [ 'Log Source' = 'Kubernetes Deployment Object Logs' | eventstats latest('Available Status') as 'DP Available', latest(Replicas) as 'DP Desired', latest('Ready Replicas') as 'DP Ready', latest('Updated Replicas') as 'DP Updated', latest('Available Replicas') as 'DP Available R', latest('Object Creation Time') as 'DP OCR' by Namespace, Name ], [ 'Log Source' = 'Kubernetes DaemonSet Object Logs' | eventstats latest('Desired Number Scheduled') as 'DM Desired', latest('Ready Count') as 'DM Ready', latest('Updated Replicas') as 'DM Updated', latest('Current Scheduled') as 'DM Scheduled', latest('Object Creation Time') as 'DM OCR' by Namespace, Name ], [ 'Log Source' = 'Kubernetes CronJob Object Logs' | eventstats latest(Schedule) as 'CR Schedule', latest(Suspend) as 'CR Suspended', latest('Last Schedule Time') as 'CR Last Schedule', latest('Object Creation Time') as 'CR OCR' by Namespace, Name ], [ 'Log Source' = 'Kubernetes Job Object Logs' | eventstats latest(Completions) as 'JB Completions', latest(Status) as 'JB Status', latest('Object Creation Time') as 'JB OCR' by Namespace, Name ], [ 'Log Source' = 'Kubernetes StatefulSet Object Logs' | eventstats latest(Replicas) as 'SS Replicas', latest('Current Replicas') as 'SS Current Replicas', latest('Desired Replicas') as 'SS Desired Replicas', latest('Ready Replicas') as 'SS Ready Replicas', latest('Object Creation Time') as 'SS OCR' by Namespace, Name ] | eval OCR = if('Log Source' = 'Kubernetes Deployment Object Logs', 'DP OCR', 'Log Source' = 'Kubernetes DaemonSet Object Logs', 'DM OCR', 'Log Source' = 'Kubernetes CronJob Object Logs', 'CR OCR', 'Log Source' = 'Kubernetes Job Object Logs', 'JB OCR', 'Log Source' = 'Kubernetes StatefulSet Object Logs', 'SS OCR', null) | eval Age = unit('End Time' - OCR, ms) | eval Status = if('Log Source' = 'Kubernetes Deployment Object Logs' and 'DP Available' = true, Available, 'Log Source' = 'Kubernetes DaemonSet Object Logs' and 'DM Desired' = 'DM Ready', Available, 'Log Source' = 'Kubernetes CronJob Object Logs' and 'CR Suspended' = true, Suspended || ' (Last Scheduled: ' || formatDate('CR Last Schedule') || ')', 'Log Source' = 'Kubernetes CronJob Object Logs' and 'CR Suspended' = false, ' Last Scheduled: ' || formatDate('CR Last Schedule'), 'Log Source' = 'Kubernetes Job Object Logs' and 'JB Status' = complete, Complete, 'Log Source' = 'Kubernetes Job Object Logs' and 'JB Status' = failed, Failed, 'Log Source' = 'Kubernetes Job Object Logs', 'JB Status', 'Log Source' = 'Kubernetes StatefulSet Object Logs' and ('SS Desired Replicas' = 'SS Replicas' and 'SS Desired Replicas' = 'SS Ready Replicas'), Available, 'Not Available') | createtable name = Workloads select Namespace, Type, Name, Status, Age | fields -'DP *', -'DM *', -'JB *', -'SS *', -OCR
-
Visualization: Node Summary
Tabs: Node
Filters: Namespace, Workload, Node
Scope: Log Explorer
Query:
'Log Source' = 'Kubernetes Node Object Logs' | link Node | stats latest('Ready Status') as 'Ready Status', latest('Ready Reason') as 'Ready Reason', latest('Disk Pressure Status') as 'Disk Pressure', latest('Memory Pressure Status') as 'Memory Pressure', latest('PID Pressure Status') as 'PID Pressure', latest(Architecture) as Arch, latest('Operating System Image') as 'OS Image', latest('Kernel Version') as Kernel, latest('Container Runtime Version') as 'Container Runtime', latest('Kubelet Version') as Kubelet, latest('KubeProxy Version') as KubeProxy, latest('CPU Allocatable') as 'CPU A', latest('CPU Capacity') as 'CPU C', latest('Memory Allocatable') as 'Memory A', latest('Memory Capacity') as 'Memory C' | eval Status = if('Ready Status' = true, Ready, 'Not Ready') | eval Issues = if('Disk Pressure' != true and 'Memory Pressure' != true and 'PID Pressure' != true and Status = Ready, 'No Issues', 'Disk Pressure' = true and 'Memory Pressure' = true and 'PID Pressure' = true, 'Low on Disk, Memory and PID', 'Disk Pressure' = true and 'Memory Pressure' = true and 'PID Pressure' != true, 'Low on Disk and Memory', 'Disk Pressure' = true and 'Memory Pressure' != true and 'PID Pressure' = true, 'Low on Disk and PID', 'Disk Pressure' = true and 'Memory Pressure' != true and 'PID Pressure' != true, 'Low on Disk', 'Disk Pressure' != true and 'Memory Pressure' = true and 'PID Pressure' = true, 'Low on Memory and PID', 'Disk Pressure' != true and 'Memory Pressure' = true and 'PID Pressure' != true, 'Low on Memory', 'Disk Pressure' != true and 'Memory Pressure' != true and 'PID Pressure' = true, 'Low on PID', Status = 'Not Ready' and 'Ready Reason' != null, 'Ready Reason', Unknown) | eval CPU = 'CPU C' || ' / ' || 'CPU A' | eval 'Memory (Capacity)' = unit('Memory C', byte) | eval 'Memory (Allocatable)' = unit('Memory A', byte) | eval Age = unit('Query End Time' - 'End Time', ms) | eval 'Kubelet / KubeProxy Versions' = Kubelet || ' / ' || KubeProxy | eval OS = 'OS Image' || ' (' || Arch || ') ' || Kernel | createtable name = 'Node Summary' select Node as Name, Status, Issues, Age, OS, 'Container Runtime', 'Kubelet / KubeProxy Versions', CPU, 'Memory (Capacity)', 'Memory (Allocatable)'
-
Visualization: Pod Summary
Tabs: Pod
Filters: Namespace, Workload, Node
Scope: Log Explorer
Query:
'Log Source' = 'Kubernetes Pod Object Logs' | link Pod | stats latest('Pod Phase') as Status, latest(Node) as Node, latest(Namespace) as Namespace, latest('Pod IP Address') as 'Pod IP', latest(Controller) as Controller, latest('Controller Kind') as 'Controller Kind', latest('Scheduler Name') as Scheduler | createtable name = 'Pod Summary' select Pod as Name, Status, Node, Namespace, 'Pod IP', Controller, 'Controller Kind', Scheduler | fields 'End Time' as 'Last Reported', -Count