Skip to content

Commit 9e06b32

Browse files
committed
feat: add TCP/UDP connection count display in network card
1 parent 1c936e3 commit 9e06b32

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

handlers/network.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ import (
1212
)
1313

1414
func getNetworkInfo() models.NetworkInfo {
15+
tcp := getTCPConnections()
16+
udp := getUDPConnections()
17+
1518
return models.NetworkInfo{
1619
Interfaces: getInterfaces(),
17-
TCP: getTCPConnections(),
18-
UDP: getUDPConnections(),
20+
TCP: tcp,
21+
UDP: udp,
22+
TCPCount: len(tcp),
23+
UDPCount: len(udp),
1924
}
2025
}
2126

@@ -106,10 +111,6 @@ func getConnections(path string) []models.Connection {
106111
Status: status,
107112
PID: pid,
108113
})
109-
110-
if len(connections) >= 50 {
111-
break
112-
}
113114
}
114115

115116
return connections

models/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type NetworkInfo struct {
5555
Interfaces []InterfaceInfo `json:"interfaces"`
5656
TCP []Connection `json:"tcp"`
5757
UDP []Connection `json:"udp"`
58+
TCPCount int `json:"tcp_count"`
59+
UDPCount int `json:"udp_count"`
5860
}
5961

6062
type InterfaceInfo struct {

static/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ <h2>Speed Test</h2>
125125
</div>
126126
</div>
127127

128+
<div class="card">
129+
<h2>Network</h2>
130+
<div class="metric">
131+
<span class="value" id="tcp-count">0</span>
132+
<span class="label">TCP Connections</span>
133+
</div>
134+
<div class="metric">
135+
<span class="value" id="udp-count">0</span>
136+
<span class="label">UDP Connections</span>
137+
</div>
138+
</div>
139+
128140
<div class="card large">
129141
<h2>Top Processes</h2>
130142
<div class="table-container">

static/script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class Dashboard {
6464
this.updateInterfaces(network.interfaces);
6565
this.updateConnections(network.tcp, 'tcp-table');
6666
this.updateConnections(network.udp, 'udp-table');
67+
68+
document.getElementById('tcp-count').textContent = network.tcp_count || 0;
69+
document.getElementById('udp-count').textContent = network.udp_count || 0;
6770
}
6871

6972
updateInterfaces(interfaces) {

0 commit comments

Comments
 (0)