OSS bill analysis examples

Updated at:

Use the OSS self-service analysis reports in Cost Manager to review your OSS costs, analyze costs with your own queries, and configure OSS 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 costs, storage usage, and traffic usage.

Click OSS Cost Trends and Structure. This report shows costs and cost forecasts for the past month, and consumption and cost forecasts for the past six months. The Cost Structure section breaks down costs by region, cost category, and storage class so that you can quickly see how your costs are composed.

Custom OSS cost analysis

In Cost Manager, use Custom Analysis to write your own query and analysis statements.

Example 1: Calculate OSS costs at the instance level

The following query and analysis statement calculates OSS costs at the instance level, where region is the bucket region and type is 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 the daily cost of each billing item for an OSS resource instance

In OSS bills, InstanceID uses the region;type format, such as cn-hangzhou;Standard. This ID combines a region with a storage class and is the smallest billable unit. The following query and analysis statement calculates the daily cost of each billing item for an OSS resource instance. Replace ${instanceId} with the actual 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

In the left-side navigation pane, choose Alerts to view all alerts of the current Cost Manager project. The following example configures an alert that is triggered 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.

    Configure the following query and analysis statement to query the total cost of an instance for the previous day. Bill data is synchronized on a T+1 basis, so you can set the query time range to Yesterday. Simple Log Service generates bill data once a day, so set the alert check frequency to a fixed interval of 1 day. Set the trigger condition to data matches the expression, and set the match condition to a cost value greater than 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 evaluation by group to No Grouping and Severity to Medium.

    In Query Statistics, select Advanced Settings. Set Type to LogStore, select aliyun_bill as the LogStore, and then click Confirm.

  3. After you configure the alert, you can view alert trigger records on the alert dashboard.