Skip to content

Commit 1fd4201

Browse files
committed
add missing deps, load disk usage of dl dir
1 parent ce44494 commit 1fd4201

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

engine/engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func New() *Engine {
2727
return &Engine{ts: map[string]*Torrent{}}
2828
}
2929

30+
func (e *Engine) Config() Config {
31+
return e.config
32+
}
33+
3034
func (e *Engine) Configure(c Config) error {
3135
//recieve config
3236
if e.client != nil {

server/server.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ type Server struct {
6161
}
6262
}
6363

64+
// Run the server
6465
func (s *Server) Run(version string) error {
65-
6666
isTLS := s.CertPath != "" || s.KeyPath != "" //poor man's XOR
6767
if isTLS && (s.CertPath == "" || s.KeyPath == "") {
6868
return fmt.Errorf("You must provide both key and cert paths")
@@ -125,9 +125,14 @@ func (s *Server) Run(version string) error {
125125
time.Sleep(1 * time.Second)
126126
}
127127
}()
128-
129128
//start collecting stats
130-
go s.state.Stats.System.loadStatsEvery(5 * time.Second)
129+
go func() {
130+
for {
131+
c := s.engine.Config()
132+
s.state.Stats.System.loadStats(c.DownloadDirectory)
133+
time.Sleep(5 * time.Second)
134+
}
135+
}()
131136

132137
host := s.Host
133138
if host == "" {

server/server_stats.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"runtime"
5-
"time"
65

76
velox "github.com/jpillora/velox/go"
87
"github.com/shirou/gopsutil/cpu"
@@ -24,14 +23,7 @@ type stats struct {
2423
pusher velox.Pusher
2524
}
2625

27-
func (s *stats) loadStatsEvery(interval time.Duration) {
28-
for {
29-
s.loadStats()
30-
time.Sleep(interval)
31-
}
32-
}
33-
34-
func (s *stats) loadStats() {
26+
func (s *stats) loadStats(diskDir string) {
3527
//count cpu cycles between last count
3628
if stats, err := cpu.CPUTimes(false); err == nil {
3729
stat := stats[0]
@@ -51,7 +43,7 @@ func (s *stats) loadStats() {
5143
s.lastCPUStat = &stat
5244
}
5345
//count disk usage
54-
if stat, err := disk.DiskUsage("/"); err == nil {
46+
if stat, err := disk.DiskUsage(diskDir); err == nil {
5547
s.DiskUsed = int64(stat.Used)
5648
s.DiskTotal = int64(stat.Total)
5749
}

vendor/github.com/anacrolix/utp/conn.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/utp/socket.go

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/utp/utp.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)