Skip to content

Commit

Permalink
[6.x] [Infra UI] Normalizing CPU usage for waffle map (#25123) (#25210)
Browse files Browse the repository at this point in the history
Backports the following commits to 6.x:
 - [Infra UI] Normalizing CPU usage for waffle map  (#25123)
  • Loading branch information
weltenwort authored Nov 6, 2018
1 parent 2268c59 commit 0879295
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ export type InfraAgg =
| InfraDerivativeAgg
| InfraAvgAgg
| InfraMaxAgg
| InfraCumulativeSumAgg;
| InfraCumulativeSumAgg
| undefined;
export interface InfraNodeMetricAgg {
[key: string]: InfraAgg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,50 @@ import { InfraNodeMetricFn, InfraNodeType } from '../adapter_types';
const FIELDS = {
[InfraNodeType.host]: 'system.cpu.user.pct',
[InfraNodeType.pod]: 'kubernetes.pod.cpu.usage.node.pct',
[InfraNodeType.container]: 'docker.cpu.user.pct',
[InfraNodeType.container]: 'docker.cpu.total.pct',
};

export const cpu: InfraNodeMetricFn = (nodeType: InfraNodeType) => {
if (nodeType === InfraNodeType.host) {
return {
cpu_user: {
avg: {
field: 'system.cpu.user.pct',
},
},
cpu_system: {
avg: {
field: 'system.cpu.system.pct',
},
},
cpu_cores: {
max: {
field: 'system.cpu.cores',
},
},
cpu: {
bucket_script: {
buckets_path: {
user: 'cpu_user',
system: 'cpu_system',
cores: 'cpu_cores',
},
script: {
source: '(params.user + params.system) / params.cores',
lang: 'painless',
},
gap_policy: 'skip',
},
},
};
}

const field = FIELDS[nodeType];
return { cpu: { avg: { field } } };
return {
cpu: {
avg: {
field,
},
},
};
};
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/infra/waffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const waffleTests: KbnTestProvider = ({ getService }) => {
expect(firstNode).to.have.property('metric');
expect(firstNode.metric).to.eql({
name: 'cpu',
value: 0.005833333333333334,
value: 0.011,
__typename: 'InfraNodeMetric',
});
}
Expand Down

0 comments on commit 0879295

Please sign in to comment.