Reputation: 3322
I am using the nodejs kubernetes client @kubernetes/client-node in a current project and I want to collect metrics (memory, network, cpu) from pods
now with the cli I'd just use
kubectl top pods
or exec /sys/fs/cgroups/cpu/...
However I was unable to find the correct API or call in the npm package. Unfortunately the documentation only points to the official API Reference which unfortunately doesn't help me in this case.
So to boil the question down it would be.
How can I get metrics from a pod using the node.js @kubernetes/client-node module?
Upvotes: 0
Views: 1440
Reputation: 12995
The GitHub repository contains the following two examples:
The essential parts:
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
// node
k8s.topNodes(k8sApi).then(...);
// pods
const metricsClient = new k8s.Metrics(kc);
k8s.topPods(k8sApi, metricsClient).then(...);
k8s.topPods(k8sApi, metricsClient, "namespace").then(...);
Upvotes: 1