简体   繁体   中英

How to get kubernetes pod metrics with nodejs

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?

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(...);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM