Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
fix #69 , /api/stats updates
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Mar 31, 2020
1 parent 4efbd6b commit 01a32ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/server_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (s *Server) apiGET(w http.ResponseWriter, r *http.Request) error {
}
case "stat":
s.state.Lock()
c := s.engine.Config()
s.state.Stats.System.loadStats(c.DownloadDirectory)
json.NewEncoder(w).Encode(s.state.Stats)
s.state.Unlock()
case "enginedebug":
Expand Down
1 change: 1 addition & 0 deletions server/server_bg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (s *Server) backgroundRoutines() {
if s.state.NumConnections() > 0 {
c := s.engine.Config()
s.state.Stats.System.loadStats(c.DownloadDirectory)
s.state.Push()
}
time.Sleep(5 * time.Second)
}
Expand Down
5 changes: 4 additions & 1 deletion server/server_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type stats struct {
pusher velox.Pusher
}

func (s *stats) Push() {
s.pusher.Push()
}

func (s *stats) loadStats(diskDir string) {
//count cpu cycles between last count
//count disk usage
Expand All @@ -44,7 +48,6 @@ func (s *stats) loadStats(diskDir string) {
s.GoRoutines = runtime.NumGoroutine()
//done
s.Set = true
s.pusher.Push()
}

func detectDiskStat(dir string) error {
Expand Down

0 comments on commit 01a32ba

Please sign in to comment.