mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-21 20:12:33 +03:00
In status page the rx and tx bytes now are shown with units
This commit is contained in:
parent
2e33f9ec52
commit
e97d6b95c1
2 changed files with 30 additions and 2 deletions
|
@ -469,6 +469,8 @@ func Status(db store.IStore) echo.HandlerFunc {
|
||||||
PublicKey string
|
PublicKey string
|
||||||
ReceivedBytes int64
|
ReceivedBytes int64
|
||||||
TransmitBytes int64
|
TransmitBytes int64
|
||||||
|
Received string
|
||||||
|
Transmit string
|
||||||
LastHandshakeTime time.Time
|
LastHandshakeTime time.Time
|
||||||
LastHandshakeRel time.Duration
|
LastHandshakeRel time.Duration
|
||||||
Connected bool
|
Connected bool
|
||||||
|
@ -528,6 +530,32 @@ func Status(db store.IStore) echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
pVm.Connected = pVm.LastHandshakeRel.Minutes() < 3.
|
pVm.Connected = pVm.LastHandshakeRel.Minutes() < 3.
|
||||||
|
|
||||||
|
units := []string{" ", " K", " M", " G", " T", " P", " E", " Z", " Y"}
|
||||||
|
|
||||||
|
pow := 0
|
||||||
|
temporal := float64(pVm.ReceivedBytes)
|
||||||
|
for ; temporal > 1024; temporal /= 1024 {
|
||||||
|
pow += 1
|
||||||
|
if pow == len(units)-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pVm.Received = fmt.Sprintf("%.3f", temporal)
|
||||||
|
pVm.Received = strings.TrimSuffix(strings.TrimRight(pVm.Received, "0"), ".")
|
||||||
|
pVm.Received = fmt.Sprintf("%s %sBytes", pVm.Received, units[pow])
|
||||||
|
|
||||||
|
pow = 0
|
||||||
|
temporal = float64(pVm.TransmitBytes)
|
||||||
|
for ; temporal > 1024; temporal /= 1024 {
|
||||||
|
pow += 1
|
||||||
|
if pow == len(units)-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pVm.Transmit = fmt.Sprintf("%.3f", temporal)
|
||||||
|
pVm.Transmit = strings.TrimSuffix(strings.TrimRight(pVm.Transmit, "0"), ".")
|
||||||
|
pVm.Transmit = fmt.Sprintf("%s %sBytes", pVm.Transmit, units[pow])
|
||||||
|
|
||||||
if _client, ok := m[pVm.PublicKey]; ok {
|
if _client, ok := m[pVm.PublicKey]; ok {
|
||||||
pVm.Name = _client.Name
|
pVm.Name = _client.Name
|
||||||
pVm.Email = _client.Email
|
pVm.Email = _client.Email
|
||||||
|
|
|
@ -41,8 +41,8 @@ Connected Peers
|
||||||
<td>{{ $peer.Name }}</td>
|
<td>{{ $peer.Name }}</td>
|
||||||
<td>{{ $peer.Email }}</td>
|
<td>{{ $peer.Email }}</td>
|
||||||
<td>{{ $peer.PublicKey }}</td>
|
<td>{{ $peer.PublicKey }}</td>
|
||||||
<td>{{ $peer.ReceivedBytes }}</td>
|
<td title="{{ $peer.ReceivedBytes }} Bytes">{{ $peer.Received }}</td>
|
||||||
<td>{{ $peer.TransmitBytes }}</td>
|
<td title="{{ $peer.TransmitBytes }} Bytes">{{ $peer.Transmit }}</td>
|
||||||
<td>{{ $peer.Connected }}</td>
|
<td>{{ $peer.Connected }}</td>
|
||||||
<td>{{ $peer.LastHandshakeTime }}</td>
|
<td>{{ $peer.LastHandshakeTime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Add table
Reference in a new issue