forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metrics UI] Add Process tab to Enhanced Node Details (elastic#83477)
- Loading branch information
Showing
20 changed files
with
1,163 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './process_list'; |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/infra/common/http_api/host_details/process_list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { MetricsAPITimerangeRT, MetricsAPISeriesRT } from '../metrics_api'; | ||
|
||
export const ProcessListAPIRequestRT = rt.type({ | ||
hostTerm: rt.record(rt.string, rt.string), | ||
timerange: MetricsAPITimerangeRT, | ||
indexPattern: rt.string, | ||
}); | ||
|
||
export const ProcessListAPIResponseRT = rt.array(MetricsAPISeriesRT); | ||
|
||
export type ProcessListAPIRequest = rt.TypeOf<typeof ProcessListAPIRequestRT>; | ||
|
||
export type ProcessListAPIResponse = rt.TypeOf<typeof ProcessListAPIResponseRT>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...gins/infra/public/pages/metrics/inventory_view/components/node_details/tabs/processes.tsx
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
...nfra/public/pages/metrics/inventory_view/components/node_details/tabs/processes/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useMemo, useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiSearchBar, EuiSpacer, EuiEmptyPrompt, EuiButton, Query } from '@elastic/eui'; | ||
import { useProcessList } from '../../../../hooks/use_process_list'; | ||
import { TabContent, TabProps } from '../shared'; | ||
import { STATE_NAMES } from './states'; | ||
import { SummaryTable } from './summary_table'; | ||
import { ProcessesTable } from './processes_table'; | ||
|
||
const TabComponent = ({ currentTime, node, nodeType, options }: TabProps) => { | ||
const [searchFilter, setSearchFilter] = useState<Query>(EuiSearchBar.Query.MATCH_ALL); | ||
|
||
const hostTerm = useMemo(() => { | ||
const field = | ||
options.fields && Reflect.has(options.fields, nodeType) | ||
? Reflect.get(options.fields, nodeType) | ||
: nodeType; | ||
return { [field]: node.name }; | ||
}, [options, node, nodeType]); | ||
|
||
const { loading, error, response, makeRequest: reload } = useProcessList( | ||
hostTerm, | ||
'metricbeat-*', | ||
options.fields!.timestamp, | ||
currentTime | ||
); | ||
|
||
if (error) { | ||
return ( | ||
<TabContent> | ||
<EuiEmptyPrompt | ||
iconType="tableDensityNormal" | ||
title={ | ||
<h4> | ||
{i18n.translate('xpack.infra.metrics.nodeDetails.processListError', { | ||
defaultMessage: 'Unable to show process data', | ||
})} | ||
</h4> | ||
} | ||
actions={ | ||
<EuiButton color="primary" fill onClick={reload}> | ||
{i18n.translate('xpack.infra.metrics.nodeDetails.processListRetry', { | ||
defaultMessage: 'Try again', | ||
})} | ||
</EuiButton> | ||
} | ||
/> | ||
</TabContent> | ||
); | ||
} | ||
|
||
return ( | ||
<TabContent> | ||
<SummaryTable isLoading={loading} processList={response ?? []} /> | ||
<EuiSpacer size="m" /> | ||
<EuiSearchBar | ||
query={searchFilter} | ||
onChange={({ query }) => setSearchFilter(query ?? EuiSearchBar.Query.MATCH_ALL)} | ||
box={{ | ||
incremental: true, | ||
placeholder: i18n.translate('xpack.infra.metrics.nodeDetails.searchForProcesses', { | ||
defaultMessage: 'Search for processes…', | ||
}), | ||
}} | ||
filters={[ | ||
{ | ||
type: 'field_value_selection', | ||
field: 'state', | ||
name: 'State', | ||
operator: 'exact', | ||
multiSelect: false, | ||
options: Object.entries(STATE_NAMES).map(([value, view]: [string, string]) => ({ | ||
value, | ||
view, | ||
})), | ||
}, | ||
]} | ||
/> | ||
<EuiSpacer size="m" /> | ||
<ProcessesTable | ||
currentTime={currentTime} | ||
isLoading={loading || !response} | ||
processList={response ?? []} | ||
searchFilter={searchFilter} | ||
/> | ||
</TabContent> | ||
); | ||
}; | ||
|
||
export const ProcessesTab = { | ||
id: 'processes', | ||
name: i18n.translate('xpack.infra.metrics.nodeDetails.tabs.processes', { | ||
defaultMessage: 'Processes', | ||
}), | ||
content: TabComponent, | ||
}; |
55 changes: 55 additions & 0 deletions
55
...pages/metrics/inventory_view/components/node_details/tabs/processes/parse_process_list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ProcessListAPIResponse } from '../../../../../../../../common/http_api'; | ||
import { Process } from './types'; | ||
|
||
export const parseProcessList = (processList: ProcessListAPIResponse) => | ||
processList.map((process) => { | ||
const command = process.id; | ||
let mostRecentPoint; | ||
for (let i = process.rows.length - 1; i >= 0; i--) { | ||
const point = process.rows[i]; | ||
if (point && Array.isArray(point.meta) && point.meta?.length) { | ||
mostRecentPoint = point; | ||
break; | ||
} | ||
} | ||
if (!mostRecentPoint) return { command, cpu: null, memory: null, startTime: null, state: null }; | ||
|
||
const { cpu, memory } = mostRecentPoint; | ||
const { system, process: processMeta, user } = (mostRecentPoint.meta as any[])[0]; | ||
const startTime = system.process.cpu.start_time; | ||
const state = system.process.state; | ||
|
||
const timeseries = { | ||
cpu: pickTimeseries(process.rows, 'cpu'), | ||
memory: pickTimeseries(process.rows, 'memory'), | ||
}; | ||
|
||
return { | ||
command, | ||
cpu, | ||
memory, | ||
startTime, | ||
state, | ||
pid: processMeta.pid, | ||
user: user.name, | ||
timeseries, | ||
} as Process; | ||
}); | ||
|
||
const pickTimeseries = (rows: any[], metricID: string) => ({ | ||
rows: rows.map((row) => ({ | ||
timestamp: row.timestamp, | ||
metric_0: row[metricID], | ||
})), | ||
columns: [ | ||
{ name: 'timestamp', type: 'date' }, | ||
{ name: 'metric_0', type: 'number' }, | ||
], | ||
id: metricID, | ||
}); |
Oops, something went wrong.