mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert all metric requests to be injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
12beacec81
commit
35f3c08279
43 files changed
+869
-441
No files matched your search
@@ -3,8 +3,6 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { MetricData, IMetricsReqParams } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
@@ -28,30 +26,6 @@ export class ClusterApi extends KubeApi<Cluster> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsByNodeNames(nodeNames: string[], params?: IMetricsReqParams): Promise<ClusterMetricData> {
|
||||
const nodes = nodeNames.join("|");
|
||||
const opts = { category: "cluster", nodes };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
memoryUsage: opts,
|
||||
workloadMemoryUsage: opts,
|
||||
memoryRequests: opts,
|
||||
memoryLimits: opts,
|
||||
memoryCapacity: opts,
|
||||
memoryAllocatableCapacity: opts,
|
||||
cpuUsage: opts,
|
||||
cpuRequests: opts,
|
||||
cpuLimits: opts,
|
||||
cpuCapacity: opts,
|
||||
cpuAllocatableCapacity: opts,
|
||||
podUsage: opts,
|
||||
podCapacity: opts,
|
||||
podAllocatableCapacity: opts,
|
||||
fsSize: opts,
|
||||
fsUsage: opts,
|
||||
}, params);
|
||||
}
|
||||
|
||||
export enum ClusterStatus {
|
||||
ACTIVE = "Active",
|
||||
CREATING = "Creating",
|
||||
@@ -59,21 +33,6 @@ export enum ClusterStatus {
|
||||
ERROR = "Error",
|
||||
}
|
||||
|
||||
export interface ClusterMetricData extends Partial<Record<string, MetricData>> {
|
||||
memoryUsage: MetricData;
|
||||
memoryRequests: MetricData;
|
||||
memoryLimits: MetricData;
|
||||
memoryCapacity: MetricData;
|
||||
cpuUsage: MetricData;
|
||||
cpuRequests: MetricData;
|
||||
cpuLimits: MetricData;
|
||||
cpuCapacity: MetricData;
|
||||
podUsage: MetricData;
|
||||
podCapacity: MetricData;
|
||||
fsSize: MetricData;
|
||||
fsUsage: MetricData;
|
||||
}
|
||||
|
||||
export interface Cluster {
|
||||
spec: {
|
||||
clusterNetwork?: {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { PodTemplateSpec } from "./types/pod-template-spec";
|
||||
@@ -90,20 +88,3 @@ export class DaemonSetApi extends KubeApi<DaemonSet> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForDaemonSets(daemonsets: DaemonSet[], namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const podSelector = daemonsets.map(daemonset => `${daemonset.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import moment from "moment";
|
||||
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData, PodSpec } from "./pod.api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isNumber, isObject } from "../../utils";
|
||||
@@ -70,23 +69,6 @@ export class DeploymentApi extends KubeApi<Deployment> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForDeployments(deployments: Deployment[], namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const podSelector = deployments.map(deployment => `${deployment.getName()}-[[:alnum:]]{9,}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface DeploymentSpec {
|
||||
replicas: number;
|
||||
selector: LabelSelector;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isString, iter } from "../../utils";
|
||||
import type { MetricData } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
@@ -24,26 +22,6 @@ export class IngressApi extends KubeApi<Ingress> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForIngress(ingress: string, namespace: string): Promise<IngressMetricData> {
|
||||
const opts = { category: "ingress", ingress, namespace };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
bytesSentSuccess: opts,
|
||||
bytesSentFailure: opts,
|
||||
requestDurationSeconds: opts,
|
||||
responseDurationSeconds: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface IngressMetricData extends Partial<Record<string, MetricData>> {
|
||||
bytesSentSuccess: MetricData;
|
||||
bytesSentFailure: MetricData;
|
||||
requestDurationSeconds: MetricData;
|
||||
responseDurationSeconds: MetricData;
|
||||
}
|
||||
|
||||
export interface ILoadBalancerIngress {
|
||||
hostname?: string;
|
||||
ip?: string;
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData, PodSpec } from "./pod.api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { Container } from "./types/container";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@@ -103,20 +102,3 @@ export class JobApi extends KubeApi<Job> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForJobs(jobs: Job[], namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const podSelector = jobs.map(job => `${job.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
// Metrics api
|
||||
|
||||
import moment from "moment";
|
||||
import { apiBase } from "../index";
|
||||
import { isDefined, object } from "../../utils";
|
||||
|
||||
export interface MetricData {
|
||||
status: string;
|
||||
@@ -29,63 +29,6 @@ export interface MetricResult {
|
||||
values: [number, string][];
|
||||
}
|
||||
|
||||
export interface MetricProviderInfo {
|
||||
name: string;
|
||||
id: string;
|
||||
isConfigurable: boolean;
|
||||
}
|
||||
|
||||
export interface IMetricsReqParams {
|
||||
start?: number | string; // timestamp in seconds or valid date-string
|
||||
end?: number | string;
|
||||
step?: number; // step in seconds (default: 60s = each point 1m)
|
||||
range?: number; // time-range in seconds for data aggregation (default: 3600s = last 1h)
|
||||
namespace?: string; // rbac-proxy validation param
|
||||
}
|
||||
|
||||
export interface IResourceMetrics<T extends MetricData> {
|
||||
[metric: string]: T;
|
||||
cpuUsage: T;
|
||||
memoryUsage: T;
|
||||
fsUsage: T;
|
||||
fsWrites: T;
|
||||
fsReads: T;
|
||||
networkReceive: T;
|
||||
networkTransmit: T;
|
||||
}
|
||||
|
||||
async function getMetrics(query: string, reqParams?: IMetricsReqParams): Promise<MetricData>;
|
||||
async function getMetrics(query: string[], reqParams?: IMetricsReqParams): Promise<MetricData[]>;
|
||||
async function getMetrics<MetricNames extends string>(query: Record<MetricNames, Partial<Record<string, string>>>, reqParams?: IMetricsReqParams): Promise<Record<MetricNames, MetricData>>;
|
||||
|
||||
async function getMetrics(query: string | string[] | Partial<Record<string, Partial<Record<string, string>>>>, reqParams: IMetricsReqParams = {}): Promise<MetricData | MetricData[] | Partial<Record<string, MetricData>>> {
|
||||
const { range = 3600, step = 60, namespace } = reqParams;
|
||||
let { start, end } = reqParams;
|
||||
|
||||
if (!start && !end) {
|
||||
const timeNow = Date.now() / 1000;
|
||||
const now = moment.unix(timeNow).startOf("minute").unix(); // round date to minutes
|
||||
|
||||
start = now - range;
|
||||
end = now;
|
||||
}
|
||||
|
||||
return apiBase.post("/metrics", {
|
||||
data: query,
|
||||
query: {
|
||||
start, end, step,
|
||||
"kubernetes_namespace": namespace,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const metricsApi = {
|
||||
getMetrics,
|
||||
async getMetricProviders(): Promise<MetricProviderInfo[]> {
|
||||
return apiBase.get("/metrics/providers");
|
||||
},
|
||||
};
|
||||
|
||||
export function normalizeMetrics(metrics: MetricData | undefined | null, frames = 60): MetricData {
|
||||
if (!metrics?.data?.result) {
|
||||
return {
|
||||
@@ -145,7 +88,7 @@ export function isMetricsEmpty(metrics: Partial<Record<string, MetricData>>) {
|
||||
return Object.values(metrics).every(metric => !metric?.data?.result?.length);
|
||||
}
|
||||
|
||||
export function getItemMetrics(metrics: Partial<Record<string, MetricData>> | null | undefined, itemName: string): Partial<Record<string, MetricData>> | undefined {
|
||||
export function getItemMetrics<Keys extends string>(metrics: Partial<Record<Keys, MetricData>> | null | undefined, itemName: string): Partial<Record<Keys, MetricData>> | undefined {
|
||||
if (!metrics) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -166,22 +109,16 @@ export function getItemMetrics(metrics: Partial<Record<string, MetricData>> | nu
|
||||
return itemMetrics;
|
||||
}
|
||||
|
||||
export function getMetricLastPoints<T extends Partial<Record<string, MetricData>>>(metrics: T): Record<keyof T, number> {
|
||||
const result: Partial<{ [metric: string]: number }> = {};
|
||||
|
||||
Object.keys(metrics).forEach(metricName => {
|
||||
try {
|
||||
const metric = metrics[metricName];
|
||||
|
||||
if (metric?.data.result.length) {
|
||||
result[metricName] = +metric.data.result[0].values.slice(-1)[0][1];
|
||||
}
|
||||
} catch {
|
||||
// ignore error
|
||||
}
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
return result as Record<keyof T, number>;
|
||||
export function getMetricLastPoints<Keys extends string>(metrics: Partial<Record<Keys, MetricData>>): Partial<Record<Keys, number>> {
|
||||
return object.fromEntries(
|
||||
object.entries(metrics)
|
||||
.map(([metricName, metric]) => {
|
||||
try {
|
||||
return [metricName, +metric.data.result[0].values.slice(-1)[0][1]] as const;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter(isDefined),
|
||||
);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { RequestMetricsParams } from "./get.injectable";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface ClusterMetricData {
|
||||
memoryUsage: MetricData;
|
||||
memoryRequests: MetricData;
|
||||
memoryLimits: MetricData;
|
||||
memoryCapacity: MetricData;
|
||||
memoryAllocatableCapacity: MetricData;
|
||||
cpuUsage: MetricData;
|
||||
cpuRequests: MetricData;
|
||||
cpuLimits: MetricData;
|
||||
cpuCapacity: MetricData;
|
||||
cpuAllocatableCapacity: MetricData;
|
||||
podUsage: MetricData;
|
||||
podCapacity: MetricData;
|
||||
podAllocatableCapacity: MetricData;
|
||||
fsSize: MetricData;
|
||||
fsUsage: MetricData;
|
||||
}
|
||||
|
||||
export type RequestClusterMetricsByNodeNames = (nodeNames: string[], params?: RequestMetricsParams) => Promise<ClusterMetricData>;
|
||||
|
||||
const requestClusterMetricsByNodeNamesInjectable = getInjectable({
|
||||
id: "get-cluster-metrics-by-node-names",
|
||||
instantiate: (di): RequestClusterMetricsByNodeNames => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (nodeNames, params) => {
|
||||
const opts = {
|
||||
category: "cluster",
|
||||
nodes: nodeNames.join("|"),
|
||||
};
|
||||
|
||||
return requestMetrics({
|
||||
memoryUsage: opts,
|
||||
workloadMemoryUsage: opts,
|
||||
memoryRequests: opts,
|
||||
memoryLimits: opts,
|
||||
memoryCapacity: opts,
|
||||
memoryAllocatableCapacity: opts,
|
||||
cpuUsage: opts,
|
||||
cpuRequests: opts,
|
||||
cpuLimits: opts,
|
||||
cpuCapacity: opts,
|
||||
cpuAllocatableCapacity: opts,
|
||||
podUsage: opts,
|
||||
podCapacity: opts,
|
||||
podAllocatableCapacity: opts,
|
||||
fsSize: opts,
|
||||
fsUsage: opts,
|
||||
}, params);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestClusterMetricsByNodeNamesInjectable;
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface IngressMetricData {
|
||||
bytesSentSuccess: MetricData;
|
||||
bytesSentFailure: MetricData;
|
||||
requestDurationSeconds: MetricData;
|
||||
responseDurationSeconds: MetricData;
|
||||
}
|
||||
|
||||
export type RequestIngressMetrics = (ingress: string, namespace: string) => Promise<IngressMetricData>;
|
||||
|
||||
const requestIngressMetricsInjectable = getInjectable({
|
||||
id: "request-ingress-metrics",
|
||||
instantiate: (di): RequestIngressMetrics => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (ingress, namespace) => {
|
||||
const opts = { category: "ingress", ingress, namespace };
|
||||
|
||||
return requestMetrics({
|
||||
bytesSentSuccess: opts,
|
||||
bytesSentFailure: opts,
|
||||
requestDurationSeconds: opts,
|
||||
responseDurationSeconds: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestIngressMetricsInjectable;
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface NodeMetricData {
|
||||
memoryUsage: MetricData;
|
||||
workloadMemoryUsage: MetricData;
|
||||
memoryCapacity: MetricData;
|
||||
memoryAllocatableCapacity: MetricData;
|
||||
cpuUsage: MetricData;
|
||||
cpuCapacity: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsSize: MetricData;
|
||||
}
|
||||
|
||||
export type RequestAllNodeMetrics = () => Promise<NodeMetricData>;
|
||||
|
||||
const requestAllNodeMetricsInjectable = getInjectable({
|
||||
id: "request-all-node-metrics",
|
||||
instantiate: (di): RequestAllNodeMetrics => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return () => {
|
||||
const opts = { category: "nodes" };
|
||||
|
||||
return requestMetrics({
|
||||
memoryUsage: opts,
|
||||
workloadMemoryUsage: opts,
|
||||
memoryCapacity: opts,
|
||||
memoryAllocatableCapacity: opts,
|
||||
cpuUsage: opts,
|
||||
cpuCapacity: opts,
|
||||
fsSize: opts,
|
||||
fsUsage: opts,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestAllNodeMetricsInjectable;
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { PersistentVolumeClaim } from "../persistent-volume-claim.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface PersistentVolumeClaimMetricData {
|
||||
diskUsage: MetricData;
|
||||
diskCapacity: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPersistentVolumeClaimMetrics = (claim: PersistentVolumeClaim) => Promise<PersistentVolumeClaimMetricData>;
|
||||
|
||||
const requestPersistentVolumeClaimMetricsInjectable = getInjectable({
|
||||
id: "request-persistent-volume-claim-metrics",
|
||||
instantiate: (di): RequestPersistentVolumeClaimMetrics => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (claim) => {
|
||||
const opts = { category: "pvc", pvc: claim.getName(), namespace: claim.getNs() };
|
||||
|
||||
return requestMetrics({
|
||||
diskUsage: opts,
|
||||
diskCapacity: opts,
|
||||
}, {
|
||||
namespace: opts.namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPersistentVolumeClaimMetricsInjectable;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { DaemonSet } from "../daemon-set.api";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface DaemonSetPodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsForDaemonSets = (daemonsets: DaemonSet[], namespace: string, selector?: string) => Promise<DaemonSetPodMetricData>;
|
||||
|
||||
const requestPodMetricsForDaemonSetsInjectable = getInjectable({
|
||||
id: "request-pod-metrics-for-daemon-sets",
|
||||
instantiate: (di): RequestPodMetricsForDaemonSets => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (daemonSets, namespace, selector = "") => {
|
||||
const podSelector = daemonSets.map(daemonSet => `${daemonSet.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsForDaemonSetsInjectable;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Deployment } from "../deployment.api";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface DeploymentPodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsForDeployments = (deployments: Deployment[], namespace: string, selector?: string) => Promise<DeploymentPodMetricData>;
|
||||
|
||||
const requestPodMetricsForDeploymentsInjectable = getInjectable({
|
||||
id: "request-pod-metrics-for-deployments",
|
||||
instantiate: (di): RequestPodMetricsForDeployments => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (deployments, namespace, selector = "") => {
|
||||
const podSelector = deployments.map(deployment => `${deployment.getName()}-[[:alnum:]]{9,}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsForDeploymentsInjectable;
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Job } from "../job.api";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface JobPodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsForJobs = (jobs: Job[], namespace: string, selector?: string) => Promise<JobPodMetricData>;
|
||||
|
||||
const requestPodMetricsForJobsInjectable = getInjectable({
|
||||
id: "request-pod-metrics-for-jobs",
|
||||
instantiate: (di): RequestPodMetricsForJobs => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (jobs, namespace, selector) => {
|
||||
const podSelector = jobs.map(job => `${job.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsForJobsInjectable;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { ReplicaSet } from "../replica-set.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface ReplicaSetPodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsForReplicaSets = (replicaSets: ReplicaSet[], namespace: string, selector?: string) => Promise<ReplicaSetPodMetricData>;
|
||||
|
||||
const requestPodMetricsForReplicaSetsInjectable = getInjectable({
|
||||
id: "request-pod-metrics-for-replica-sets",
|
||||
instantiate: (di): RequestPodMetricsForReplicaSets => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (replicaSets, namespace, selector = "") => {
|
||||
const podSelector = replicaSets.map(replicaSet => `${replicaSet.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsForReplicaSetsInjectable;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { StatefulSet } from "../stateful-set.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface StatefulSetPodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsForStatefulSets = (statefulSets: StatefulSet[], namespace: string, selector?: string) => Promise<StatefulSetPodMetricData>;
|
||||
|
||||
const requestPodMetricsForStatefulSetsInjectable = getInjectable({
|
||||
id: "request-pod-metrics-for-stateful-sets",
|
||||
instantiate: (di): RequestPodMetricsForStatefulSets => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (statefulSets, namespace, selector = "") => {
|
||||
const podSelector = statefulSets.map(statefulset => `${statefulset.getName()}-[[:digit:]]+`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsForStatefulSetsInjectable;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface PodMetricInNamespaceData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetricsInNamespace = (namespace: string, selector?: string) => Promise<PodMetricInNamespaceData>;
|
||||
|
||||
const requestPodMetricsInNamespaceInjectable = getInjectable({
|
||||
id: "request-pod-metrics-in-namespace",
|
||||
instantiate: (di): RequestPodMetricsInNamespace => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (namespace, selector) => {
|
||||
const opts = { category: "pods", pods: ".*", namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsInNamespaceInjectable;
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { Pod } from "../pod.api";
|
||||
import requestMetricsInjectable from "./get.injectable";
|
||||
|
||||
export interface PodMetricData {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
cpuRequests: MetricData;
|
||||
cpuLimits: MetricData;
|
||||
memoryRequests: MetricData;
|
||||
memoryLimits: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetrics = (pods: Pod[], namespace: string, selector?: string) => Promise<PodMetricData>;
|
||||
|
||||
const requestPodMetricsInjectable = getInjectable({
|
||||
id: "request-pod-metrics",
|
||||
instantiate: (di): RequestPodMetrics => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (pods, namespace, selector = "pod, namespace") => {
|
||||
const podSelector = pods.map(pod => pod.getName()).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
cpuRequests: opts,
|
||||
cpuLimits: opts,
|
||||
memoryUsage: opts,
|
||||
memoryRequests: opts,
|
||||
memoryLimits: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestPodMetricsInjectable;
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
|
||||
export interface MetricProviderInfo {
|
||||
name: string;
|
||||
id: string;
|
||||
isConfigurable: boolean;
|
||||
}
|
||||
|
||||
export type RequestMetricsProviders = () => Promise<MetricProviderInfo[]>;
|
||||
|
||||
const requestMetricsProvidersInjectable = getInjectable({
|
||||
id: "request-metrics-providers",
|
||||
instantiate: (di): RequestMetricsProviders => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
|
||||
return () => apiBase.get("/metrics/providers");
|
||||
},
|
||||
});
|
||||
|
||||
export default requestMetricsProvidersInjectable;
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import moment from "moment";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
|
||||
|
||||
export interface RequestMetricsParams {
|
||||
/**
|
||||
* timestamp in seconds or valid date-string
|
||||
*/
|
||||
start?: number | string;
|
||||
|
||||
/**
|
||||
* timestamp in seconds or valid date-string
|
||||
*/
|
||||
end?: number | string;
|
||||
|
||||
/**
|
||||
* step in seconds
|
||||
* @default 60 (1 minute)
|
||||
*/
|
||||
step?: number;
|
||||
|
||||
/**
|
||||
* time-range in seconds for data aggregation
|
||||
* @default 3600 (1 hour)
|
||||
*/
|
||||
range?: number;
|
||||
|
||||
/**
|
||||
* rbac-proxy validation param
|
||||
*/
|
||||
namespace?: string;
|
||||
}
|
||||
|
||||
export interface RequestMetrics {
|
||||
(query: string, params?: RequestMetricsParams): Promise<MetricData>;
|
||||
(query: string[], params?: RequestMetricsParams): Promise<MetricData[]>;
|
||||
<Keys extends string>(query: Record<Keys, Partial<Record<string, string>>>, params?: RequestMetricsParams): Promise<Record<Keys, MetricData>>;
|
||||
}
|
||||
|
||||
const requestMetricsInjectable = getInjectable({
|
||||
id: "request-metrics",
|
||||
instantiate: (di) => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
|
||||
return (async (query: object, params: RequestMetricsParams = {}) => {
|
||||
const { range = 3600, step = 60, namespace } = params;
|
||||
let { start, end } = params;
|
||||
|
||||
if (!start && !end) {
|
||||
const timeNow = Date.now() / 1000;
|
||||
const now = moment.unix(timeNow).startOf("minute").unix(); // round date to minutes
|
||||
|
||||
start = now - range;
|
||||
end = now;
|
||||
}
|
||||
|
||||
return apiBase.post("/metrics", {
|
||||
data: query,
|
||||
query: {
|
||||
start, end, step,
|
||||
"kubernetes_namespace": namespace,
|
||||
},
|
||||
});
|
||||
}) as RequestMetrics;
|
||||
},
|
||||
});
|
||||
|
||||
export default requestMetricsInjectable;
|
||||
@@ -7,8 +7,6 @@ import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectStatus } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData } from "./pod.api";
|
||||
|
||||
export enum NamespaceStatusKind {
|
||||
ACTIVE = "Active",
|
||||
@@ -45,19 +43,3 @@ export class NamespaceApi extends KubeApi<Namespace> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForNamespace(namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const opts = { category: "pods", pods: ".*", namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
|
||||
import type { MetricData } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
@@ -21,32 +19,6 @@ export class NodeApi extends KubeApi<Node> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForAllNodes(): Promise<NodeMetricData> {
|
||||
const opts = { category: "nodes" };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
memoryUsage: opts,
|
||||
workloadMemoryUsage: opts,
|
||||
memoryCapacity: opts,
|
||||
memoryAllocatableCapacity: opts,
|
||||
cpuUsage: opts,
|
||||
cpuCapacity: opts,
|
||||
fsSize: opts,
|
||||
fsUsage: opts,
|
||||
});
|
||||
}
|
||||
|
||||
export interface NodeMetricData extends Partial<Record<string, MetricData>> {
|
||||
memoryUsage: MetricData;
|
||||
workloadMemoryUsage: MetricData;
|
||||
memoryCapacity: MetricData;
|
||||
memoryAllocatableCapacity: MetricData;
|
||||
cpuUsage: MetricData;
|
||||
cpuCapacity: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsSize: MetricData;
|
||||
}
|
||||
|
||||
export interface NodeTaint {
|
||||
key: string;
|
||||
value?: string;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
import type { LabelSelector, NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { MetricData } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { Pod } from "./pod.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
@@ -22,22 +20,6 @@ export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForPvc(pvc: PersistentVolumeClaim): Promise<PersistentVolumeClaimMetricData> {
|
||||
const opts = { category: "pvc", pvc: pvc.getName(), namespace: pvc.getNs() };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
diskUsage: opts,
|
||||
diskCapacity: opts,
|
||||
}, {
|
||||
namespace: opts.namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface PersistentVolumeClaimMetricData extends Partial<Record<string, MetricData>> {
|
||||
diskUsage: MetricData;
|
||||
diskCapacity: MetricData;
|
||||
}
|
||||
|
||||
export interface PersistentVolumeClaimSpec {
|
||||
accessModes?: string[];
|
||||
dataSource?: TypedLocalObjectReference;
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { MetricData } from "./metrics.api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions, ResourceDescriptor } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
@@ -33,41 +31,6 @@ export class PodApi extends KubeApi<Pod> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForPods(pods: Pod[], namespace: string, selector = "pod, namespace"): Promise<PodMetricData> {
|
||||
const podSelector = pods.map(pod => pod.getName()).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
cpuRequests: opts,
|
||||
cpuLimits: opts,
|
||||
memoryUsage: opts,
|
||||
memoryRequests: opts,
|
||||
memoryLimits: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface PodMetricData extends Partial<Record<string, MetricData>> {
|
||||
cpuUsage: MetricData;
|
||||
memoryUsage: MetricData;
|
||||
fsUsage: MetricData;
|
||||
fsWrites: MetricData;
|
||||
fsReads: MetricData;
|
||||
networkReceive: MetricData;
|
||||
networkTransmit: MetricData;
|
||||
cpuRequests?: MetricData;
|
||||
cpuLimits?: MetricData;
|
||||
memoryRequests?: MetricData;
|
||||
memoryLimits?: MetricData;
|
||||
}
|
||||
|
||||
// Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#read-log-pod-v1-core
|
||||
export interface PodLogsQuery {
|
||||
container?: string;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { PodTemplateSpec } from "./types/pod-template-spec";
|
||||
@@ -41,23 +39,6 @@ export class ReplicaSetApi extends KubeApi<ReplicaSet> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForReplicaSets(replicasets: ReplicaSet[], namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const podSelector = replicasets.map(replicaset => `${replicaset.getName()}-[[:alnum:]]{5}`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface ReplicaSetSpec {
|
||||
replicas?: number;
|
||||
selector: LabelSelector;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { PodMetricData } from "./pod.api";
|
||||
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { PodTemplateSpec } from "./types/pod-template-spec";
|
||||
@@ -46,23 +44,6 @@ export class StatefulSetApi extends KubeApi<StatefulSet> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetricsForStatefulSets(statefulSets: StatefulSet[], namespace: string, selector = ""): Promise<PodMetricData> {
|
||||
const podSelector = statefulSets.map(statefulset => `${statefulset.getName()}-[[:digit:]]+`).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
|
||||
return metricsApi.getMetrics({
|
||||
cpuUsage: opts,
|
||||
memoryUsage: opts,
|
||||
fsUsage: opts,
|
||||
fsWrites: opts,
|
||||
fsReads: opts,
|
||||
networkReceive: opts,
|
||||
networkTransmit: opts,
|
||||
}, {
|
||||
namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export interface StatefulSetSpec {
|
||||
serviceName: string;
|
||||
replicas: number;
|
||||
|
||||
Reference in new issue
Block a user