Skip to content

Commit 836c5e3

Browse files
[Metrics UI] Use CPU Usage limits for Kubernetes pods when available (#58424) (#58906)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 65fb3a8 commit 836c5e3

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@
77
import { SnapshotModel } from '../../../types';
88

99
export const cpu: SnapshotModel = {
10-
cpu: {
10+
cpu_with_limit: {
11+
avg: {
12+
field: 'kubernetes.pod.cpu.usage.limit.pct',
13+
},
14+
},
15+
cpu_without_limit: {
1116
avg: {
1217
field: 'kubernetes.pod.cpu.usage.node.pct',
1318
},
1419
},
20+
cpu: {
21+
bucket_script: {
22+
buckets_path: {
23+
with_limit: 'cpu_with_limit',
24+
without_limit: 'cpu_without_limit',
25+
},
26+
script: {
27+
source: 'params.with_limit > 0.0 ? params.with_limit : params.without_limit',
28+
lang: 'painless',
29+
},
30+
gap_policy: 'skip',
31+
},
32+
},
1533
};

x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ export const podCpuUsage: TSVBMetricModelCreator = (
2424
metrics: [
2525
{
2626
field: 'kubernetes.pod.cpu.usage.node.pct',
27-
id: 'avg-cpu-usage',
27+
id: 'avg-cpu-without',
2828
type: 'avg',
2929
},
30+
{
31+
field: 'kubernetes.pod.cpu.usage.limit.pct',
32+
id: 'avg-cpu-with',
33+
type: 'avg',
34+
},
35+
{
36+
id: 'cpu-usage',
37+
type: 'calculation',
38+
variables: [
39+
{ id: 'cpu_with', name: 'with_limit', field: 'avg-cpu-with' },
40+
{ id: 'cpu_without', name: 'without_limit', field: 'avg-cpu-without' },
41+
],
42+
script: 'params.with_limit > 0.0 ? params.with_limit : params.without_limit',
43+
},
3044
],
3145
},
3246
],

0 commit comments

Comments
 (0)