All Products
Search
Document Center

Simple Log Service:Use the new version of Cost Manager

Last Updated:May 28, 2024

The new version of Cost Manager stores data in Tablestore to ensure data accuracy and real-time performance. The new version of Cost Manager automatically updates full data every day. This topic describes how to use the new version of Cost Manager.

Entry point

  1. Log on to the Simple Log Service console.

  2. In the Log Application section, click the Business Analysis tab. Then, click Cost Manager.

  3. Click Custom Analysis.

Syntax description

Basic syntax

The dedicated Tablestore table of the new version of Cost Manager is associated with the dedicated Logstore of Cost Manager as an external table. You can query billing data only by using the external table.

  • Search statement: You can specify only an asterisk (*) before the vertical bar (|).

  • Analytic statement: The name of the external table is fixed as instance_bill. You must specify all query conditions in a WHERE clause. Example:

* | select xxx from instance_bill where xxx group by xxx limit xxx

The following query statement is executed to query the daily expenses of Simple Log Service:

* |
select
  date_trunc('day', __time__) as day,
  sum(PretaxAmount) as cost
FROM  instance_bill
where
  productcode = 'sls'
group by
  day

Example 1: Query aggregated data

The following query statement is executed to obtain the total expenses of Simple Log Service:

  • Query statement

    * |
    select
      sum(PretaxAmount) as cost
    FROM  instance_bill
    where
      productcode = 'sls'
  • Query and analysis resultsimage

Example 2: Query data by group

The following query statement is executed to obtain the expenses of each service:

  • Query statement

    * |
    select
      productcode,
      sum(PretaxAmount) as cost
    FROM  instance_bill
    group by
      productcode
  • Query and analysis resultsimage

Example 3: Perform comparative analysis

The following query statement is executed to compare the expenses of the current month with the expenses of the previous month:

  • Query statement

    * |
    SELECT
      diff [1] AS "Expenses of this month",
      diff [2] AS "Expenses of the previous month",
      diff [3] * 100 -100 as "Increased by (%)"
    FROM (
        SELECT
          compare(amount, 2592000) as diff
        FROM (
            SELECT
              sum(PretaxAmount) AS amount
            FROM instance_bill
          )
      )
  • Query and analysis resultsimage

Example 4: Analyze data by billable item in a service

The following query statement is executed to query the expenses and usage of each billable item in Simple Log Service:

  • Query statement

    * |
    SELECT
      BillingItem,
      sum(PretaxAmount) AS "Expense",
      sum(Usage) as "Usage"
    FROM  instance_bill
    where
      productcode = 'sls'
    GROUP by
      BillingItem
  • Query and analysis resultsimage

Example 5: Analyze data by instance in a service

The following query statement is executed to query the expenses of each instance in Simple Log Service:

  • Query statement

    * |
    SELECT
      InstanceID,
      sum(PretaxAmount) AS "Expense"
    FROM  instance_bill
    where
      productcode = 'sls'
    GROUP by
      InstanceID
  • Query and analysis resultsimage

Example 6: Use the JOIN clause and an external table to query data

The following query statement is executed to query billing data by joining the instance_bill table with a custom external table.

In this example, a custom external table named instance_name_table is used. The custom table is used to map the instanceName field to the data in the instance_bill table based on the instanceID field.

  • Query statement

    * | with t1 as (
      select
        InstanceID,
        sum(PretaxAmount) as PretaxAmount
      FROM    instance_bill
    ),
    t2 as (
      select
        InstanceID,
        InstanceName
      FROM    instance_name_table
    )
    select
      t1.InstanceID,
      t1.PretaxAmount,
      t2.InstanceName
    FROM  t1
      left join t2 on t1.InstanceID = t2.InstanceID

Fields in billing data

Field

Description

Example

BillingDate

The billing cycle.

2022-11-06

BillingItem

The billable item.

Number of requests, including PUT requests

BillingType

The billing method.

Others

CostUnit

The cost unit.

Not Allocated

Currency

The currency.

CNY

DeductedByCashCoupons

The fee that is offset by using coupons.

0.0

DeductedByCoupons

The fee that is offset by using vouchers.

0.0

DeductedByPrepaidCard

The fee that is offset by using stored-value cards.

0.0

DeductedByResourcePackage

The fee that is offset by using resource plans.

0

InstanceConfig

The configuration of the instance.

None

InstanceID

The ID of the instance.

me-east-1%3Bstandard

InstanceSpec

The specifications of the instance.

None

InternetIP

The public IP address.

None

IntranetIP

The internal IP address.

None

InvoiceDiscount

The discount amount.

0.001

Item

The type of the bill. Valid values:

  • SubscriptionOrder: a subscription bill

  • PayAsYouGoBill: a pay-as-you-go bill

  • Refund: a refund bill

  • Adjustment: an account adjustment bill

PayAsYouGoBill

ListPrice

The unit price.

1.020000

ListPriceUnit

The unit.

USD per 10,000 requests

NickName

The alias of the instance.

test

OutstandingAmount

The unsettled amount.

0.0

OwnerID

The ID of the account.

12***3212

PaymentAmount

The fee that is paid in cash.

0.0

PretaxAmount

The payable amount.

0.0

PretaxGrossAmount

The original price.

0.005

ProductCode

The service code.

oss

ProductDetail

The service details.

OSS

ProductName

The service name.

Object Storage Service

ProductType

The service type.

None

Region

The region.

China (Shanghai)

ResourceGroup

The resource group.

None

ServicePeriod

The validity period.

10800

SubscriptionType

The billing method. Valid values:

  • Subscription: the subscription billing method

  • PayAsYouGo: the pay-as-you-go billing method

PayAsYouGo

Tag

The tag.

None

Usage

The usage.

0.005000

UsageUnit

The usage unit.

10,000 requests

Zone

The zone.

cn-shanghai-b

What to do next

After a query succeeds, you can view the data in charts on dashboards based on the query and analysis results. For more information, see Create a dashboard.