← All cheatsheets
$ kubectl get servicemonitors -AInstall the kube-prometheus-stack, check scrape targets and rules, and copy the PromQL queries you need most for Kubernetes.
Install and access
helm repo add prometheus-community https://prometheus-community.github.io/helm-chartsAdd the community chart repohelm install kps prometheus-community/kube-prometheus-stack -n monitoring --create-namespaceInstall Prometheus, Alertmanager and Grafanakubectl -n monitoring get svcFind the Prometheus and Grafana serviceskubectl -n monitoring port-forward svc/kps-kube-prometheus-stack-prometheus 9090Open Prometheus on localhost:9090kubectl get servicemonitors,podmonitors,prometheusrules -AList scrape and rule objectspromtool check rules rules.yamlValidate alerting and recording rulespromtool check config prometheus.ymlValidate a Prometheus configCluster health queries
up == 0Targets that are downkube_pod_status_phase{phase="Pending"} == 1Pods stuck in Pendingincrease(kube_pod_container_status_restarts_total[1h]) > 3Containers restarting oftenkube_deployment_status_replicas_available / kube_deployment_spec_replicas < 1Deployments missing replicas(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100Node memory used, in percentpredict_linear(node_filesystem_avail_bytes[6h], 24*3600) < 0Disks that will fill within a daykubelet_volume_stats_used_bytes / kubelet_volume_stats_capacity_bytes > 0.8PVCs over 80 percent fullWorkload and app queries
sum by (pod) (rate(container_cpu_usage_seconds_total{namespace="prod"}[5m]))CPU per podsum by (pod) (container_memory_working_set_bytes{namespace="prod"})Memory per podtopk(5, sum by (pod) (rate(container_cpu_usage_seconds_total[5m])))Top 5 CPU heavy podssum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))Error ratiohistogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))p95 latencyServiceMonitor example
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: api
namespace: prod
labels:
release: kps
spec:
selector:
matchLabels:
app: api
endpoints:
- port: metrics
interval: 30s
path: /metrics