1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(kubernetes/resource-usage): k8s resource usage for cluster, node and namespace EE-3 EE-1112 (#5301)

* backported resource usage functionality from EE

* utilising view bound endpoint object instead of depracated EndpointProvider

* refactor flatmap

* addressed merge conflict issues
This commit is contained in:
zees-dev 2021-07-28 14:26:03 +12:00 committed by GitHub
parent cee7ac26e9
commit ce31de5e9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 188 additions and 30 deletions

View file

@ -9,8 +9,12 @@ class KubernetesMetricsService {
this.KubernetesMetrics = KubernetesMetrics;
this.capabilitiesAsync = this.capabilitiesAsync.bind(this);
this.getPodAsync = this.getPodAsync.bind(this);
this.getNodeAsync = this.getNodeAsync.bind(this);
this.getPodsAsync = this.getPodsAsync.bind(this);
this.getNodesAsync = this.getNodesAsync.bind(this);
}
/**
@ -68,6 +72,42 @@ class KubernetesMetricsService {
getPod(namespace, podName) {
return this.$async(this.getPodAsync, namespace, podName);
}
/**
* Stats of Nodes in cluster
*
* @param {string} endpointID
*/
async getNodesAsync(endpointID) {
try {
const data = await this.KubernetesMetrics().getNodes({ endpointId: endpointID }).$promise;
return data;
} catch (err) {
throw new PortainerError('Unable to retrieve nodes stats', err);
}
}
getNodes(endpointID) {
return this.$async(this.getNodesAsync, endpointID);
}
/**
* Stats of Pods in a namespace
*
* @param {string} namespace
*/
async getPodsAsync(namespace) {
try {
const data = await this.KubernetesMetrics(namespace).getPods().$promise;
return data;
} catch (err) {
throw new PortainerError('Unable to retrieve pod stats', err);
}
}
getPods(namespace) {
return this.$async(this.getPodsAsync, namespace);
}
}
export default KubernetesMetricsService;