Datasources¶
Note
The Prometheus datasource is deprecated as of the 2026.1 release and will be removed in a future release. Use the Aetos datasource instead, which provides the same functionality with added multi-tenancy and Keystone authentication support. See the Migrating from Prometheus to Aetos guide.
DataSource base class¶
All datasource backends inherit from DataSourceBase and share a common
metric-retrieval interface.
Metric retrieval¶
statistic_aggregation(resource, resource_type, meter_name, period,
aggregate, granularity) is the public method used by strategies to
retrieve a metric value. It is implemented in the base class and manages a
per-instance in-memory cache backed by
MetricDataCache.
The cache key encodes all five parameters: (resource.uuid, meter_name,
aggregate, period, granularity). On the first call for a given combination
of these five values, the result is fetched from the backend and stored in the
cache. Subsequent calls with identical arguments return the cached value
without contacting the backend again.
Each concrete datasource implements _statistic_aggregation with the same
signature. That private method contains the backend-specific query logic and
is called by the base class on a cache miss.
Cache injection¶
inject_metric(resource_uuid, metric, aggregation, period, value,
granularity=300) writes a value directly into the cache without querying the
backend. Any subsequent statistic_aggregation call with the same
resource_uuid, metric, aggregation, period, and
granularity will return the injected value.
Parameter |
Description |
|---|---|
|
UUID of the resource |
|
Metric name as a key from |
|
Aggregation method (e.g. |
|
Time span in seconds the value covers |
|
The metric value to store |
|
Granularity in seconds (default |
Implementing a new datasource¶
A new datasource must:
Inherit from
DataSourceBaseand callsuper().__init__()to initialise the metric cache.Override
_statistic_aggregationwith the backend-specific query logic.Override the remaining abstract methods defined in
DataSourceBase(check_availability,list_metrics,statistic_series, and theget_host_*/get_instance_*convenience methods).
Warning
Overriding statistic_aggregation in a concrete datasource will bypass
the base-class caching system. If you do so, the datasource becomes
responsible for implementing its own caching strategy and must also provide
its own inject_metric implementation so that callers can pre-populate
the cache with externally computed values.