OSS bill analysis examples

更新时间:
复制 MD 格式

This topic explains how to use OSS self-service analysis reports, provides common examples of OSS cost analysis, and describes how to configure cost alerts.

OSS self-service analysis reports

Cost Manager provides two statistical reports: OSS Bill Self-service Analysis and OSS Cost Trends and Structure. Click the OSS Bill Self-service Analysis report to view your OSS cost, storage, and traffic usage.

The OSS Cost Trends and Structure report shows your costs and cost forecasts for the last month, and your consumption and cost forecasts for the last six months. In the Cost Structure section, the report breaks down costs by region, cost category, and storage class, helping you quickly understand your cost composition.

Custom OSS cost analysis

The Custom Analysis feature in Cost Manager lets you write custom analysis queries.

Example 1: Calculate instance-level OSS costs

This query calculates costs at the OSS instance level. In the results, region represents the bucket region and type represents the instance storage class.

* | select
  instanceId,
  split_part(InstanceID, ';', 1) as region,
  split_part(InstanceID, ';', 2) as type,
  sum(PretaxAmount) as cost
FROM  instance_bill
where
  productcode = 'oss'
group by
  split_part(InstanceID, ';', 1),
  split_part(InstanceID, ';', 2),
  instanceId

Example 2: Query daily costs by billing item

In OSS bills, the InstanceID is formatted as region;type, for example, cn-hangzhou;Standard. This ID represents the smallest billable unit, which is a combination of a region and a storage class. The following query statement calculates the daily costs for each billing item of a specific OSS instance. Replace ${instanceId} with your instance ID.

* | select
  date_trunc('day', __time__) as t,
  billingItem,
  sum(PretaxAmount) as cost
FROM  instance_bill
where
  productcode = 'oss'
  and instanceId = '${instanceId}'
group by
  t,
  billingItem
order by
  t

OSS instance cost alert setup

The Alerts page, accessible from the left-side navigation pane, shows all alerts for the current project in Cost Manager. The following example shows how to create an alert that triggers when the total cost of a single instance exceeds a threshold.

  1. In the left-side navigation pane, click Alerts. On the Alert Center page, click Create Alert.

  2. On the Create Alert page, configure the Check Frequency, Query Statistics, and Trigger Condition. For other parameters, see Configuration Description.

    Use the following query to retrieve the total cost of an instance from the previous day. Because bill data is synchronized on a T+1 basis, set the query time range to Yesterday. Since SLS bill data is generated daily, set the alert check frequency to 1 day. Set Trigger Condition to data matches the expression, and configure the expression to trigger the alert when the cost value exceeds your alert threshold. This example uses an alert threshold of 10.

    * | select
      instanceId,
      sum(PretaxAmount) as cost
    FROM  instance_bill
    where
      productcode = 'oss'
    group by
      instanceId

    Set Group Evaluation to No Grouping and Severity to Medium.

    In the Query Statistics section, select Advanced Settings. Set Type to Logstore, and select aliyun_bill as the logstore. When finished, click Confirm.

  3. After configuring the alert, you can view its trigger records on the alert dashboard. For more information, see Step 4: View alert trigger records.