1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(k8s/container): realtime metrics (#4416)

* feat(k8s/container): metrics layout

* feat(k8s/container): memory graph

* feat(k8s/container): cpu usage percent

* feat(k8s/metrics): metrics api validation to enable metrics server

* feat(k8s/pods): update error metrics view

* feat(k8s/container): improve stopRepeater function

* feat(k8s/pods): display empty view instead of empty graphs

* feat(k8s/pods): fix CPU usage

* feat(k8s/configure): fix the metrics server test

* feat(k8s/pod): fix cpu issue

* feat(k8s/pod): fix toaster for non register pods in metrics server

* feat(k8s/service): remove options before 30 secondes for refresh rate

* feat(k8s/pod): fix default value for the refresh rate

* feat(k8s/pod): fix rebase
This commit is contained in:
Alice Groux 2021-04-29 03:10:14 +02:00 committed by GitHub
parent befccacc27
commit d99358ea8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 411 additions and 3 deletions

View file

@ -0,0 +1,53 @@
import angular from 'angular';
import PortainerError from 'Portainer/error';
import { KubernetesCommonParams } from 'Kubernetes/models/common/params';
class KubernetesMetricsService {
/* @ngInject */
constructor($async, KubernetesMetrics) {
this.$async = $async;
this.KubernetesMetrics = KubernetesMetrics;
this.capabilitiesAsync = this.capabilitiesAsync.bind(this);
this.getPodAsync = this.getPodAsync.bind(this);
}
/**
* GET
*/
async capabilitiesAsync(endpointID) {
try {
await this.KubernetesMetrics().capabilities({ endpointId: endpointID }).$promise;
} catch (err) {
throw new PortainerError('Unable to retrieve metrics', err);
}
}
capabilities(endpointID) {
return this.$async(this.capabilitiesAsync, endpointID);
}
/**
* Stats
*
* @param {string} namespace
* @param {string} podName
*/
async getPodAsync(namespace, podName) {
try {
const params = new KubernetesCommonParams();
params.id = podName;
const data = await this.KubernetesMetrics(namespace).getPod(params).$promise;
return data;
} catch (err) {
throw new PortainerError('Unable to retrieve pod stats', err);
}
}
getPod(namespace, podName) {
return this.$async(this.getPodAsync, namespace, podName);
}
}
export default KubernetesMetricsService;
angular.module('portainer.kubernetes').service('KubernetesMetricsService', KubernetesMetricsService);

View file

@ -0,0 +1,27 @@
angular.module('portainer.kubernetes').factory('KubernetesMetrics', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
function KubernetesMetrics($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
return function (namespace) {
const url = API_ENDPOINT_ENDPOINTS + '/:endpointId/kubernetes/apis/metrics.k8s.io/v1beta1';
const podUrl = `${url}${namespace ? '/namespaces/:namespace' : ''}/pods/:id`;
return $resource(
url,
{
endpointId: EndpointProvider.endpointID,
namespace: namespace,
},
{
capabilities: { method: 'GET' },
getPod: {
method: 'GET',
url: podUrl,
},
}
);
};
},
]);