Count of Received IPv4 Unicast Prefixes

Sampling the number of received unicast prefixes is an example for an index based metric. The IPv4 unicast prefixes are stored in the instance.default.ribd.1.fib-local.ipv4.labeled-unicast table, which exists per routing instance with instance being the instance name. The prefix count can be read by sampling the active-entry-count attribute of the primary index. The listing below shows the JSON object to sample the active PPPoE sessions:

Listing 15 - JSON object to enable PPPoE session count sampling
{
    "rtbrick-config:metric": {
        "name": "default_ipv4_unicast_prefix_count",
        "table-name": "default.ribd.1.fib-local.ipv4.unicast",
        "bds-type": "index-metric",
        "index-name": "primary",
        "prometheus-type": "gauge",
        "description": "IPv4 unicast prefixes default instance",
        "attribute": [
            {
                "attribute-name": "active-entry-count"
            }
        ]
    }
}
The prefix count can increase and decrease. Therefore the metric type must be gauge rather than counter.

Run show datastore ribd schema table table-name default.ribd.1.fib-local.ipv4.unicast to inspect the definition of the default.ribd.1.fib-local.ipv4.unicast table.

Listing 16 - Excerpt of the table definition CLI output
$ show datastore fibd schema table-name default.ribd.1.fib-local.ipv4.labeled-unicast
{
  "table": {
    "type": "rib_fiblocal_v4_table",
    "object": "rib_entry",
    "table_objects": {
      "shared_object": "generic_table_attributes",
      "app_objects": [
        "generic_table_attributes"
      ]
    },
    "index": [
      {
        "name": "primary",
        "type": "radix",
        "immutable": true,
        "key": [
          "prefix4"
        ]
      },
 ...

The primary index uses the IPv4 prefix (prefix4) as key and contains an object per prefix. Counting the objects therefore represents the stored prefixes.