Before you begin
- A saved transform with a cost. Refer to Price usage.
- A push connection. Several transforms can send through one connection, and each
counts its own usage. A push to the same connection with
overwrite: truereplaces transform usage in its window too, so keep those pushes on their own connection. - An API key with the
focus:writescope, from Settings > API keys.
Pick the connection
1
Open Send usage
On the transform, click Send usage.
2
Select the connection
In Connection, select the push connection for this source. The endpoint
and configuration update with its ID. If you have no push connection, click
Open integrations and create one.
3
Copy the configuration
Copy the endpoint and the configuration for your format, then replace
<CostGraph API key> with your key.X-API-Key header. The
hosted API is at https://api.costgraph.ai/api/v1.
JSON
Post events to the push endpoint with the connection ID and the transform ID. Put one event or many inrows.
accepted were recorded, and rejections lists
the index and error of each rejected event. When no event is accepted, the
response is 422.
OpenTelemetry
Add a pipeline to an OpenTelemetry Collector contrib build. The filter sends only your usage metric, andcumulativetodelta converts cumulative sums to the delta
sums CostGraph needs.
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta in your app instead of
using cumulativetodelta, so no replica has to track counters.
The transform accepts these metrics, in protobuf or JSON:
A gauge gap longer than 5 minutes counts as 5 minutes, so a series that stops
reporting stops adding cost. The latest value is billed when the next one arrives.
A cumulative sum or histogram is rejected with
Send delta metrics; add the cumulativetodelta processor to your collector pipeline. A summary is rejected,
because quantiles aren’t usage. The Collector reports the rejected data points
from the response.
Prometheus
Add aremote_write block to prometheus.yml. Prometheus keeps scraping as it
does today and sends only the metric you keep.
- Counter: CostGraph turns each increase into usage. The first sample of a new series sets the starting value. A drop in value counts as a counter reset.
- Gauge: CostGraph bills each value for the time it was held, as for
OpenTelemetry gauges, with the same 5 minute limit on gaps. Map
PricingQuantitytoevent.value_hours.
_count or _sum series on a Counter transform.
CostGraph skips _bucket series, because each bucket counts the same observations
again. A native histogram arrives as _count and _sum counters.
Resent usage
A resent request counts once. CostGraph identifies each event by its content, so retrying after a timeout doesn’t add usage twice. Two events with identical content count once too. Make sure each event differs somewhere, such as in its timestamp or request ID. To control identity yourself, open Advanced: batching and identity on the Mapping tab. Each field takes an expression over the event and defaults to the request value when empty.
For JSON, you can also send
batch_id, row_offset, and final in the request
body. They work as they do for paging a large export.
Next steps
Fix rejected events
Check what the transform accepted and fix events it rejected.