- Skill ID
- coralogix/cx-cli/cx-cost-optimization
- Publisher
- coralogix
- Repository
- cx-cli
- Installs
- 0
- Files
- 2
- Synced
- Sep 23, 2026
Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.
coralogix/cx-cli/cx-cost-optimizationInstalls these files- SKILL.md
- references/data-usage-query-api.md
What this skill tells the agent
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 jsonLoad `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 jsonBuild 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 jsonIdentify 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 jsonTCO 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 jsonLong 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 jsonVerify 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 jsonRetention Review
# All retention settings
cx retentions list -o json | jq '.[]'
# Check if retention is active
cx retentions status -o jsonArchive 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
More from coralogix
Use this skill in a project
Open any RiverX project, search the Skills panel for coralogix/cx-cli/cx-cost-optimization, and install it in one click.
