Longhorn Module API Explanation
The Longhorn module aggregates node storage statistics and available persistent volume capacity.
API Execution Logic
The module locates the service matching the identifier longhorn. The target URL is parsed, and no authentication header is attached.
Request Execution
A GET request is sent to the /v1/nodes API endpoint. The request sets an Accept: application/json header and a 5-second timeout.
Data Parsing and Storage Aggregation
Upon receiving node details, the module iterates through the returned list of storage nodes:
- Node Counting: The length of the
dataarray represents the total number of storage nodes. - Disk Capacity Summation: For each node, the module loops through its configured
disksmap. It sums thestorageAvailablebyte values across all disks on all nodes. -
Unit Conversion: The total accumulated bytes are converted to gigabytes (divided by \(1024^3\)) and rounded to one decimal place.
-
Primary Metric: The total number of storage nodes.
- Secondary Metric: The formatted available storage string (e.g.
FREE: 143.2 GB).
Caching Strategy
Due to the overhead of traversing disk configurations, responses are cached for 60 seconds (TTL) with a maximum stale limit of 300 seconds.