From 45e38494c1d65ad9178ad15f4048c0ab16f98b77 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 19 Feb 2019 13:57:12 +0100 Subject: Introduce higer-level API for retrieving statistics - see stats-api example Change-Id: I11d29d32b60d25238e75cb6b86ee34842348ab38 Signed-off-by: Ondrej Fabry --- examples/stats-api/README.md | 93 ++++++++++++++++++++++++++++++++++++++--- examples/stats-api/stats_api.go | 55 +++++++++++++++++++++--- 2 files changed, 136 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/stats-api/README.md b/examples/stats-api/README.md index 0f26197..77afad8 100644 --- a/examples/stats-api/README.md +++ b/examples/stats-api/README.md @@ -12,18 +12,96 @@ The following requirements are required to run this example: ```sh statseg { default + per-node-counters on } - ``` + ``` > The [default socket](https://wiki.fd.io/view/VPP/Command-line_Arguments#.22statseg.22_parameters) is located at `/run/vpp/stats.sock`. -- run the VPP, ideally with some traffic +- run the VPP (ideally with some traffic) ## Running example -First build the example: `go build git.fd.io/govpp.git/examples/stats-api`. +First build the example: `go build git.fd.io/govpp.git/examples/stats-api`. -Use commands `ls` and `dump` to list and dump statistics. Optionally, patterns can be used to filter the results. +### Higher-level access to stats -### List stats matching patterns `/sys/` and `/if/` +Use commands following commands to retrieve stats that are aggregated and +processed into logical structures from [api package](../../api). + +- `system` to retrieve system statistics +- `nodes` to retrieve per node statistics +- `interfaces` to retrieve per interface statistics +- `errors` to retrieve error statistics (you can use patterns to filter the errors) + +#### System stats + +Following command will retrieve system stats. +``` +$ ./stats-api system +System stats: &{VectorRate:0 InputRate:0 LastUpdate:32560 LastStatsClear:0 Heartbeat:3255} +``` + +#### Node stats + +Following command will retrieve per node stats. +``` +$ ./stats-api nodes +Listing node stats.. +... + - {NodeIndex:554 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:555 Clocks:189609 Vectors:15 Calls:15 Suspends:0} + - {NodeIndex:556 Clocks:2281847 Vectors:0 Calls:0 Suspends:21} + - {NodeIndex:557 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:558 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:559 Clocks:7094 Vectors:0 Calls:1 Suspends:1} + - {NodeIndex:560 Clocks:88159323916601 Vectors:0 Calls:14066116 Suspends:0} + - {NodeIndex:561 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:562 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:563 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:564 Clocks:447894125 Vectors:0 Calls:0 Suspends:32395} + - {NodeIndex:565 Clocks:1099655497824612 Vectors:0 Calls:40 Suspends:117} + - {NodeIndex:566 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:567 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:568 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:569 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:570 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:571 Clocks:0 Vectors:0 Calls:0 Suspends:0} + - {NodeIndex:572 Clocks:0 Vectors:0 Calls:0 Suspends:0} +Listed 573 node counters +``` + +#### Interface stats + +Following command will retrieve per interface stats. +``` +$ ./stats-api interfaces +Listing interface stats.. + - {InterfaceIndex:0 RxPackets:0 RxBytes:0 RxErrors:0 TxPackets:0 TxBytes:0 TxErrors:0 RxUnicast:[0 0] RxMulticast:[0 0] RxBroadcast:[0 0] TxUnicastMiss:[0 0] TxMulticast:[0 0] TxBroadcast:[0 0] Drops:0 Punts:0 IP4:0 IP6:0 RxNoBuf:0 RxMiss:0} + - {InterfaceIndex:1 RxPackets:0 RxBytes:0 RxErrors:0 TxPackets:0 TxBytes:0 TxErrors:0 RxUnicast:[0 0] RxMulticast:[0 0] RxBroadcast:[0 0] TxUnicastMiss:[0 0] TxMulticast:[0 0] TxBroadcast:[0 0] Drops:5 Punts:0 IP4:0 IP6:0 RxNoBuf:0 RxMiss:0} + - {InterfaceIndex:2 RxPackets:0 RxBytes:0 RxErrors:0 TxPackets:0 TxBytes:0 TxErrors:0 RxUnicast:[0 0] RxMulticast:[0 0] RxBroadcast:[0 0] TxUnicastMiss:[0 0] TxMulticast:[0 0] TxBroadcast:[0 0] Drops:0 Punts:0 IP4:0 IP6:0 RxNoBuf:0 RxMiss:0} + - {InterfaceIndex:3 RxPackets:0 RxBytes:0 RxErrors:0 TxPackets:0 TxBytes:0 TxErrors:0 RxUnicast:[0 0] RxMulticast:[0 0] RxBroadcast:[0 0] TxUnicastMiss:[0 0] TxMulticast:[0 0] TxBroadcast:[0 0] Drops:0 Punts:0 IP4:0 IP6:0 RxNoBuf:0 RxMiss:0} +Listed 4 interface counters +``` + +#### Error stats + +Following command will retrieve error stats. +Use flag `-all` to include stats with zero values. +``` +$ ./stats-api errors ip +Listing error stats.. ip + - {ip4-input/ip4 spoofed local-address packet drops 15} +Listed 1 (825) error counters +``` + +### Low-level access to stats + +Use commands `ls` and `dump` to list and dump statistics in their raw format +from [adapter package](../../adapter). +Optionally, patterns can be used to filter the results. + +#### List stats + +Following command will list stats matching patterns `/sys/` and `/if/`. ``` $ ./stats-api ls /sys/ /if/ Listing stats.. /sys/ /if/ @@ -55,7 +133,10 @@ Listing stats.. /sys/ /if/ Listed 25 stats ``` -### Dump all stats with their types and values +#### Dump stats + +Following command will dump stats with their types and actual values. +Use flag `-all` to include stats with zero values. ``` $ ./stats-api dump Dumping stats.. diff --git a/examples/stats-api/stats_api.go b/examples/stats-api/stats_api.go index 6fd46d2..b905f60 100644 --- a/examples/stats-api/stats_api.go +++ b/examples/stats-api/stats_api.go @@ -23,6 +23,7 @@ import ( "git.fd.io/govpp.git/adapter" "git.fd.io/govpp.git/adapter/vppapiclient" + "git.fd.io/govpp.git/core" ) // ------------------------------------------------------------------ @@ -39,7 +40,7 @@ var ( func init() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s: usage [ls|dump] ...\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "%s: usage [ls|dump|errors|interfaces|nodes|system] ...\n", os.Args[0]) flag.PrintDefaults() os.Exit(1) } @@ -47,11 +48,11 @@ func init() { func main() { flag.Parse() + skipZeros := !*dumpAll cmd := flag.Arg(0) - switch cmd { - case "", "ls", "dump": + case "", "ls", "dump", "errors", "interfaces", "nodes", "system": default: flag.Usage() } @@ -65,14 +66,56 @@ func main() { fmt.Printf("Connecting to stats socket: %s\n", *statsSocket) - if err := client.Connect(); err != nil { + c, err := core.ConnectStats(client) + if err != nil { log.Fatalln("Connecting failed:", err) } - defer client.Disconnect() + defer c.Disconnect() switch cmd { + case "system": + stats, err := c.GetSystemStats() + if err != nil { + log.Fatalln("getting system stats failed:", err) + } + fmt.Printf("System stats: %+v\n", stats) + case "nodes": + fmt.Println("Listing node stats..") + stats, err := c.GetNodeStats() + if err != nil { + log.Fatalln("getting node stats failed:", err) + } + for _, iface := range stats.Nodes { + fmt.Printf(" - %+v\n", iface) + } + fmt.Printf("Listed %d node counters\n", len(stats.Nodes)) + case "interfaces": + fmt.Println("Listing interface stats..") + stats, err := c.GetInterfaceStats() + if err != nil { + log.Fatalln("getting interface stats failed:", err) + } + for _, iface := range stats.Interfaces { + fmt.Printf(" - %+v\n", iface) + } + fmt.Printf("Listed %d interface counters\n", len(stats.Interfaces)) + case "errors": + fmt.Printf("Listing error stats.. %s\n", strings.Join(patterns, " ")) + stats, err := c.GetErrorStats(patterns...) + if err != nil { + log.Fatalln("getting error stats failed:", err) + } + n := 0 + for _, counter := range stats.Errors { + if counter.Value == 0 && skipZeros { + continue + } + fmt.Printf(" - %v\n", counter) + n++ + } + fmt.Printf("Listed %d (%d) error counters\n", n, len(stats.Errors)) case "dump": - dumpStats(client, patterns, !*dumpAll) + dumpStats(client, patterns, skipZeros) default: listStats(client, patterns) } -- cgit 1.2.3-korg