forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_inetstats.go
55 lines (45 loc) · 1.62 KB
/
list_inetstats.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
package cmd
import (
"fmt"
"strings"
"github.com/bpicode/fritzctl/assert"
"github.com/bpicode/fritzctl/conv"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/logger"
"github.com/mitchellh/cli"
)
type listInetstatsCommand struct {
}
func (cmd *listInetstatsCommand) Help() string {
return "Get recent internet upstream/downstream statistics from the FRITZ!Box."
}
func (cmd *listInetstatsCommand) Synopsis() string {
return "get recent internet statistics"
}
func (cmd *listInetstatsCommand) Run(args []string) int {
c := clientLogin()
f := fritz.Internal(c)
stats, err := f.InternetStats()
assert.NoError(err, "cannot obtain internet stats:", err)
logger.Success("Obtained recent upstream/downstream time series:\n")
printTrafficData(stats)
return 0
}
// ListInetstats is a factory creating commands for commands listing internet statistics.
func ListInetstats() (cli.Command, error) {
p := listInetstatsCommand{}
return &p, nil
}
func printTrafficData(data *fritz.TrafficMonitoringData) {
kbps := data.KiloBitsPerSecond()
printSlice("Downstream/internet [kb/s]: ", kbps.DownstreamInternet)
printSlice("Downstream/media [kb/s]: ", kbps.DownStreamMedia)
printSlice("Upstream/low priority [kb/s]: ", kbps.UpstreamLowPriority)
printSlice("Upstream/default priority [kb/s]: ", kbps.UpstreamDefaultPriority)
printSlice("Upstream/high priority [kb/s]: ", kbps.UpstreamHighPriority)
printSlice("Upstream/realtime [kb/s]: ", kbps.UpstreamRealtime)
}
func printSlice(pre string, data []float64) {
strs := conv.Float64Slice(data).String('f', 2)
fmt.Println(pre, strings.Join(strs, " "))
}