Skip to content

Commit 84ad28d

Browse files
committed
feat: show tcp stat
1 parent 86ae3ac commit 84ad28d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/pages/Traffic/components/TrafficDataRow.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from '@emotion/styled/macro'
44
import css from '@emotion/css/macro'
55
import bytes from 'bytes'
66
import tw from 'twin.macro'
7-
import React, { useState } from 'react'
7+
import React, { useMemo, useState } from 'react'
88
import { ChevronRight } from '@sumup/icons'
99
import { Collapse } from 'react-collapse'
1010

@@ -18,6 +18,17 @@ interface TrafficDataRowProps {
1818

1919
const TrafficDataRow: React.FC<TrafficDataRowProps> = ({ name, data }) => {
2020
const [isDetailsOpen, setIsDetailsOpen] = useState<boolean>(false)
21+
const tcpStat = useMemo(() => {
22+
if (!data.statistics || !data.statistics.length) return
23+
24+
let total = 0
25+
26+
data.statistics.forEach((stat) => {
27+
total += stat.srtt
28+
})
29+
30+
return Math.round(total / data.statistics.length)
31+
}, [data.statistics])
2132

2233
return (
2334
<DataRow
@@ -62,6 +73,12 @@ const TrafficDataRow: React.FC<TrafficDataRowProps> = ({ name, data }) => {
6273
上传: {bytes(data.outMaxSpeed)}/s 下载: {bytes(data.inMaxSpeed)}/s
6374
</div>
6475
</DataRowSub>
76+
{!!tcpStat && (
77+
<DataRowSub>
78+
<div>TCP 统计</div>
79+
<div>Avg. RTT {tcpStat}ms</div>
80+
</DataRowSub>
81+
)}
6582
</div>
6683
</Collapse>
6784
</DataRow>

0 commit comments

Comments
 (0)