FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
Statistics

In VPP most things are measured and counted. There are counters for interface statistics, like RX, TX counters, packet drops, and so on. Every node has a set of per-node counters, one set of error counters, like TTL exceeded, or packet to big or out-of-buffers. And a set of performance counters, like number of clocks, vectors, calls and suspends.

There is also a set of system counters and performance counters, e.g. memory utilization per heap, buffer utilisation and so on.

VPP Counter Architecture

Counters are exposed directly via shared memory. These are the actual counters in VPP, no sampling or aggregation is done by the statistics infrastructure. With the exception of per node performance data under /sys/node and a few system counters.

Clients mount the shared memory segment read-only, using a optimistic concurrency algorithm.

Directory structure as an index.

Memory layout

The memory segment consists of a shared header, containing atomics for the optimistic concurrency mechanism, and offsets into memory for the directory vectors. The only data structure used is the VPP vectors. All pointers are converted to offsets so that client applications can map the shared memory wherever it pleases.

Directory layout

Optimistic concurrency

1 /*
2  * Shared header first in the shared memory segment.
3  */
4 typedef struct {
5  atomic_int_fast64_t epoch;
6  atomic_int_fast64_t in_progress;
7  atomic_int_fast64_t directory_offset;
8  atomic_int_fast64_t error_offset;
9  atomic_int_fast64_t stats_offset;
10 } stat_segment_shared_header_t;

Writer

On the VPP side there is a single writer (controlled by a spinlock). When the writer starts it sets in_progress=1, continues with the update of the data-structures, and when done, bumps epoch++ and sets in_progress=0.

Readers

If in_progress=1, there is no point continuing, so reader sits spinning on the in_progress flag until it is 0. Then it sets start_epoch = epoch and continues copying out the counter data it is interested in, while doing strict boundary checks on all offsets / pointers. When the reader is done, it checks if in_progress=1 or if epoch != start_epoch. If either of those are true is discards the data read.

How are counters exposed out of VPP?

Types of Counters

All counters under /err and /if are the directly exposed VPP counters.

  • Gauges
  • u64 / float
  • Interface Counters
    • Simple counters, counter_t array of threads of an array of interfaces
    • Combined counters, vlib_counter_t array of threads of an array of interfaces.

Client libraries

Writing a new client library

A new client library can either wrap the C library (libvppapiclient.so) or it can integrate directly with the shared memory. That involves exchanging a file descriptor over the VPP stats Unix domain socket, and opening the memory mapped segment.

Python

1 #!/usr/bin/env python
2 from vpp_papi.vpp_stats import VPPStats
3 stats = VPPStats('/var/run/stats.socks')
4 dir = stats.ls(['^/if', '/err/ip4-input', '/sys/node/ip4-input'])
5 counters = stats.dump(dir)
6 
7 # Print the RX counters for the first interface on the first worker core
8 print ('RX interface core 0, sw_if_index 0', counters['/if/rx'][0][0])

### C

1 #include <vpp-api/client/stat_client.h>
2 #include <vppinfra/vec.h>
3 
4 int main (int argc, char **argv) {
5  uint8_t *patterns = 0;
6 
7  vec_add1(patterns, "^/if");
8  vec_add1(patterns, "ip4-input");
9 
10  int rv = stat_segment_connect("/var/run/stats.sock");
11  uint32_t *dir = stat_segment_ls(patterns);
12  stat_segment_data_t *res = stat_segment_dump(dir);
13 
14  for (int i = 0; i < vec_len(res); i++) {
15  switch (res[i].type) {
16  case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
17  for (k = 0; k < vec_len (res[i].simple_counter_vec) - 1; k++)
18  for (j = 0; j < vec_len (res[i].simple_counter_vec[k]); j++)
19  fformat (stdout, "[%d @ %d]: %llu packets %s\n",
20  j, k, res[i].simple_counter_vec[k][j],
21  res[i].name);
22  break;
23 
24  case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
25  for (k = 0; k < vec_len (res[i].combined_counter_vec); k++)
26  for (j = 0; j < vec_len (res[i].combined_counter_vec[k]); j++)
27  fformat (stdout, "[%d @ %d]: %llu packets, %llu bytes %s\n",
28  j, k, res[i].combined_counter_vec[k][j].packets,
29  res[i].combined_counter_vec[k][j].bytes,
30  res[i].name);
31  break;
32 
33  case STAT_DIR_TYPE_ERROR_INDEX:
34  fformat (stdout, "%llu %s\n", res[i].error_value, res[i].name);
35  break;
36 
37  case STAT_DIR_TYPE_SCALAR_INDEX:
38  fformat (stdout, "%.2f %s\n", res[i].scalar_value, res[i].name);
39  break;
40 
41  default:
42  ;
43  }
44  }
45  stat_segment_data_free (res);
46 }

Integrations

  • CLI command. vpp_get_stats [ls | dump | poll]
  • Prometheus

Future evolution

  • Deprecate the stats over binary API calls that are based on want_stats