From c47c592ef211b8cabe4aadafdc400ce096239166 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Fri, 26 Nov 2021 16:03:12 +0100 Subject: [PATCH] Add more file system metrics to the pod and container graphs (#3961) --- src/common/k8s-api/endpoints/daemon-set.api.ts | 2 ++ src/common/k8s-api/endpoints/deployment.api.ts | 2 ++ src/common/k8s-api/endpoints/job.api.ts | 2 ++ src/common/k8s-api/endpoints/metrics.api.ts | 2 ++ src/common/k8s-api/endpoints/namespaces.api.ts | 2 ++ src/common/k8s-api/endpoints/pods.api.ts | 6 +++++- src/common/k8s-api/endpoints/replica-set.api.ts | 2 ++ src/common/k8s-api/endpoints/stateful-set.api.ts | 2 ++ src/main/prometheus/lens.ts | 4 ++++ src/main/prometheus/operator.ts | 4 ++++ src/main/prometheus/stacklight.ts | 4 ++++ .../+workloads-pods/container-charts.tsx | 16 ++++++++++++++++ .../components/+workloads-pods/pod-charts.tsx | 16 ++++++++++++++++ 13 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/common/k8s-api/endpoints/daemon-set.api.ts b/src/common/k8s-api/endpoints/daemon-set.api.ts index 44c99a13b8d69..7c5717ae10be7 100644 --- a/src/common/k8s-api/endpoints/daemon-set.api.ts +++ b/src/common/k8s-api/endpoints/daemon-set.api.ts @@ -110,6 +110,8 @@ export function getMetricsForDaemonSets(daemonsets: DaemonSet[], namespace: stri cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/common/k8s-api/endpoints/deployment.api.ts b/src/common/k8s-api/endpoints/deployment.api.ts index f4d82c64b3171..a59cdb8b31d6c 100644 --- a/src/common/k8s-api/endpoints/deployment.api.ts +++ b/src/common/k8s-api/endpoints/deployment.api.ts @@ -83,6 +83,8 @@ export function getMetricsForDeployments(deployments: Deployment[], namespace: s cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/common/k8s-api/endpoints/job.api.ts b/src/common/k8s-api/endpoints/job.api.ts index 4907e6c7960fd..8f96d8b15eda3 100644 --- a/src/common/k8s-api/endpoints/job.api.ts +++ b/src/common/k8s-api/endpoints/job.api.ts @@ -133,6 +133,8 @@ export function getMetricsForJobs(jobs: Job[], namespace: string, selector = "") cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/common/k8s-api/endpoints/metrics.api.ts b/src/common/k8s-api/endpoints/metrics.api.ts index 91587bff97762..bd6bc4709cf2b 100644 --- a/src/common/k8s-api/endpoints/metrics.api.ts +++ b/src/common/k8s-api/endpoints/metrics.api.ts @@ -65,6 +65,8 @@ export interface IResourceMetrics { cpuUsage: T; memoryUsage: T; fsUsage: T; + fsWrites: T; + fsReads: T; networkReceive: T; networkTransmit: T; } diff --git a/src/common/k8s-api/endpoints/namespaces.api.ts b/src/common/k8s-api/endpoints/namespaces.api.ts index 08e95933996c2..7a3a360ce0644 100644 --- a/src/common/k8s-api/endpoints/namespaces.api.ts +++ b/src/common/k8s-api/endpoints/namespaces.api.ts @@ -63,6 +63,8 @@ export function getMetricsForNamespace(namespace: string, selector = ""): Promis cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/common/k8s-api/endpoints/pods.api.ts b/src/common/k8s-api/endpoints/pods.api.ts index 361e72ca54cb7..2c1bfdc6e8620 100644 --- a/src/common/k8s-api/endpoints/pods.api.ts +++ b/src/common/k8s-api/endpoints/pods.api.ts @@ -46,6 +46,8 @@ export function getMetricsForPods(pods: Pod[], namespace: string, selector = "po memoryRequests: opts, memoryLimits: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { @@ -57,7 +59,9 @@ export interface IPodMetrics { [metric: string]: T; cpuUsage: T; memoryUsage: T; - fsUsage: T; + fsUsage: T, + fsWrites: T, + fsReads: T, networkReceive: T; networkTransmit: T; cpuRequests?: T; diff --git a/src/common/k8s-api/endpoints/replica-set.api.ts b/src/common/k8s-api/endpoints/replica-set.api.ts index 7a9a76ec060ff..50240621740b0 100644 --- a/src/common/k8s-api/endpoints/replica-set.api.ts +++ b/src/common/k8s-api/endpoints/replica-set.api.ts @@ -59,6 +59,8 @@ export function getMetricsForReplicaSets(replicasets: ReplicaSet[], namespace: s cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/common/k8s-api/endpoints/stateful-set.api.ts b/src/common/k8s-api/endpoints/stateful-set.api.ts index dd97e01e05702..1a844da7e4077 100644 --- a/src/common/k8s-api/endpoints/stateful-set.api.ts +++ b/src/common/k8s-api/endpoints/stateful-set.api.ts @@ -62,6 +62,8 @@ export function getMetricsForStatefulSets(statefulSets: StatefulSet[], namespace cpuUsage: opts, memoryUsage: opts, fsUsage: opts, + fsWrites: opts, + fsReads: opts, networkReceive: opts, networkTransmit: opts, }, { diff --git a/src/main/prometheus/lens.ts b/src/main/prometheus/lens.ts index 026e91f03be44..2debb817cf9c2 100644 --- a/src/main/prometheus/lens.ts +++ b/src/main/prometheus/lens.ts @@ -109,6 +109,10 @@ export class PrometheusLens extends PrometheusProvider { return `sum(kube_pod_container_resource_limits{pod=~"${opts.pods}",resource="memory",namespace="${opts.namespace}"}) by (${opts.selector})`; case "fsUsage": return `sum(container_fs_usage_bytes{container!="POD",container!="",pod=~"${opts.pods}",namespace="${opts.namespace}"}) by (${opts.selector})`; + case "fsWrites": + return `sum(rate(container_fs_writes_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; + case "fsReads": + return `sum(rate(container_fs_reads_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkReceive": return `sum(rate(container_network_receive_bytes_total{pod=~"${opts.pods}",namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkTransmit": diff --git a/src/main/prometheus/operator.ts b/src/main/prometheus/operator.ts index 28e65fd96f7dd..83638e4ec1d7f 100644 --- a/src/main/prometheus/operator.ts +++ b/src/main/prometheus/operator.ts @@ -109,6 +109,10 @@ export class PrometheusOperator extends PrometheusProvider { return `sum(kube_pod_container_resource_limits{pod=~"${opts.pods}", resource="memory", namespace="${opts.namespace}"}) by (${opts.selector})`; case "fsUsage": return `sum(container_fs_usage_bytes{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}) by (${opts.selector})`; + case "fsWrites": + return `sum(rate(container_fs_writes_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; + case "fsReads": + return `sum(rate(container_fs_reads_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkReceive": return `sum(rate(container_network_receive_bytes_total{pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkTransmit": diff --git a/src/main/prometheus/stacklight.ts b/src/main/prometheus/stacklight.ts index a64c7bcd2eb3a..6e98a5328de96 100644 --- a/src/main/prometheus/stacklight.ts +++ b/src/main/prometheus/stacklight.ts @@ -109,6 +109,10 @@ export class PrometheusStacklight extends PrometheusProvider { return `sum(kube_pod_container_resource_limits{pod=~"${opts.pods}",resource="memory",namespace="${opts.namespace}"}) by (${opts.selector})`; case "fsUsage": return `sum(container_fs_usage_bytes{container!="POD",container!="",pod=~"${opts.pods}",namespace="${opts.namespace}"}) by (${opts.selector})`; + case "fsWrites": + return `sum(rate(container_fs_writes_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; + case "fsReads": + return `sum(rate(container_fs_reads_bytes_total{container!="", pod=~"${opts.pods}", namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkReceive": return `sum(rate(container_network_receive_bytes_total{pod=~"${opts.pods}",namespace="${opts.namespace}"}[${this.rateAccuracy}])) by (${opts.selector})`; case "networkTransmit": diff --git a/src/renderer/components/+workloads-pods/container-charts.tsx b/src/renderer/components/+workloads-pods/container-charts.tsx index 3e5d0dd583c92..68da9bd99a4ee 100644 --- a/src/renderer/components/+workloads-pods/container-charts.tsx +++ b/src/renderer/components/+workloads-pods/container-charts.tsx @@ -46,6 +46,8 @@ export const ContainerCharts = observer(() => { memoryRequests, memoryLimits, fsUsage, + fsWrites, + fsReads } = mapValues(metrics, metric => normalizeMetrics(metric).data.result[0].values); const datasets = [ @@ -106,6 +108,20 @@ export const ContainerCharts = observer(() => { borderColor: "#ffc63d", data: fsUsage.map(([x, y]) => ({ x, y })), }, + { + id: "fsWrites", + label: `Writes`, + tooltip: `Bytes written on this filesystem`, + borderColor: "#ff963d", + data: fsWrites.map(([x, y]) => ({ x, y })), + }, + { + id: "fsReads", + label: `Reads`, + tooltip: `Bytes read on this filesystem`, + borderColor: "#fff73d", + data: fsReads.map(([x, y]) => ({ x, y })), + }, ], ]; diff --git a/src/renderer/components/+workloads-pods/pod-charts.tsx b/src/renderer/components/+workloads-pods/pod-charts.tsx index a41219cc2e5ff..db88e56dd0f61 100644 --- a/src/renderer/components/+workloads-pods/pod-charts.tsx +++ b/src/renderer/components/+workloads-pods/pod-charts.tsx @@ -51,6 +51,8 @@ export const PodCharts = observer(() => { cpuUsage, memoryUsage, fsUsage, + fsWrites, + fsReads, networkReceive, networkTransmit, } = mapValues(metrics, metric => normalizeMetrics(metric).data.result[0].values); @@ -102,6 +104,20 @@ export const PodCharts = observer(() => { borderColor: "#ffc63d", data: fsUsage.map(([x, y]) => ({ x, y })), }, + { + id: `${id}-fsWrites`, + label: `Writes`, + tooltip: `Bytes written on this filesystem`, + borderColor: "#ff963d", + data: fsWrites.map(([x, y]) => ({ x, y })), + }, + { + id: `${id}-fsReads`, + label: `Reads`, + tooltip: `Bytes read on this filesystem`, + borderColor: "#fff73d", + data: fsReads.map(([x, y]) => ({ x, y })), + }, ], ];