Add Process column to connections (#722)

This commit is contained in:
CHIZI-0618 2022-11-07 16:38:33 +08:00 committed by GitHub
parent e40551246a
commit 840ba663cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View file

@ -21,6 +21,7 @@ export type ConnectionItem = {
sourcePort: string; sourcePort: string;
destinationPort: string; destinationPort: string;
host: string; host: string;
processPath: string;
}; };
upload: number; upload: number;
download: number; download: number;

View file

@ -1,7 +1,7 @@
.tr { .tr {
display: grid; display: grid;
/* grid-template-columns: repeat(11, minmax(max-content, 1fr)); */ /* grid-template-columns: repeat(11, minmax(max-content, 1fr)); */
grid-template-columns: repeat(11, minmax(max-content, auto)); grid-template-columns: repeat(12, minmax(max-content, auto));
} }
.th { .th {

View file

@ -12,6 +12,7 @@ const sortDescFirst = true;
const columns = [ const columns = [
{ accessor: 'id', show: false }, { accessor: 'id', show: false },
{ Header: 'Host', accessor: 'host' }, { Header: 'Host', accessor: 'host' },
{ Header: 'Process', accessor: 'process' },
{ Header: 'DL', accessor: 'download', sortDescFirst }, { Header: 'DL', accessor: 'download', sortDescFirst },
{ Header: 'UL', accessor: 'upload', sortDescFirst }, { Header: 'UL', accessor: 'upload', sortDescFirst },
{ Header: 'DL Speed', accessor: 'downloadSpeedCurr', sortDescFirst }, { Header: 'DL Speed', accessor: 'downloadSpeedCurr', sortDescFirst },
@ -85,7 +86,7 @@ function Table({ data }) {
className={cx( className={cx(
s.td, s.td,
i % 2 === 0 ? s.odd : false, i % 2 === 0 ? s.odd : false,
j >= 1 && j <= 4 ? s.du : false j >= 2 && j <= 5 ? s.du : false
)} )}
> >
{renderCell(cell)} {renderCell(cell)}

View file

@ -31,6 +31,10 @@ function arrayToIdKv<T extends { id: string }>(items: T[]) {
return o; return o;
} }
function basePath (path: string) {
return path.replace(/.*[/\\]/, '')
}
type FormattedConn = { type FormattedConn = {
id: string; id: string;
upload: number; upload: number;
@ -46,6 +50,7 @@ type FormattedConn = {
host: string; host: string;
type: string; type: string;
network: string; network: string;
processPath: string;
downloadSpeedCurr?: number; downloadSpeedCurr?: number;
uploadSpeedCurr?: number; uploadSpeedCurr?: number;
}; };
@ -67,6 +72,7 @@ function filterConns(conns: FormattedConn[], keyword: string) {
conn.rule, conn.rule,
conn.type, conn.type,
conn.network, conn.network,
conn.processPath,
].some((field) => hasSubstring(field, keyword)) ].some((field) => hasSubstring(field, keyword))
); );
} }
@ -77,7 +83,7 @@ function formatConnectionDataItem(
now: number now: number
): FormattedConn { ): FormattedConn {
const { id, metadata, upload, download, start, chains, rule, rulePayload } = i; const { id, metadata, upload, download, start, chains, rule, rulePayload } = i;
const { host, destinationPort, destinationIP, network, type, sourceIP, sourcePort } = metadata; const { host, destinationPort, destinationIP, network, type, sourceIP, sourcePort, processPath } = metadata;
// host could be an empty string if it's direct IP connection // host could be an empty string if it's direct IP connection
let host2 = host; let host2 = host;
if (host2 === '') host2 = destinationIP; if (host2 === '') host2 = destinationIP;
@ -95,6 +101,7 @@ function formatConnectionDataItem(
source: `${sourceIP}:${sourcePort}`, source: `${sourceIP}:${sourcePort}`,
downloadSpeedCurr: download - (prev ? prev.download : 0), downloadSpeedCurr: download - (prev ? prev.download : 0),
uploadSpeedCurr: upload - (prev ? prev.upload : 0), uploadSpeedCurr: upload - (prev ? prev.upload : 0),
process: basePath(processPath),
}; };
return ret; return ret;
} }