-
Notifications
You must be signed in to change notification settings - Fork 42
/
stat.go
79 lines (71 loc) · 2.18 KB
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/tomcraven/gotable"
"os"
"seeder/src/config"
"seeder/src/qbittorrent"
"seeder/src/qbittorrent/pkg/model"
"time"
)
func main() {
var servers []qbittorrent.Server
if cfg, err := config.GetConfig(); err == nil {
for _, value := range cfg.Server {
if value.Enable == true {
server := qbittorrent.NewClientWrapper(value.Endpoint, value.Username, value.Password, value.Remark, value.Rule)
servers = append(servers, server)
}
}
} else {
os.Exit(1)
}
for true {
t := gotable.NewTable([]gotable.Column{
gotable.NewColumn("Name", 20),
gotable.NewColumn("FreeDisk(GB)", 20),
gotable.NewColumn("DiskLatency(ms)", 20),
gotable.NewColumn("CurrentSpeed(MB/s)", 20),
gotable.NewColumn("TaskList(Count)", 20),
gotable.NewColumn("Transfer(TB)", 20),
gotable.NewColumn("Ratio(%)", 20),
})
for _, server := range servers {
if r, err := server.Client.GetMainData(); err == nil {
ConcurrentDownload := 0
ConcurrentUpload := 0
TaskCount := 0
var options model.GetTorrentListOptions
options.Filter = "all"
if ts, err := server.Client.GetList(); err == nil {
for _, t := range ts {
if t.AmountLeft != 0 {
ConcurrentDownload++
}
if t.Upspeed > 0 {
ConcurrentUpload++
}
TaskCount++
server.Status.EstimatedQuota -= t.AmountLeft
}
} else {
//如果无法获取状态,直接让并行任务数显示最大以跳过规则.
server.Status.ConcurrentDownload = 65535
}
t.Push(
server.Remark,
fmt.Sprintf("%.2f", float64(r.ServerState.FreeSpaceOnDisk)/1073741820),
fmt.Sprintf("%d", r.ServerState.AverageTimeQueue),
fmt.Sprintf("%.2f(U)|%.2f(D)", float64(r.ServerState.UpInfoSpeed)/1048576.0, float64(r.ServerState.DlInfoSpeed)/1048576.0),
fmt.Sprintf("%d(U)|%d(D)|%d(A)", ConcurrentUpload, ConcurrentDownload, TaskCount),
fmt.Sprintf("%.2f(U)|%.2f(D)", float64(r.ServerState.AlltimeUl)/1099511623680, float64(r.ServerState.AlltimeDl)/1099511623680),
fmt.Sprintf("%.2f", float64(r.ServerState.GlobalRatio)),
)
}
}
fmt.Printf("\x1bc")
fmt.Println("QB服务器最新状态:")
t.Print()
time.Sleep(5)
}
}