Portainer Module API Explanation
The Portainer module monitors container statuses and environment counts across Portainer endpoints.
API Execution Logic
The module locates the service matching the identifier portainer. It retrieves the PORTAINER_API_KEY (or PORTAINER_TOKEN) and attaches it via the X-API-Key header.
Request Execution
A GET request is sent to the /api/endpoints endpoint under the target URL. Trailing slashes are stripped from the base URL to prevent HTTP 404 errors. A 5-second timeout is attached.
Data Parsing
Portainer returns an array of environments. The module aggregates the container metrics:
- Active Environments: Loops through all environments returned by the API.
- Container Counts: It parses the
Snapshotsarray for each environment to extract container counts. To support Portainer Community Edition, the module checks for theContainerCountproperty in the snapshot schema. - Primary Metric: The total count of running containers.
- Secondary Metric: The total count of all containers (running and stopped).
Caching Strategy
The telemetry is cached for 60 seconds (TTL) with a stale window of 300 seconds to minimize polling overhead.