Add peers and seeders on routes page.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-05-21 18:44:57 +02:00
parent ecd524ed3c
commit 9f6d1d713a
3 changed files with 14 additions and 1 deletions

View file

@ -20,8 +20,12 @@ function fetchData() {
var download = torrentStat.downloadedBytes / torrentStat.timePassed;
var upload = torrentStat.uploadedBytes / torrentStat.timePassed;
var seeders = torrentStat.seeders
var peers = torrentStat.peers
document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText =
Humanize.bytes(download, 1024) + "/s down, " + Humanize.bytes(upload, 1024) + "/s up";
document.getElementById("peers-seeders-" + torrentStat.hash).innerText =
peers + " peers, " + seeders + " seeders."
});
});

View file

@ -30,6 +30,8 @@ type TorrentStats struct {
Hash string `json:"hash"`
DownloadedBytes int64 `json:"downloadedBytes"`
UploadedBytes int64 `json:"uploadedBytes"`
Peers int `json:"peers"`
Seeders int `json:"seeders"`
TimePassed float64 `json:"timePassed"`
PieceChunks []*PieceChunk `json:"pieceChunks"`
TotalPieces int `json:"totalPieces"`
@ -51,6 +53,8 @@ type stats struct {
downloadBytes int64
totalUploadBytes int64
uploadBytes int64
peers int
seeders int
time time.Time
}
@ -141,7 +145,6 @@ func (s *Torrent) stats(now time.Time, t *torrent.Torrent, chunks bool) *Torrent
log.Println("Using previous stats")
} else {
st := t.Stats()
rd := st.BytesReadData.Int64()
wd := st.BytesWrittenData.Int64()
ist := &stats{
@ -150,10 +153,14 @@ func (s *Torrent) stats(now time.Time, t *torrent.Torrent, chunks bool) *Torrent
totalDownloadBytes: rd,
totalUploadBytes: wd,
time: now,
peers: st.TotalPeers,
seeders: st.ConnectedSeeders,
}
ts.DownloadedBytes = ist.downloadBytes
ts.UploadedBytes = ist.uploadBytes
ts.Peers = ist.peers
ts.Seeders = ist.seeders
s.previousStats[t.InfoHash().String()] = ist
}

View file

@ -28,6 +28,8 @@
</div>
<div class="col">
<p id="up-down-speed-text-{{.Hash}}">...</p>
<p id="peers-seeders-{{.Hash}}">...</p>
</div>
<div class="col">
<div id="file-chunks-{{.Hash}}" class="progress">