Skip to main content

Overview

Fetch the metrics of a validator segment for the last 7 days, one day at a time, and write them to a CSV file. Fetching one day at a time accounts for the API response limit, which returns a maximum of 3000 results per request. When a time range holds more results, only the most recent 3000 are returned. Results older than the metric retention period are not returned. To fetch metrics for all segments of a validator, first call segments, which returns a list of all segments.

Steps

1

Construct the query

Select the values of interest for each metric type. If you know which threshold the validator uses, you only need that fragment.
2

Create a CSV writer

Create a CSV writer. For a specific validator, where the keys are known and a single threshold is used, a DictWriter is a better fit, because you don’t have to keep track of the columns.
3

Iterate over each day

For each day, execute the query and pass the validator ID, the segment ID, and the time range.
4

Write the result

For each day’s response, iterate over the values and write them to the CSV file. The first value’s keys become the header row.

Full code sample

Python

Example response

JSON