cx-cost-optimization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Optimization Skill
成本优化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, setting ingestion quotas, and configuring archive storage for cold data.
当需要调查或降低Coralogix数据成本时使用此Skill。它涵盖完整的成本管理生命周期:衡量当前支出、审核TCO策略、调整保留周期、设置摄入配额,以及为冷数据配置归档存储。
CLI Commands
CLI命令
| Command | Subcommands | Purpose |
|---|---|---|
| | Measure current data consumption |
| | Manage TCO (Total Cost of Ownership) policies |
| | Manage data retention periods |
| | Set ingestion guardrails |
| | Configure logs archive target |
| | Configure metrics archive storage |
| | Query billing and usage metrics via PromQL (instant) |
| | Query billing and usage metrics via PromQL (range) |
Key flags:
- All commands support for structured output and
-o jsonfor profile selection-p <profile> - accepts
cx usage dailyand--type processed-gbs|units|evaluation-tokens/--starttime filters--end - accepts
cx usage summary/--starttime filters--end - ,
cx tco create/update,cx retentions update,cx quotas create/update,cx archive logs setusecx archive metrics create/update/validate(or--from-file <path>for stdin)-
| 命令 | 子命令 | 用途 |
|---|---|---|
| | 衡量当前数据消耗 |
| | 管理TCO(总拥有成本)策略 |
| | 管理数据保留周期 |
| | 设置摄入防护规则 |
| | 配置日志归档目标 |
| | 配置指标归档存储 |
| | 通过PromQL查询计费和使用指标(即时查询) |
| | 通过PromQL查询计费和使用指标(范围查询) |
关键参数:
- 所有命令均支持 以输出结构化数据,支持
-o json选择配置文件-p <profile> - 接受
cx usage daily以及--type processed-gbs|units|evaluation-tokens/--start时间过滤器--end - 接受
cx usage summary/--start时间过滤器--end - 、
cx tco create/update、cx retentions update、cx quotas create/update、cx archive logs set支持cx archive metrics create/update/validate(或--from-file <path>表示标准输入)-
Cost Investigation Workflow
成本调查工作流
Follow these steps to diagnose and reduce costs:
按照以下步骤诊断并降低成本:
Step 1: Measure Current Usage
步骤1:衡量当前使用情况
bash
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 -o json
cx usage spans-count -o jsonIdentify which data types consume the most volume. Use to sort:
jqbash
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse'bash
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 -o json
cx usage spans-count -o json识别哪种数据类型消耗的容量最大。使用 进行排序:
jqbash
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse'Step 2: Review TCO Policies
步骤2:审核TCO策略
bash
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:
bash
cx tco list -o json | jq '.[] | select(.priority == "LOW") | {name, application, subsystem, archive_retention}'bash
cx tco list -o json
cx tco settings -o jsonTCO策略控制哪些日志进入频繁搜索(成本高、速度快)还是归档(成本低、速度慢)。检查是否有高容量、低价值的日志处于频繁搜索层级:
bash
cx tco list -o json | jq '.[] | select(.priority == "LOW") | {name, application, subsystem, archive_retention}'Step 3: Check Retention Settings
步骤3:检查保留设置
bash
cx retentions list -o json
cx retentions status -o jsonLong retention periods increase storage costs. Identify indices with unnecessarily long retention.
bash
cx retentions list -o json
cx retentions status -o json较长的保留周期会增加存储成本。识别保留周期过长的索引。
Step 4: Review Quota Rules
步骤4:审核配额规则
bash
cx quotas get -o jsonQuota rules cap ingestion volume. If there are no quotas and you see burst ingestion, recommend adding guardrails.
bash
cx quotas get -o json配额规则会限制摄入容量。如果没有设置配额且存在突发摄入情况,建议添加防护规则。
Step 5: Check Archive Configuration
步骤5:检查归档配置
bash
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.
bash
cx archive logs get -o json
cx archive metrics get -o json验证是否为冷数据配置了归档存储。如果未设置归档,这是一个节省成本的机会。
Step 6: Recommend Optimizations
步骤6:推荐优化方案
Based on findings, recommend changes in priority order (highest impact first).
根据调查结果,按优先级顺序(影响从高到低)推荐更改措施。
Common Optimization Patterns
常见优化模式
| Symptom | Diagnosis Command | Optimization |
|---|---|---|
| High-volume low-value logs | | Move to archive tier via |
| Long retention on cold data | | Reduce retention with |
| Burst ingestion spikes | | Add quota rules with |
| No cold storage configured | | Enable archive with |
| Expensive metrics not queried | | Enable metrics archiving with |
| 症状 | 诊断命令 | 优化措施 |
|---|---|---|
| 高容量低价值日志 | | 通过 |
| 冷数据保留周期过长 | | 使用 |
| 突发摄入峰值 | | 使用 |
| 未配置冷存储 | | 在获得用户批准后,使用 |
| 昂贵指标未被查询 | | 在获得用户批准后,使用 |
jq Examples
jq示例
Usage Analysis
使用情况分析
bash
undefinedbash
undefinedTop consumers by daily volume
按每日容量排序的顶级消耗者
cx usage summary -o json | jq '[.[] | {name, daily_avg: .avg_daily_gb}] | sort_by(.daily_avg) | reverse | .[0:10]'
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}]'
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 -o json | jq '.total_count'
cx usage spans-count -o json | jq '.total_count'
undefinedcx usage logs-count -o json | jq '.total_count'
cx usage spans-count -o json | jq '.total_count'
undefinedTCO Policy Analysis
TCO策略分析
bash
undefinedbash
undefinedPolicies routing to archive tier
路由至归档层级的策略
cx tco list -o json | jq '[.[] | select(.archive_retention != null)]'
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})'
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
undefinedcx tco test --from-file test-definition.json -o json
undefinedRetention Review
保留设置审核
bash
undefinedbash
undefinedAll retention settings
所有保留设置
cx retentions list -o json | jq '.[]'
cx retentions list -o json | jq '.[]'
Check if retention is active
检查保留设置是否激活
cx retentions status -o json
undefinedcx retentions status -o json
undefinedQuota Analysis
配额分析
bash
undefinedbash
undefinedCurrent quota rules
当前配额规则
cx quotas get -o json | jq '.rules // empty'
undefinedcx quotas get -o json | jq '.rules // empty'
undefinedArchive Status
归档状态
bash
undefinedbash
undefinedLogs archive configuration
日志归档配置
cx archive logs get -o json | jq '{active: .active, bucket: .bucket}'
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}'
---cx archive metrics get -o json | jq '{enabled: .enabled, bucket: .bucket}'
---Applying Changes
应用更改
IMPORTANT: NEVER pass without explicit user approval. All write operations across archive, TCO, retentions, and quotas require interactive confirmation and the 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--yes--yesRead-only mode: Use (or ) to safely explore cost data without risk of accidental writes. All query commands (usage, tco list/get, retentions list, quotas get, archive get) work normally in read-only mode.
--read-onlyCX_READ_ONLY=1Agent 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 .
--yesWhen modifying TCO policies, retention, quotas, or archive:
-
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.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: Useto set priority order. Policies are evaluated top-to-bottom; the first match wins.
cx tco reorder --from-file
重要提示:未经用户明确批准,切勿使用 参数。 所有涉及归档、TCO、保留设置和配额的写入操作都需要交互式确认,并且需要使用 参数才能以非交互式方式执行。在执行任何写入操作之前,向用户说明具体的更改内容,等待用户批准后再添加 参数。
--yes--yes--yes只读模式: 使用 (或 )可以安全地探索成本数据,而无需担心意外写入。所有查询命令(usage、tco list/get、retentions list、quotas get、archive get)在只读模式下均可正常工作。
--read-onlyCX_READ_ONLY=1Agent模式: 在AI Agent中运行时,cx会在写入操作时快速失败,而不是挂起等待标准输入提示。先获得用户确认,然后添加 参数重新运行。
--yes修改TCO策略、保留设置、配额或归档时:
-
从现有配置生成模板: 获取当前配置的JSON格式,修改后再应用:bash
cx tco get <policy-id> -o json > policy.json # 编辑policy.json cx tco update --from-file policy.json -
更改后验证: 重新运行诊断命令以确认更改已生效。
-
TCO策略顺序很重要: 使用设置优先级顺序。策略按从上到下的顺序评估,第一个匹配的策略生效。
cx tco reorder --from-file
Metrics-Based Cost Analysis
基于指标的成本分析
The API gives summaries, but for billing-accurate analysis, anomaly detection, and breakdown by pillar/feature, query the customer metrics exporter via PromQL.
cx usagecx usageKey Metrics
关键指标
| Metric | Meaning | Query suffix |
|---|---|---|
| Daily billable usage in units (canonical billing metric) | No |
| Current daily plan quota in units (snapshot) | No |
| Daily overage/PAYG usage in units | No |
| Processed data size in bytes | |
| AI evaluation tokens | |
| Processed metric samples | |
| 指标 | 含义 | 查询后缀 |
|---|---|---|
| 每日计费使用量(单位:计费单位,标准计费指标) | 无 |
| 当前每日套餐配额(单位:计费单位,快照) | 无 |
| 每日超额/PAYG使用量(单位:计费单位) | 无 |
| 处理的数据大小(单位:字节) | |
| AI评估令牌 | |
| 处理的指标样本 | |
Concept-to-Metric Mapping
概念与指标映射
- Billing / plan usage / consumption -> +
cx_data_usage_unitscx_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
- 计费/套餐使用/消耗 -> +
cx_data_usage_unitscx_data_plan_units_per_day - 处理字节数/数据容量 ->
cx_data_usage_total - AI评估令牌 ->
cx_data_usage_tokens_total - 指标样本 ->
cx_data_usage_samples_total - 超额使用/PAYG ->
cx_data_usage_payg_units
Common PromQL Queries
常见PromQL查询
bash
undefinedbash
undefinedToday's billable units consumed so far
今日截至目前已消耗的计费单位
cx metrics query 'sum(cx_data_usage_units)' --time now -o json
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
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
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
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
cx metrics query 'sum by (feature_group_id) (cx_data_usage_units)' --time now -o json
PAYG overage (if any)
PAYG超额使用量(如有)
cx metrics query 'cx_data_usage_payg_units' --time now -o json
undefinedcx metrics query 'cx_data_usage_payg_units' --time now -o json
undefinedUTC-Day Bucketing Rules
UTC日分桶规则
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
所有使用指标从UTC午夜开始累积,并在重置:
00:00 UTC- 白天的即时查询返回“今日截至目前”的数据
- 要获取完整日期的总计,使用午夜前的最后一个样本
- 切勿跨UTC午夜边界进行值的减法运算
- 进行周/月分析时,先获取完整的每日总计,再进行汇总
- 计算趋势或平均值时排除当前不完整的UTC日
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_namesubsystem_name - Prefer same-weekday comparisons for seasonal traffic
- Use for billing anomalies,
cx_data_usage_unitsfor volume anomaliescx_data_usage_total
调查使用异常时:
- 比较完整的UTC日数据(排除当前不完整的日期)
- 按以下维度细分:->
measurement_type->pillar->entity_type->priority->feature_group_id->application_namesubsystem_name - 优先选择同工作日进行比较,以应对季节性流量
- 计费异常使用,容量异常使用
cx_data_usage_unitscx_data_usage_total
Breakdown Labels
细分标签
Usage metrics support these grouping dimensions: , , , , , , , .
pillarentity_typeprioritymeasurement_typefeature_group_idfeature_idapplication_namesubsystem_name使用指标支持以下分组维度:、、、、、、、。
pillarentity_typeprioritymeasurement_typefeature_group_idfeature_idapplication_namesubsystem_nameKey Principles
核心原则
- Measure before changing - always run usage/summary commands before modifying policies
- Use with jq - structured output enables precise analysis
-o json - Verify changes - re-query after every modification to confirm it took effect
- Multi-profile awareness - use or
-p <profile>to compare costs across environments--all-profiles - 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
- 先衡量再更改 - 修改策略前务必运行usage/summary命令
- 结合与jq使用 - 结构化输出支持精准分析
-o json - 验证更改 - 每次修改后重新查询以确认生效
- 多配置文件意识 - 使用或
-p <profile>比较不同环境的成本--all-profiles - 从现有配置生成模板 - 创建或更新前先获取当前配置的JSON格式
- TCO是最大杠杆 - 将日志从频繁搜索移至归档层级对成本的影响最大
Related Skills
相关Skill
- - investigate what data is being ingested (understand usage before cutting)
cx-telemetry-querying - - query logs to identify high-volume sources
cx-query-logs - - check metric cardinality and usage
cx-metrics-query
- - 调查正在摄入的数据(在削减使用量前先了解使用情况)
cx-telemetry-querying - - 查询日志以识别高容量来源
cx-query-logs - - 检查指标基数和使用情况
cx-metrics-query