mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Improves the accuracy and perf of the up/down/total counts Sets the correct size of 50 for the monitor list. The widget shows 50 entries.
This commit is contained in:
parent
3e224eb445
commit
43da7a298e
1 changed files with 27 additions and 35 deletions
|
@ -158,7 +158,7 @@ export class ElasticsearchMonitorsAdapter implements UMMonitorsAdapter {
|
|||
body: {
|
||||
query,
|
||||
aggs: {
|
||||
hosts: {
|
||||
ids: {
|
||||
composite: {
|
||||
sources: [
|
||||
{
|
||||
|
@ -168,13 +168,6 @@ export class ElasticsearchMonitorsAdapter implements UMMonitorsAdapter {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
port: {
|
||||
terms: {
|
||||
field: 'tcp.port',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
size: 10000,
|
||||
},
|
||||
|
@ -194,36 +187,34 @@ export class ElasticsearchMonitorsAdapter implements UMMonitorsAdapter {
|
|||
},
|
||||
},
|
||||
};
|
||||
// TODO: this doesn't solve the issue of HB being down
|
||||
const res = await this.database.search(request, params);
|
||||
const hostBuckets = get(res, 'aggregations.hosts.buckets', []);
|
||||
const monitorStatuses = hostBuckets.map(bucket => {
|
||||
const latest = get(bucket, 'latest.hits.hits', []);
|
||||
return latest.reduce(
|
||||
(acc, doc) => {
|
||||
const status = get(doc, '_source.monitor.status', null);
|
||||
if (statusFilter && statusFilter !== status) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
let up: number = 0;
|
||||
let down: number = 0;
|
||||
let searchAfter: any = null;
|
||||
|
||||
do {
|
||||
if (searchAfter) {
|
||||
set(params, 'body.aggs.ids.composite.after', searchAfter);
|
||||
}
|
||||
|
||||
const queryResult = await this.database.search(request, params);
|
||||
const idBuckets = get(queryResult, 'aggregations.ids.buckets', []);
|
||||
|
||||
idBuckets.forEach(bucket => {
|
||||
// We only get the latest doc
|
||||
const status = get(bucket, 'latest.hits.hits[0]._source.monitor.status', null);
|
||||
if (!statusFilter || (statusFilter && statusFilter === status)) {
|
||||
if (status === 'up') {
|
||||
acc.up += 1;
|
||||
up++;
|
||||
} else {
|
||||
acc.down += 1;
|
||||
down++;
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{ up: 0, down: 0 }
|
||||
);
|
||||
});
|
||||
const { up, down } = monitorStatuses.reduce(
|
||||
(acc, status) => {
|
||||
acc.up += status.up || 0;
|
||||
acc.down += status.down || 0;
|
||||
return acc;
|
||||
},
|
||||
// @ts-ignore TODO update typings and remove this comment
|
||||
{ up: 0, down: 0 }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
searchAfter = get(queryResult, 'aggregations.ids.after_key');
|
||||
} while (searchAfter);
|
||||
|
||||
return { up, down, total: up + down };
|
||||
}
|
||||
|
||||
|
@ -261,6 +252,7 @@ export class ElasticsearchMonitorsAdapter implements UMMonitorsAdapter {
|
|||
},
|
||||
},
|
||||
],
|
||||
size: 50,
|
||||
},
|
||||
aggs: {
|
||||
latest: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue