mirror of
https://github.com/portainer/portainer.git
synced 2025-08-03 04:45:21 +02:00
fix(gke): port metrics to the backend EE-5447 (#9041)
This commit is contained in:
parent
e996d29d52
commit
704d70c99b
15 changed files with 441 additions and 247 deletions
|
@ -6,8 +6,11 @@ import { withError } from '@/react-tools/react-query';
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { isFulfilled } from '@/portainer/helpers/promise-utils';
|
||||
|
||||
import { Service } from './types';
|
||||
import {
|
||||
NodeMetrics,
|
||||
NodeMetric,
|
||||
Service,
|
||||
} from '@/react/kubernetes/services/types';
|
||||
|
||||
export const queryKeys = {
|
||||
clusterServices: (environmentId: EnvironmentId) =>
|
||||
|
@ -105,3 +108,67 @@ export async function deleteServices({
|
|||
throw parseAxiosError(e as Error, 'Unable to delete service(s)');
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMetricsForAllNodes(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: nodes } = await axios.get<NodeMetrics>(
|
||||
`kubernetes/${environmentId}/metrics/nodes`,
|
||||
{}
|
||||
);
|
||||
return nodes;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(
|
||||
e as Error,
|
||||
'Unable to retrieve metrics for all nodes'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMetricsForNode(
|
||||
environmentId: EnvironmentId,
|
||||
nodeName: string
|
||||
) {
|
||||
try {
|
||||
const { data: node } = await axios.get<NodeMetric>(
|
||||
`kubernetes/${environmentId}/metrics/nodes/${nodeName}`,
|
||||
{}
|
||||
);
|
||||
return node;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve metrics for node');
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMetricsForAllPods(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string
|
||||
) {
|
||||
try {
|
||||
const { data: pods } = await axios.get(
|
||||
`kubernetes/${environmentId}/metrics/pods/namespace/${namespace}`,
|
||||
{}
|
||||
);
|
||||
return pods;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(
|
||||
e as Error,
|
||||
'Unable to retrieve metrics for all pods'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMetricsForPod(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
podName: string
|
||||
) {
|
||||
try {
|
||||
const { data: pod } = await axios.get(
|
||||
`kubernetes/${environmentId}/metrics/pods/namespace/${namespace}/${podName}`,
|
||||
{}
|
||||
);
|
||||
return pod;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve metrics for pod');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,3 +39,24 @@ export type Service = {
|
|||
CreationTimestamp: string;
|
||||
Applications?: Application[];
|
||||
};
|
||||
|
||||
export type NodeMetrics = {
|
||||
items: NodeMetric[];
|
||||
};
|
||||
|
||||
export type NodeMetric = {
|
||||
metadata: NodeMetricMetadata;
|
||||
timestamp: Date;
|
||||
usage: Usage;
|
||||
window: string;
|
||||
};
|
||||
|
||||
export type NodeMetricMetadata = {
|
||||
creationTimestamp: Date;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Usage = {
|
||||
cpu: string;
|
||||
memory: string;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue