cx-cost-optimization
coralogix/cx-cli
Analyze and optimize Coralogix data costs through usage measurement, TCO policies, and retention management.
What is cx-cost-optimization?
This skill helps investigate and reduce Coralogix observability spending by measuring current data consumption, reviewing cost optimization (TCO) policies, adjusting retention periods, and configuring archive storage for cold data. Use it when users ask about billing, data usage, cost reduction, or want to understand what's driving their observability expenses.
- Measure billable data consumption and quota usage via the Data Usage Query API
- Review and manage TCO policies that route logs between Frequent Search and Archive tiers
- List and adjust data retention periods for different data types
- Configure archive storage targets for logs and metrics to reduce costs
- Query usage trends and breakdowns by application, subsystem, or time period
- Identify high-volume, low-value data candidates for cost optimization
How to install cx-cost-optimization
npx skills add https://github.com/coralogix/cx-cli --skill cx-cost-optimization- Coralogix account with API access and appropriate permissions to view usage and manage TCO policies, retention, and archive settings
- cx-cli installed and authenticated with valid Coralogix credentials
How to use cx-cost-optimization
- 1.Run `cx usage capabilities -o json` to retrieve the current tenant's supported dimensions, measurements, and constraints
- 2.Build a usage query from the capabilities response and run `cx usage query --from-file usage-query.json -o json` to get authoritative billable totals
- 3.Run `cx tco list -o json` and `cx retentions list -o json` to review current cost policies and retention settings
- 4.Identify high-volume or long-retained data using jq filters (e.g., sort by daily_avg_gb)
- 5.Create or update TCO policies with `cx tco create --from-file policy.json` to route low-value logs to Archive tier
- 6.Update retention periods with `cx retentions update --from-file retention.json` to reduce storage duration
- 7.Configure archive storage with `cx archive logs set --from-file --yes` or `cx archive metrics create --from-file --yes` for cold data
Use cases
- A user reports their Coralogix bill is higher than expected; run usage summary and daily queries to identify top consumers
- A team wants to move verbose debug logs to archive storage; create a TCO policy routing them to the Archive tier
- Retention periods are set to 90 days but most queries only need 30 days of data; update retention to reduce storage costs
- Archive storage is not configured; set up logs or metrics archiving to enable cheaper cold-data storage
- Analyze daily usage trends over the past week to spot anomalies or seasonal patterns in data ingestion
- DevOps engineers managing observability costs
- Platform teams optimizing logging infrastructure spend
- SREs investigating unexpected billing increases
- Architects designing cost-efficient observability strategies
cx-cost-optimization FAQ
The legacy commands (`cx usage summary`, `cx usage daily`) provide a quick consumption overview but are not authoritative for billing. The Data Usage Query API (via `cx usage capabilities` + `cx usage query`) returns tenant-specific, billable totals and is the required method for accurate cost analysis.
Run `cx usage summary -o json` to identify high-volume data types, then use `cx tco list -o json` to see which are currently on Frequent Search. Logs that are rarely queried or are verbose debug output are good candidates for archiving via a new TCO policy.
Yes. You can move logs to Archive (slower but cheaper), reduce retention periods on cold data, or enable metrics archiving. Archive data is still queryable; it just takes longer and costs less.
TCO policies are evaluated in priority order. Use `cx tco reorder --from-file` to set the evaluation sequence, and `cx tco test --from-file` to validate a policy against sample logs before deploying.
The `--yes` flag bypasses confirmation. Omit it to review the configuration first, or use `cx archive logs get` / `cx archive metrics get` to inspect current settings before making changes.
Full instructions (SKILL.md)
Source of truth, from coralogix/cx-cli.
name: cx-cost-optimization description: > Use this skill when the user asks to "check data usage", "list TCO policies", "reduce Coralogix costs", "optimize observability spend", "lower our logging bill", "data budget exceeded", "TCO policy", "retention tier", "archive storage", "ingestion costs", "frequent search vs archive", "why is our bill so high", "spending too much on logs", "data retention settings", "cost analysis", "usage breakdown", "optimize log volume", "control data ingestion", "archive cold data", "billing units", "plan consumption", "daily plan", "overage", "PAYG", "usage anomaly", "usage trend", "cx_data_usage_units", or wants to investigate, analyze, or reduce Coralogix data costs. metadata: version: "0.1.0"
Cost Optimization Skill
Use this skill when investigating or reducing Coralogix data costs. It covers the full cost management lifecycle: measuring current spend, reviewing TCO policies, adjusting retention periods, and configuring archive storage for cold data.
CLI Commands
| Command | Subcommands | Purpose |
|---|---|---|
cx usage | summary, daily, logs-count, spans-count, export-status, capabilities, query | Measure current data consumption and billable usage |
cx tco | list, get, create, update, delete, reorder, test, settings, settings-update | Manage TCO (Total Cost of Ownership) policies |
cx retentions | list, update, activate, status | Manage data retention periods |
cx archive logs | get, set | Configure logs archive target |
cx archive metrics | get, create, update, enable, disable, validate | Configure metrics archive storage |
cx metrics query | <promql> (positional), --time | Query billing and usage metrics via PromQL (instant) |
cx metrics query-range | <promql> (positional), --start/--end | Query billing and usage metrics via PromQL (range) |
Key flags:
- All commands support
-o jsonfor structured output and-p <profile>for profile selection cx usage dailyaccepts--type processed-gbs|units|evaluation-tokensand--start/--endtime filterscx usage summaryaccepts--start/--endtime filterscx usage logs-countandcx usage spans-countaccept--start/--endtime filters, defaulting to the last 24h, plus--resolution(default1h),--subsystem-aggregation,--application-aggregation, and repeated--param KEY=VALUEfor API filter query params- Data usage summary and count endpoints are documented as newline-delimited JSON over
Accept: text/event-stream; the CLI handles that transport and normalizes count chunks into.result.logsCount[]or.result.spansCount[]. cx usage capabilitiesis the required first step: it returns the labels, measurements, units, and request limits that the public Data Usage Query API currently supports for the selected tenantcx usage queryis the required second step: submit only a JSON request derived from the immediately precedingcapabilitiesresponse with exactly one of--query '<json>'or--from-file <path>(--from-file -reads stdin)cx tco create/update,cx retentions update,cx archive logs set,cx archive metrics create/update/validateuse--from-file <path>(or-for stdin)
Authoritative Billable Usage Queries
For billable totals, quota units, plan consumption, or a supported usage breakdown, use this mandatory two-step workflow:
- Run
cx usage capabilitiesin the current session. - Build and run
cx usage queryusing only that response.
Do not call cx usage query first and do not guess labels, measurement kinds, units, filter values, intervals, or request limits. They are tenant-specific and can change.
# Inspect the currently valid dimensions and constraints
cx usage capabilities -o json
# Submit a capabilities-derived request inline
cx usage query --query '{"daily":{"relativeRange":"DAILY_RELATIVE_RANGE_LAST_7_DAYS"}}' -o json
# Or read the same request from a file or stdin
cx usage query --from-file usage-query.json -o json
printf '%s' '{"daily":{"relativeRange":"DAILY_RELATIVE_RANGE_LAST_7_DAYS"}}' \
| cx usage query --from-file - -o json
Load references/data-usage-query-api.md before creating the query body. It defines the capability and response schemas, valid interval forms, and limits.
Cost Investigation Workflow
Follow these steps to diagnose and reduce costs:
Step 1: Measure Current Usage
For billable totals, quota units, plan consumption, or supported breakdowns, first follow the mandatory two-step workflow above:
cx usage capabilities -o json
cx usage query --from-file usage-query.json -o json
Build usage-query.json only from the immediately preceding capabilities response. Do not use the legacy commands below as a substitute for an authoritative billing answer.
For a legacy consumption overview and log/span record counts, use:
cx usage summary -o json
cx usage summary --start now-30d -o json
cx usage daily --type processed-gbs --start now-7d -o json
cx usage logs-count --start now-7d --end now -o json
cx usage spans-count --start now-7d --end now -o json
Identify which data types consume the most volume. Use jq to sort:
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse'
Step 2: Review TCO Policies
cx tco list -o json
cx tco settings -o json
TCO policies control which logs go to Frequent Search (expensive, fast) vs. Archive (cheap, slower). Check if high-volume, low-value logs are on Frequent Search:
cx tco list -o json | jq '.[] | select(.priority == "LOW") | {name, application, subsystem, archive_retention}'
Step 3: Check Retention Settings
cx retentions list -o json
cx retentions status -o json
Long retention periods increase storage costs. Identify indices with unnecessarily long retention.
Step 4: Check Archive Configuration
cx archive logs get -o json
cx archive metrics get -o json
Verify that archive storage is configured for cold data. If no archive is set up, that's a cost-saving opportunity.
Step 5: Recommend Optimizations
Based on findings, recommend changes in priority order (highest impact first).
Common Optimization Patterns
| Symptom | Diagnosis Command | Optimization |
|---|---|---|
| High-volume low-value logs | cx usage summary -o json | Move to archive tier via cx tco create --from-file policy.json |
| Long retention on cold data | cx retentions list -o json | Reduce retention with cx retentions update --from-file |
| No cold storage configured | cx archive logs get -o json | Enable archive with cx archive logs set --from-file --yes (after user approval) |
| Expensive metrics not queried | cx archive metrics get -o json | Enable metrics archiving with cx archive metrics create --from-file --yes (after user approval) |
jq Examples
Usage Analysis
# Top consumers by daily volume
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse | .[0:10]'
# Daily trend for the past week
cx usage daily --type processed-gbs --start now-7d -o json | jq '[.[] | {date, gb: .processed_gbs}]'
# Total logs and spans counts
cx usage logs-count --start now-7d --end now -o json | jq '[.result.logsCount[]?.logsCount | tonumber] | add // 0'
cx usage spans-count --start now-7d --end now -o json | jq '[.result.spansCount[]? | ((.successSpanCount | tonumber) + (.errorSpanCount | tonumber) + (.lowSuccessSpanCount | tonumber) + (.lowErrorSpanCount | tonumber) + (.mediumSuccessSpanCount | tonumber) + (.mediumErrorSpanCount | tonumber))] | add // 0'
TCO Policy Analysis
# Policies routing to archive tier
cx tco list -o json | jq '[.[] | select(.archive_retention != null)]'
# Policies by priority
cx tco list -o json | jq 'group_by(.priority) | map({priority: .[0].priority, count: length})'
# Test if a log pattern matches a policy
cx tco test --from-file test-definition.json -o json
Retention Review
# All retention settings
cx retentions list -o json | jq '.[]'
# Check if retention is active
cx retentions status -o json
Archive Status
# Logs archive configuration
cx archive logs get -o json | jq '{active: .active, bucket: .bucket}'
# Metrics archive configuration
cx archive metrics get -o json | jq '{enabled: .enabled, bucket: .bucket}'
Applying Changes
IMPORTANT: NEVER pass --yes without explicit user approval. All write operations across archive, TCO, and retentions require interactive confirmation and the --yes flag to execute non-interactively. Before executing any write operation, describe the exact change to the user and wait for their approval before passing --yes.
Read-only mode: Use --read-only (or CX_READ_ONLY=1) to safely explore cost data without risk of accidental writes. All query commands (usage, tco list/get, retentions list, archive get) work normally in read-only mode.
Agent mode: When running inside an AI agent, cx fails fast on write operations instead of hanging on a stdin prompt. Get user confirmation first, then re-run with --yes.
When modifying TCO policies, retention, or archive:
-
Template from existing: Get the current configuration as JSON, modify it, then apply:
cx tco get <policy-id> -o json > policy.json # Edit policy.json cx tco update --from-file policy.json -
Verify after changes: Re-run the diagnosis commands to confirm the change took effect.
-
TCO policy ordering matters: Use
cx tco reorder --from-fileto set priority order. Policies are evaluated top-to-bottom; the first match wins.
Metrics-Based Cost Analysis
The cx usage API gives summaries, but for billing-accurate analysis, anomaly detection, and breakdown by pillar/feature, query the customer metrics exporter via PromQL.
Key Metrics
| Metric | Meaning | Query suffix |
|---|---|---|
cx_data_usage_units | Daily billable usage in units (canonical billing metric) | No _total |
cx_data_plan_units_per_day | Current daily plan quota in units (snapshot) | No _total |
cx_data_usage_payg_units | Daily overage/PAYG usage in units | No _total |
cx_data_usage_total | Processed data size in bytes | _total |
cx_data_usage_tokens_total | AI evaluation tokens | _total |
cx_data_usage_samples_total | Processed metric samples | _total |
Concept-to-Metric Mapping
- Billing / plan usage / consumption ->
cx_data_usage_units+cx_data_plan_units_per_day - Processed bytes / data volume ->
cx_data_usage_total - AI evaluation tokens ->
cx_data_usage_tokens_total - Metric samples ->
cx_data_usage_samples_total - Overage / PAYG ->
cx_data_usage_payg_units
Common PromQL Queries
# Today's billable units consumed so far
cx metrics query 'sum(cx_data_usage_units)' --time now -o json
# Units breakdown by pillar
cx metrics query 'sum by (pillar) (cx_data_usage_units)' --time now -o json
# Daily plan quota
cx metrics query 'cx_data_plan_units_per_day' --time now -o json
# Plan consumption percentage
cx metrics query '100 * sum(cx_data_usage_units) / cx_data_plan_units_per_day' --time now -o json
# Units by feature group
cx metrics query 'sum by (feature_group_id) (cx_data_usage_units)' --time now -o json
# PAYG overage (if any)
cx metrics query 'cx_data_usage_payg_units' --time now -o json
UTC-Day Bucketing Rules
All usage metrics accumulate from UTC midnight and reset at 00:00 UTC:
- An instant query during the day returns "today so far"
- For completed-day totals, use the last sample before midnight
- Never subtract values across a UTC midnight boundary
- For weekly/monthly analysis, derive completed daily totals first, then roll up
- Exclude the current partial UTC day when computing trends or averages
Anomaly Detection
When investigating usage anomalies:
- Compare completed UTC days (exclude current partial day)
- Break down by:
measurement_type->pillar->entity_type->priority->feature_group_id->application_name->subsystem_name - Prefer same-weekday comparisons for seasonal traffic
- Use
cx_data_usage_unitsfor billing anomalies,cx_data_usage_totalfor volume anomalies
Breakdown Labels
Usage metrics support these grouping dimensions: pillar, entity_type, priority, measurement_type, feature_group_id, feature_id, application_name, subsystem_name.
Key Principles
- Measure before changing - always run usage/summary commands before modifying policies
- Use
-o jsonwith jq - structured output enables precise analysis - Verify changes - re-query after every modification to confirm it took effect
- Multi-profile awareness - use
-p <profile>or--all-profilesto compare costs across environments - Template from existing - get current config as JSON before creating or updating
- TCO is the biggest lever - moving logs from Frequent Search to Archive tier has the largest cost impact
Related Skills
cx-telemetry-querying- investigate what data is being ingested (query logs, metrics, and spans to identify high-volume sources)
Reference Files
references/data-usage-query-api.md- capabilities and query schemas, interval rules, limits, and response interpretation
Related skills
More from coralogix/cx-cli and the wider catalog.

cx-dashboards
Build and deploy Coralogix dashboards from service telemetry via cx CLI.

cx-data-pipeline
Configure Coralogix data pipelines: parsing rules, enrichments, Events2Metrics, and recording rules.

cx-incident-management
>

cx-infra
Query and filter Coralogix infrastructure resources—discover types, list resources, check health.

cx-observability-setup
Set up monitoring, alerts, webhooks, and integrations for your observability stack.

cx-olly
Chat with Coralogix's Olly Observability Agent to analyze logs, metrics, and alerts via natural language.