Skip to content

Commit

Permalink
add missing deps, load disk usage of dl dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Oct 11, 2017
1 parent ce44494 commit 1fd4201
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
4 changes: 4 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func New() *Engine {
return &Engine{ts: map[string]*Torrent{}}
}

func (e *Engine) Config() Config {
return e.config
}

func (e *Engine) Configure(c Config) error {
//recieve config
if e.client != nil {
Expand Down
11 changes: 8 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type Server struct {
}
}

// Run the server
func (s *Server) Run(version string) error {

isTLS := s.CertPath != "" || s.KeyPath != "" //poor man's XOR
if isTLS && (s.CertPath == "" || s.KeyPath == "") {
return fmt.Errorf("You must provide both key and cert paths")
Expand Down Expand Up @@ -125,9 +125,14 @@ func (s *Server) Run(version string) error {
time.Sleep(1 * time.Second)
}
}()

//start collecting stats
go s.state.Stats.System.loadStatsEvery(5 * time.Second)
go func() {
for {
c := s.engine.Config()
s.state.Stats.System.loadStats(c.DownloadDirectory)
time.Sleep(5 * time.Second)
}
}()

host := s.Host
if host == "" {
Expand Down
12 changes: 2 additions & 10 deletions server/server_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"runtime"
"time"

velox "github.com/jpillora/velox/go"
"github.com/shirou/gopsutil/cpu"
Expand All @@ -24,14 +23,7 @@ type stats struct {
pusher velox.Pusher
}

func (s *stats) loadStatsEvery(interval time.Duration) {
for {
s.loadStats()
time.Sleep(interval)
}
}

func (s *stats) loadStats() {
func (s *stats) loadStats(diskDir string) {
//count cpu cycles between last count
if stats, err := cpu.CPUTimes(false); err == nil {
stat := stats[0]
Expand All @@ -51,7 +43,7 @@ func (s *stats) loadStats() {
s.lastCPUStat = &stat
}
//count disk usage
if stat, err := disk.DiskUsage("/"); err == nil {
if stat, err := disk.DiskUsage(diskDir); err == nil {
s.DiskUsed = int64(stat.Used)
s.DiskTotal = int64(stat.Total)
}
Expand Down
14 changes: 9 additions & 5 deletions vendor/github.com/anacrolix/utp/conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 22 additions & 14 deletions vendor/github.com/anacrolix/utp/socket.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vendor/github.com/anacrolix/utp/utp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fd4201

Please sign in to comment.