mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
parent
80fb111ef7
commit
5de4f1c58f
6 changed files with 36 additions and 3 deletions
|
@ -43,7 +43,11 @@ describe('formatters', () => {
|
|||
|
||||
it('should return fallback when denominator is 0 ', () => {
|
||||
expect(asPercent(3725, 0, 'n/a')).toEqual('n/a');
|
||||
expect(asPercent(3725, 0)).toEqual('');
|
||||
});
|
||||
|
||||
it('should return fallback when numerator or denominator is NaN', () => {
|
||||
expect(asPercent(3725, NaN, 'n/a')).toEqual('n/a');
|
||||
expect(asPercent(NaN, 10000, 'n/a')).toEqual('n/a');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -139,7 +139,7 @@ export function asPercent(
|
|||
denominator: number | undefined,
|
||||
fallbackResult = ''
|
||||
) {
|
||||
if (!denominator) {
|
||||
if (!denominator || isNaN(numerator)) {
|
||||
return fallbackResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,18 @@ Array [
|
|||
},
|
||||
},
|
||||
],
|
||||
"must": Array [
|
||||
Object {
|
||||
"exists": Object {
|
||||
"field": "system.memory.total",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"exists": Object {
|
||||
"field": "system.memory.actual.free",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
"size": 0,
|
||||
|
|
|
@ -36,6 +36,20 @@ const percentSystemMemoryUsedScript = {
|
|||
export async function fetch(args: MetricsRequestArgs) {
|
||||
return fetchMetrics<Aggs>({
|
||||
...args,
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
exists: {
|
||||
field: METRIC_SYSTEM_TOTAL_MEMORY
|
||||
}
|
||||
},
|
||||
{
|
||||
exists: {
|
||||
field: METRIC_SYSTEM_FREE_MEMORY
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
timeseriesBucketAggregations: {
|
||||
averagePercentMemoryUsed: { avg: percentSystemMemoryUsedScript },
|
||||
maximumPercentMemoryUsed: { max: percentSystemMemoryUsedScript }
|
||||
|
|
|
@ -12,7 +12,8 @@ export async function fetchMetrics<T = void>({
|
|||
serviceName,
|
||||
setup,
|
||||
timeseriesBucketAggregations = {},
|
||||
totalAggregations = {}
|
||||
totalAggregations = {},
|
||||
bool = {}
|
||||
}: MetricsRequestArgs) {
|
||||
const { start, end, esFilterQuery, client, config } = setup;
|
||||
const { intervalString } = getBucketSize(start, end, 'auto');
|
||||
|
@ -41,6 +42,7 @@ export async function fetchMetrics<T = void>({
|
|||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
...bool,
|
||||
filter: filters
|
||||
}
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ export interface MetricsRequestArgs {
|
|||
setup: Setup;
|
||||
timeseriesBucketAggregations?: StringMap<any>;
|
||||
totalAggregations?: StringMap<any>;
|
||||
bool?: StringMap<any>;
|
||||
}
|
||||
|
||||
export interface AggValue {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue