-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstats.go
45 lines (38 loc) · 834 Bytes
/
stats.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
package main
import (
"fmt"
humanize "github.com/pyed/go-humanize"
)
// stats echo back transmission stats
func stats() {
stats, err := rtorrent.Stats()
if err != nil {
logger.Print("stats:", err)
send("stats: "+err.Error(), false)
return
}
// show 'off' instead of 0 for throttling
var throttleUp, throttleDown string
if stats.ThrottleUp == 0 {
throttleUp = "off"
} else {
throttleUp = humanize.IBytes(stats.ThrottleUp)
}
if stats.ThrottleDown == 0 {
throttleDown = "off"
} else {
throttleDown = humanize.IBytes(stats.ThrottleDown)
}
msg := fmt.Sprintf(
`
\[Throttle *%s* / *%s*]
\[Port *%s*]
\[*%s*]
Total Uploaded: *%s*
Total Download: *%s*
`,
throttleUp, throttleDown, stats.Port, stats.Directory,
humanize.IBytes(stats.TotalUp), humanize.IBytes(stats.TotalDown),
)
send(msg, true)
}