costDataModel & aggregatedCostModel API
These APIs are now deprecated. This page should not be consulted. Please reference the Allocation API doc for updated information.
Kubecost exposes multiple APIs to obtain cost, resource allocation, and utilization data. Below is documentation on two options: the cost model API and aggregated cost model API.
Cost model API
The full cost model API exposes pricing model inputs at the individual container/workload level and is available at:
http://<kubecost-address>/model/costDataModel
Here's an example use:
http://localhost:9090/model/costDataModel?timeWindow=7d&offset=7d
API parameters include the following:
timeWindow
dictates the applicable window for measuring cost metrics. Supported units are d, h, and m.offset
shifts timeWindow backward relative to the current time. Supported units are d, h, and m.
This API returns a set of JSON elements in this format:
Optional request parameters include the following:
Aggregated cost model API
NOTE: this API is actively being replaced by the Allocation API. That is the recommended API for querying historical and run-rate cost allocation metrics.
The aggregated cost model API retrieves data similar to the Kubecost Allocation frontend view (e.g. cost by namespace, label, deployment, and more) and is available at the following endpoint:
http://<kubecost-address>/model/aggregatedCostModel
Here are example uses:
http://localhost:9090/model/aggregatedCostModel?window=1d&aggregation=namespace
http://localhost:9090/model/aggregatedCostModel?window=1d&aggregation=label&aggregationSubfield=product
http://localhost:9090/model/aggregatedCostModel?window=1d&aggregation=namespace&sharedNamespaces=kube-system
API parameters include the following:
window
dictates the applicable window for measuring cost metrics. Current support options:"15m", "24h", "7d", "48h", etc.
"today", "yesterday", "week", "month", "lastweek", "lastmonth"
"1586822400,1586908800", etc. (start and end unix timestamps)
"2020-04-01T00:00:00Z,2020-04-03T00:00:00Z", etc. (start and end UTC RFC3339 pairs)
offset
(optional) shifts window backward from current time. Supported units are d, h, m, and s.aggregation
is the field used to consolidate cost model data. Supported types are cluster, namespace, controller, deployment, service, label, pod and container.aggregationSubfield
used for aggregation types that require subfields, e.g. aggregation type equalslabel
and the value of the label (aggregationSubfield) equalsapp
. Comma-separated list of values supported.allocateIdle
(optional) when set totrue
, applies the cost of all idle compute resources to tenants, defaultfalse
.sharedNamespaces
(optional) provide a comma-separated list of namespaces (e.g. kube-system) to be allocated to other tenants. These resources are evenly allocated to other tenants assharedCost
.sharedLabelNames
(optional) provide a comma-separated list of Kubernetes labels (e.g. app) to be allocated to other tenants. Must provide the corresponding set of label values insharedLabelValues
.sharedLabelValues
(optional) label value (e.g. prometheus) associated withsharedLabelNames
parameter.sharedSplit
(optional) Shared costs are split evenly across tenants unlessweighted
is passed for this request parameter. When allocating shared costs on a weighted basis, these costs are distributed based on the percentage of in-cluster resource costs of the individual pods in the particular aggregation, e.g. namespace.disableCache
this API caches recently fetched data by default. Set this variable tofalse
to avoid cache entirely.etl
setting this variable totrue
forces a request to be served by the ETL pipeline. More info on this feature is in the Caching Overview section below.
Optional filter parameters include the following:
This API returns a set of JSON objects in this format:
Caching Overview
Kubecost implements a two-layer caching system for cost allocation metrics.
First, the unaggregated cost model is pre-cached for commonly used time windows, 1 and 2 days by default. This data is refreshed every ~5 minutes.
Longer time windows, 120 days by default, are part of an ETL pipeline that stores cost by day for each workload. This pipeline is updated approximately ~10 mins. On update, only the latest day is rebuilt to reduce the load on the underlying data store. Currently, this ETL pipeline is stored in memory and is built any time the pod restarts. ETL is built with daily granularity for UI improved performance. Daily aggregations default to UTC
but timezones can be configured with the utcOffset
within values.
Returning cached data from either caching layer typically takes < 300ms on medium-sized clusters. To guarantee you bypass both caches, you can set etl=false
and disableCache=false
.
Have questions? Email us at support@kubecost.com.
Last updated