--- /dev/null
+package main
+
+import (
+ "log"
+ "time"
+
+ "github.com/anacrolix/torrent"
+ "github.com/dustin/go-humanize"
+)
+
+func overallStatus(c *torrent.Client) {
+ tick := time.Tick(time.Second)
+ var prev torrent.ConnStats
+ for {
+ select {
+ case <-Cancel:
+ Jobs.Done()
+ return
+ case <-tick:
+ }
+ stats := c.ConnStats()
+ var peers int
+ for _, t := range c.Torrents() {
+ if t.Info() == nil {
+ continue
+ }
+ tStats := t.Stats()
+ cur := tStats.Copy()
+ TorrentStatsM.Lock()
+ prev := TorrentStats[t.InfoHash()].stats
+ TorrentStats[t.InfoHash()] = TorrentStat{
+ stats: cur,
+ rxSpeed: cur.BytesReadData.Int64() - prev.BytesReadData.Int64(),
+ txSpeed: cur.BytesWrittenData.Int64() - prev.BytesWrittenData.Int64(),
+ }
+ TorrentStatsM.Unlock()
+ peers += tStats.ActivePeers
+ }
+ log.Printf(
+ "%s / %s | %d | %s%d%s / %s%d%s",
+ humanize.IBytes(uint64(stats.BytesRead.Int64())),
+ humanize.IBytes(uint64(stats.BytesWritten.Int64())),
+ peers,
+ Green, (stats.BytesRead.Int64()-prev.BytesRead.Int64())/1024, Reset,
+ Magenta, (stats.BytesWritten.Int64()-prev.BytesWritten.Int64())/1024, Reset,
+ )
+ prev = stats
+ }
+}