2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // Show queued NNCP Rx/Tx stats
31 "github.com/dustin/go-humanize"
35 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
36 fmt.Fprintln(os.Stderr, "nncp-stat -- show queued Rx/Tx stats\n")
37 fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0])
43 cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
44 nodeRaw = flag.String("node", "", "Process only that node")
45 debug = flag.Bool("debug", false, "Print debug messages")
46 version = flag.Bool("version", false, "Print version information")
47 warranty = flag.Bool("warranty", false, "Print warranty information")
52 fmt.Println(nncp.Warranty)
56 fmt.Println(nncp.VersionGet())
60 cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
62 log.Fatalln("Can not read config:", err)
64 ctx, err := nncp.CfgParse(cfgRaw)
66 log.Fatalln("Can not parse config:", err)
70 var nodeOnly *nncp.Node
72 nodeOnly, err = ctx.FindNode(*nodeRaw)
74 log.Fatalln("Invalid -node specified:", err)
78 nodeNames := make([]string, 0, len(ctx.Neigh))
79 nodeNameToNode := make(map[string]*nncp.Node, len(ctx.Neigh))
80 for _, node := range ctx.Neigh {
81 nodeNames = append(nodeNames, node.Name)
82 nodeNameToNode[node.Name] = node
84 sort.Strings(nodeNames)
87 for _, nodeName := range nodeNames {
88 node = nodeNameToNode[nodeName]
89 if nodeOnly != nil && *node.Id != *nodeOnly.Id {
92 rxNums := make(map[uint8]int)
93 rxBytes := make(map[uint8]int64)
94 for job := range ctx.Jobs(node.Id, nncp.TRx) {
96 rxNums[job.PktEnc.Nice] = rxNums[job.PktEnc.Nice] + 1
97 rxBytes[job.PktEnc.Nice] = rxBytes[job.PktEnc.Nice] + job.Size
99 txNums := make(map[uint8]int)
100 txBytes := make(map[uint8]int64)
101 for job := range ctx.Jobs(node.Id, nncp.TTx) {
103 txNums[job.PktEnc.Nice] = txNums[job.PktEnc.Nice] + 1
104 txBytes[job.PktEnc.Nice] = txBytes[job.PktEnc.Nice] + job.Size
106 fmt.Println(node.Name)
107 for nice := 0; nice < 256; nice++ {
108 rxNum, rxExists := rxNums[uint8(nice)]
109 txNum, txExists := txNums[uint8(nice)]
110 if !(rxExists || txExists) {
114 "\tnice:% 3d | Rx: % 10s, % 3d pkts | Tx: % 10s, % 3d pkts\n",
116 humanize.IBytes(uint64(rxBytes[uint8(nice)])),
118 humanize.IBytes(uint64(txBytes[uint8(nice)])),