Giter Site home page Giter Site logo

bygui86 / k8s-example-resource-monitoring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wuestkamp/k8s-example-resource-monitoring

0.0 0.0 0.0 12 KB

Find out how much resources your Kubernetes Pods actually use and visualise CPU throttling.

Shell 100.00%

k8s-example-resource-monitoring's Introduction

Kubernetes Resource Monitoring by example

Medium article: https://medium.com/@wuestkamp/k8s-monitor-pod-cpu-and-memory-usage-with-prometheus-28eec6d84729?source=friends_link&sk=b498011bceb730596ee93d56869a2f5c

NOTICE If some of the Prometheus queries are not working for you it might be because of pod_name or container_name have been renamed to pod and container in other metrics-server version.

run yourself

You need a cluster, like with Gcloud:

gcloud container clusters create resources --num-nodes 3 --zone europe-west3-b --machine-type n1-standard-2

Install helm repos:

Helmfile is used for managing helm repos.

kubectl create ns grafana
kubectl create ns prometheus

# if you need to install metrics-server create the namespace and uncomment code in i/helm/helmfile.yaml
#kubectl create ns metrics-server

cd i/helm
helmfile diff
helmfile sync

Install k8s test app:

kubectl apply -f i/k8s

monitor

Run Grafana

./run/grafana.sh

Then head to http://localhost:3000/login

User: admin

Password: printed in the terminal output.

install Dashboard

Go to http://localhost:3000/dashboard/import and import the dashboard from i/grafana/dashboard.json

Use resources

kubectl run curl --image=curlimages/curl --rm --restart=Never -it sh

# use cluster internal compute pod IP
curl --data "millicores=400&durationSec=3600" 10.12.0.11:8080/ConsumeCPU
curl --data "megabytes=400&durationSec=300" 10.12.2.13:8080/ConsumeMem

Prometheus queries

cpu

# container usage
rate (container_cpu_usage_seconds_total{pod_name=~"compute-.*", image!="", container!="POD"}[5m])

# container requests
avg(kube_pod_container_resource_requests_cpu_cores{pod=~"compute-.*"})

# container limits
avg(kube_pod_container_resource_limits_cpu_cores{pod=~"compute-.*"})

# throttling
rate(container_cpu_cfs_throttled_seconds_total{pod=~"compute-.*", container!="POD", image!=""}[5m])

memory

# container usage
container_memory_working_set_bytes{pod_name=~"compute-.*", image!="", container!="POD"}

# container requests
avg(kube_pod_container_resource_requests_memory_bytes{pod=~"compute-.*"})

# container limits
avg(kube_pod_container_resource_limits_memory_bytes{pod=~"compute-.*"})

k8s-example-resource-monitoring's People

Contributors

wuestkamp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.