]> Sergey Matveev's repositories - btrtrc.git/blob - cmd/btrtrc/status.go
Speed is in KiBs everywhere
[btrtrc.git] / cmd / btrtrc / status.go
1 package main
2
3 import (
4         "log"
5         "time"
6
7         "github.com/anacrolix/torrent"
8         "github.com/dustin/go-humanize"
9 )
10
11 func overallStatus(c *torrent.Client) {
12         var prev torrent.ConnStats
13         for range time.Tick(time.Second) {
14                 stats := c.ConnStats()
15                 var peers int
16                 for _, t := range c.Torrents() {
17                         if t.Info() == nil {
18                                 continue
19                         }
20                         tStats := t.Stats()
21                         TorrentStatsM.Lock()
22                         TorrentStats[t.InfoHash()] = tStats
23                         TorrentStatsM.Unlock()
24                         peers += tStats.ActivePeers
25                 }
26                 log.Printf(
27                         "%s / %s | %d | %s%d%s / %s%d%s",
28                         humanize.IBytes(uint64(stats.BytesRead.Int64())),
29                         humanize.IBytes(uint64(stats.BytesWritten.Int64())),
30                         peers,
31                         Green, (stats.BytesRead.Int64()-prev.BytesRead.Int64())/1024, Reset,
32                         Magenta, (stats.BytesWritten.Int64()-prev.BytesWritten.Int64())/1024, Reset,
33                 )
34                 prev = stats
35         }
36 }