Cx Cost Optimization

coralogix/cx-cli/skills/cx-cost-optimization

作者 coralogixc0713729787b無授權條款121 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

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.

AI 產生的概覽

指導使用 cx CLI 的用量、TCO、保留期與封存指令,排查並降低 Coralogix 可觀測性資料成本。

功能
此技能引導代理完成 Coralogix 成本管理:衡量計費資料用量、檢視 TCO 政策、檢查保留期設定,並為冷資料設定封存儲存。它規定必須先執行 cx usage capabilities,再執行 cx usage query 的兩步流程,並以 PromQL 查詢 cx_data_usage_units 等計費指標。產出包括成本來源診斷,以及將日誌移至封存、縮短保留期或啟用封存的優先順序建議。文件也提供以 jq 為基礎的分析模式與寫入操作的安全規則。
適用情境
適用於使用者要求查看資料用量、排查 Coralogix 帳單過高或異常、檢視 TCO 政策或保留層級,或降低日誌與可觀測性支出的情境。它針對 Coralogix 租用戶上的成本分析與最佳化任務,而非一般資料分析。
執行需求
需要已驗證設定檔的 Coralogix cx CLI 及存取租用戶的網路連線,並使用 jq 進行 JSON 分析。寫入操作需使用者明確核准並加上 --yes 旗標,可透過 --read-only 或 CX_READ_ONLY=1 進入唯讀模式。此技能不含指令碼,僅附一份關於 Data Usage Query API 的參考文件。

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

CommandSubcommandsPurpose
cx usagesummary, daily, logs-count, spans-count, export-status, capabilities, queryMeasure current data consumption and billable usage
cx tcolist, get, create, update, delete, reorder, test, settings, settings-updateManage TCO (Total Cost of Ownership) policies
cx retentionslist, update, activate, statusManage data retention periods
cx archive logsget, setConfigure logs archive target
cx archive metricsget, create, update, enable, disable, validateConfigure metrics archive storage
cx metrics query<promql> (positional), --timeQuery billing and usage metrics via PromQL (instant)
cx metrics query-range<promql> (positional), --start/--endQuery billing and usage metrics via PromQL (range)

Key flags:

  • All commands support -o json for structured output and -p <profile> for profile selection
  • cx usage daily accepts --type processed-gbs|units|evaluation-tokens and --start/--end time filters
  • cx usage summary accepts --start/--end time filters
  • cx usage logs-count and cx usage spans-count accept --start/--end time filters, defaulting to the last 24h, plus --resolution (default 1h), --subsystem-aggregation, --application-aggregation, and repeated --param KEY=VALUE for 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 capabilities is 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 tenant
  • cx usage query is the required second step: submit only a JSON request derived from the immediately preceding capabilities response 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/validate use --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:

  1. Run cx usage capabilities in the current session.
  2. Build and run cx usage query using 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.

bash
# Inspect the currently valid dimensions and constraintscx usage capabilities -o json
# Submit a capabilities-derived request inlinecx usage query --query '{"daily":{"relativeRange":"DAILY_RELATIVE_RANGE_LAST_7_DAYS"}}' -o json
# Or read the same request from a file or stdincx usage query --from-file usage-query.json -o jsonprintf '%s' '{"daily":{"relativeRange":"DAILY_RELATIVE_RANGE_LAST_7_DAYS"}}' \  | cx usage query --from-file - -o json

Load references/data-usage-query-api.md [blocked] 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:

bash
cx usage capabilities -o jsoncx 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:

bash
cx usage summary -o jsoncx usage summary --start now-30d -o jsoncx usage daily --type processed-gbs --start now-7d -o jsoncx usage logs-count --start now-7d --end now -o jsoncx usage spans-count --start now-7d --end now -o json

Identify which data types consume the most volume. Use jq to sort:

bash
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse'

Step 2: Review TCO Policies

bash
cx tco list -o jsoncx 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:

bash
cx tco list -o json | jq '.[] | select(.priority == "LOW") | {name, application, subsystem, archive_retention}'

Step 3: Check Retention Settings

bash
cx retentions list -o jsoncx retentions status -o json

Long retention periods increase storage costs. Identify indices with unnecessarily long retention.

Step 4: Check Archive Configuration

bash
cx archive logs get -o jsoncx 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

SymptomDiagnosis CommandOptimization
High-volume low-value logscx usage summary -o jsonMove to archive tier via cx tco create --from-file policy.json
Long retention on cold datacx retentions list -o jsonReduce retention with cx retentions update --from-file
No cold storage configuredcx archive logs get -o jsonEnable archive with cx archive logs set --from-file --yes (after user approval)
Expensive metrics not queriedcx archive metrics get -o jsonEnable metrics archiving with cx archive metrics create --from-file --yes (after user approval)

jq Examples

Usage Analysis

bash
# Top consumers by daily volumecx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse | .[0:10]'
# Daily trend for the past weekcx usage daily --type processed-gbs --start now-7d -o json | jq '[.[] | {date, gb: .processed_gbs}]'
# Total logs and spans countscx 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

bash
# Policies routing to archive tiercx tco list -o json | jq '[.[] | select(.archive_retention != null)]'
# Policies by prioritycx tco list -o json | jq 'group_by(.priority) | map({priority: .[0].priority, count: length})'
# Test if a log pattern matches a policycx tco test --from-file test-definition.json -o json

Retention Review

bash
# All retention settingscx retentions list -o json | jq '.[]'
# Check if retention is activecx retentions status -o json

Archive Status

bash
# Logs archive configurationcx archive logs get -o json | jq '{active: .active, bucket: .bucket}'
# Metrics archive configurationcx 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:

  1. Template from existing: Get the current configuration as JSON, modify it, then apply:

    bash
    cx tco get <policy-id> -o json > policy.json# Edit policy.jsoncx tco update --from-file policy.json
  2. Verify after changes: Re-run the diagnosis commands to confirm the change took effect.

  3. TCO policy ordering matters: Use cx tco reorder --from-file to 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

MetricMeaningQuery suffix
cx_data_usage_unitsDaily billable usage in units (canonical billing metric)No _total
cx_data_plan_units_per_dayCurrent daily plan quota in units (snapshot)No _total
cx_data_usage_payg_unitsDaily overage/PAYG usage in unitsNo _total
cx_data_usage_totalProcessed data size in bytes_total
cx_data_usage_tokens_totalAI evaluation tokens_total
cx_data_usage_samples_totalProcessed 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

bash
# Today's billable units consumed so farcx metrics query 'sum(cx_data_usage_units)' --time now -o json
# Units breakdown by pillarcx metrics query 'sum by (pillar) (cx_data_usage_units)' --time now -o json
# Daily plan quotacx metrics query 'cx_data_plan_units_per_day' --time now -o json
# Plan consumption percentagecx metrics query '100 * sum(cx_data_usage_units) / cx_data_plan_units_per_day' --time now -o json
# Units by feature groupcx 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:

  1. Compare completed UTC days (exclude current partial day)
  2. Break down by: measurement_type -> pillar -> entity_type -> priority -> feature_group_id -> application_name -> subsystem_name
  3. Prefer same-weekday comparisons for seasonal traffic
  4. Use cx_data_usage_units for billing anomalies, cx_data_usage_total for 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 json with 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-profiles to 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 [blocked] - capabilities and query schemas, interval rules, limits, and response interpretation

來源與署名

來源:coralogix/cx-cli位於skills/cx-cost-optimization提交c071372

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架