0a44a55e9db9fa2bf72d7199bbe8de1ceaaabe3e
[govpp.git] / examples / stats-client / README.md
1 # Stats Client Example
2
3 This example demonstrates how to retrieve statistics from VPP using [the new Stats API](https://github.com/FDio/vpp/blob/master/src/vpp/stats/stats.md).
4
5 ## Requirements
6
7 The following requirements are required to run this example:
8
9 - install VPP **18.10+** (VPP 19.04+ for statsclient)
10 - enable stats in VPP
11
12 To enable stats add following section to you VPP config:
13
14   ```sh
15   statseg {
16         default
17         per-node-counters on
18   }
19   ```
20   > The [default socket](https://wiki.fd.io/view/VPP/Command-line_Arguments#.22statseg.22_parameters) is located at `/run/vpp/stats.sock`.
21
22 ## Running example
23
24 First build the example: `go build git.fd.io/govpp.git/examples/stats-api`.
25
26 ### Higher-level access to stats
27
28 Use commands following commands to retrieve stats that are aggregated and
29 processed into logical structures from [api package](../../api).
30
31 - `system` to retrieve system statistics
32 - `nodes` to retrieve per node statistics
33 - `interfaces` to retrieve per interface statistics
34 - `errors` to retrieve error statistics (you can use patterns to filter the errors)
35
36 #### System stats
37
38 Following command will retrieve system stats.
39 ```
40 $ ./stats-api system
41 System stats: &{VectorRate:0 InputRate:0 LastUpdate:32560 LastStatsClear:0 Heartbeat:3255}
42 ```
43
44 #### Node stats
45
46 Following command will retrieve per node stats.
47 ```
48 $ ./stats-api nodes
49 Listing node stats..
50 ...
51  - {NodeIndex:554 Clocks:0 Vectors:0 Calls:0 Suspends:0}
52  - {NodeIndex:555 Clocks:189609 Vectors:15 Calls:15 Suspends:0}
53  - {NodeIndex:556 Clocks:2281847 Vectors:0 Calls:0 Suspends:21}
54  - {NodeIndex:557 Clocks:0 Vectors:0 Calls:0 Suspends:0}
55  - {NodeIndex:558 Clocks:0 Vectors:0 Calls:0 Suspends:0}
56  - {NodeIndex:559 Clocks:7094 Vectors:0 Calls:1 Suspends:1}
57  - {NodeIndex:560 Clocks:88159323916601 Vectors:0 Calls:14066116 Suspends:0}
58  - {NodeIndex:561 Clocks:0 Vectors:0 Calls:0 Suspends:0}
59  - {NodeIndex:562 Clocks:0 Vectors:0 Calls:0 Suspends:0}
60  - {NodeIndex:563 Clocks:0 Vectors:0 Calls:0 Suspends:0}
61  - {NodeIndex:564 Clocks:447894125 Vectors:0 Calls:0 Suspends:32395}
62  - {NodeIndex:565 Clocks:1099655497824612 Vectors:0 Calls:40 Suspends:117}
63  - {NodeIndex:566 Clocks:0 Vectors:0 Calls:0 Suspends:0}
64  - {NodeIndex:567 Clocks:0 Vectors:0 Calls:0 Suspends:0}
65  - {NodeIndex:568 Clocks:0 Vectors:0 Calls:0 Suspends:0}
66  - {NodeIndex:569 Clocks:0 Vectors:0 Calls:0 Suspends:0}
67  - {NodeIndex:570 Clocks:0 Vectors:0 Calls:0 Suspends:0}
68  - {NodeIndex:571 Clocks:0 Vectors:0 Calls:0 Suspends:0}
69  - {NodeIndex:572 Clocks:0 Vectors:0 Calls:0 Suspends:0}
70 Listed 573 node counters
71 ```
72
73 #### Interface stats
74
75 Following command will retrieve per interface stats.
76 ```
77 $ ./stats-api interfaces
78 Listing interface stats..
79  - {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}
80  - {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}
81  - {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}
82  - {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}
83 Listed 4 interface counters
84 ```
85
86 #### Error stats
87
88 Following command will retrieve error stats.
89 Use flag `-all` to include stats with zero values.
90 ```
91 $ ./stats-api errors ip
92 Listing error stats.. ip
93  - {ip4-input/ip4 spoofed local-address packet drops 15}
94 Listed 1 (825) error counters
95 ```
96
97 ### Low-level access to stats
98
99 Use commands `ls` and `dump` to list and dump statistics in their raw format
100 from [adapter package](../../adapter).
101 Optionally, patterns can be used to filter the results.
102
103 #### List stats
104
105 Following command will list stats matching patterns `/sys/` and `/if/`.
106 ```
107 $ ./stats-api ls /sys/ /if/
108 Listing stats.. /sys/ /if/
109  - /sys/vector_rate
110  - /sys/input_rate
111  - /sys/last_update
112  - /sys/last_stats_clear
113  - /sys/heartbeat
114  - /sys/node/clocks
115  - /sys/node/vectors
116  - /sys/node/calls
117  - /sys/node/suspends
118  - /if/drops
119  - /if/punt
120  - /if/ip4
121  - /if/ip6
122  - /if/rx-no-buf
123  - /if/rx-miss
124  - /if/rx-error
125  - /if/tx-error
126  - /if/rx
127  - /if/rx-unicast
128  - /if/rx-multicast
129  - /if/rx-broadcast
130  - /if/tx
131  - /if/tx-unicast-miss
132  - /if/tx-multicast
133  - /if/tx-broadcast
134 Listed 25 stats
135 ```
136
137 #### Dump stats
138
139 Following command will dump stats with their types and actual values.
140 Use flag `-all` to include stats with zero values.
141 ```
142 $ ./stats-api dump
143 Dumping stats..
144  - /sys/last_update                       ScalarIndex 10408
145  - /sys/heartbeat                         ScalarIndex 1041
146  - /err/ip4-icmp-error/unknown type        ErrorIndex 5
147  - /net/route/to                CombinedCounterVector [[{Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:0 Bytes:0} {Packets:5 Bytes:420}]]
148  - /if/drops                      SimpleCounterVector [[0 5 5]]
149 Dumped 5 (2798) stats
150 ```