Skip to content

Commit 0cb3b6c

Browse files
committed
feat: add metric type 'buckets'
1 parent 8542e84 commit 0cb3b6c

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,44 @@ A `mapping` metric looks like this:
437437
arista_show_ip_bgp_summary_peerState{hostname="198.51.100.1",name="router-1.example.com",peer="192.168.1.1",vrf="default"} 6.0
438438
```
439439

440+
#### Buckets
441+
442+
```yaml
443+
show ip route vrf all summary:
444+
type: multiple
445+
lookup_keys: vrfs
446+
metrics:
447+
- name: maskLen
448+
type: buckets
449+
bucket_name: prefix_length
450+
```
451+
452+
Some data are spread out in a histogram kind of way. This is the case with the `maskLen` metric of `show ip route summary`
453+
which show number of routes spread out per mask length:
454+
455+
```json
456+
{
457+
"vrfs": {
458+
"default": {
459+
"maskLen": {
460+
"8": 2,
461+
"31": 19,
462+
"32": 25
463+
}
464+
}
465+
}
466+
}
467+
```
468+
469+
Instead of going through every possible metric from `- name: maskLen.0` up to `- name: masklen.32`, a metric of type `buckets`
470+
with a `bucket_name` will automatically produce metrics for every possible values represented as labels, like this :
471+
472+
```
473+
arista_show_ip_route_vrf_all_summary_maskLen{hostname="198.51.100.1",name="router-1.example.com",prefix_length="8"} 2.0
474+
arista_show_ip_route_vrf_all_summary_maskLen{hostname="198.51.100.1",name="router-1.example.com",prefix_length="31"} 19.0
475+
arista_show_ip_route_vrf_all_summary_maskLen{hostname="198.51.100.1",name="router-1.example.com",prefix_length="32"} 25.0
476+
```
477+
440478
### Labels
441479

442480
#### prom_name

api_commands.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ commands:
9292
- name: dynamicPolicy
9393
- name: internal
9494
- name: ospfCounts.ospfTotal
95+
- name: maskLen
96+
type: buckets
97+
bucket_name: prefix_length
9598
labels:
9699
- name: vrfs
97100
prom_name: vrf

arista-eapi-exporter.py

+17
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ def main(): # pylint: disable=missing-function-docstring
363363
labelnames=host_labels + normalized_labels,
364364
states=metric["enum"],
365365
)
366+
elif metric_type == "buckets":
367+
exported_metrics[metric_name] = Gauge(
368+
metric_name,
369+
f"Arista EOS metric '{metric['name']}' under '{command}'",
370+
labelnames=host_labels
371+
+ normalized_labels
372+
+ [metric["bucket_name"]],
373+
)
366374

367375
# This will hold each set of label:value ("labelset") PREVIOUSLY KNOWN for each metric. At each poll cycle, it will be compared
368376
# with the retrieved label:value set, in order to remove the no-longer-valid ones.
@@ -575,10 +583,12 @@ def main(): # pylint: disable=missing-function-docstring
575583
exported_metrics[metric_name].labels(
576584
**extracted_labels
577585
).set(metric_data)
586+
578587
elif metric_type == "enum":
579588
exported_metrics[metric_name].labels(
580589
**extracted_labels
581590
).state(metric_data)
591+
582592
elif metric_type == "mapping":
583593
mapped_value = metric["mapping"].get(metric_data)
584594
if mapped_value is None:
@@ -594,6 +604,13 @@ def main(): # pylint: disable=missing-function-docstring
594604
**extracted_labels
595605
).set(mapped_value)
596606

607+
elif metric_type == "buckets":
608+
for bucket_value, bucket_data in metric_data.items():
609+
bucket = {metric["bucket_name"]: bucket_value}
610+
exported_metrics[metric_name].labels(
611+
**extracted_labels, **bucket
612+
).set(bucket_data)
613+
597614
labelsets_current[metric_name].append(extracted_labels)
598615

599616
logger.info("Finished polling %s", target["name"])

0 commit comments

Comments
 (0)