Analyze Simple Log Service (SLS) bills with the Bill Self-service Analysis report and configure storage usage alerts.
SLS billing data concepts
Billing data records resource usage per instance and billing item. Run the following query to view your SLS bill details:
* |
select
BillingDate,
BillingItem,
BillingType,
CostUnit,
Currency,
DeductedByCashCoupons,
DeductedByCoupons,
DeductedByPrepaidCard,
DeductedByResourcePackage,
InstanceConfig,
InstanceID,
InstanceSpec,
InvoiceDiscount,
Item,
ListPrice,
ListPriceUnit,
NickName,
OutstandingAmount,
OwnerID,
PaymentAmount,
PretaxAmount,
PretaxGrossAmount,
ProductCode,
ProductDetail,
ProductName,
ProductType,
Region,
ResourceGroup,
ServicePeriod,
SubscriptionType,
Tag,
Usage,
UsageUnit,
Zone
from
instance_bill
Run this query in the SQL editor on the Custom Analysis page of Cost Manager to view your detailed billing data.
The following table describes the instance and billing item fields.
|
Parameter |
Field |
Description |
Example |
|
instance |
InstanceID |
The smallest resource unit of a cloud service. For Simple Log Service, a Logstore is the smallest resource unit. The InstanceID is in the format: |
12345;test-project;test-Logstore;cn-guangzhou |
|
billing item |
BillingItem |
A billing item for Simple Log Service, such as storage space or index traffic. |
index traffic |
Log Service Bill Self-service Analysis report
In Cost Manager, open the Simple Log Service Bill Self-service Analysis report to view cost and usage trends. Filter by Project, Logstore, Region, or OwnerId to analyze a single instance.
The report includes Top Project Usage Details and Top Logstore Usage Details, which show costs and usage at the Project and Logstore level.
The table displays metrics including Region, Project, Cost (CNY), Month-over-Month Change (%), Resource Package Deduction, and usage for hot storage, Infrequent Access storage, and archive storage. By default, it shows data from the previous day.
The Top Logstore Usage Details table includes columns such as Cost (CNY), Month-over-Month Change (%), Resource Package Deduction, Storage - Hot Storage (GB), and Storage - Infrequent Access Storage (GB).
SLS bill usage analysis
Example 1: Yesterday's expenses
To view your expenses from the previous day:
-
Open the Log Service Bill Self-service Analysis report and find the Yesterday's Expenses chart.
-
Hover over the
icon in the upper-right corner of the chart and click Preview Query Statement to view the query.Query statement:
(*) | select t, cost as "Yesterday's Expenses", (cost - lag(cost, 1, 0) over()) / lag(cost, 1, 0) over() * 100 as "Day-over-Day Change (%)" FROM ( select sum(PretaxAmount) as cost, date_format(__time__, '%Y-%m-%d') as t FROM instance_bill where ( productcode = 'sls' or productcode = 'slsingest' ) and split_part(InstanceID, ';', 3) like '%%' and split_part(InstanceID, ';', 2) like '%%' and split_part(InstanceID, ';', 4) like '%%' and OwnerId like '%%' group by t order by t asc ) limit 1000 -
To customize the query, click Search & Analysis to go to the corresponding Project in Cost Manager.
In the SQL editor, the query uses the
lagwindow function to analyze billing data from theinstance_billtable where theproductcodeisslsorslsingest. It calculates the previous day's expenses and the day-over-day percentage change. Click Search & Analysis. The result table contains three columns: t (date), Yesterday's Expenses, and Day-over-Day Change (%).
Example 2: Usage trends for SLS billing items
The following query tracks usage trends for each SLS billing item.
* |
select
date_trunc('day', __time__) as t,
BillingItem,
round(sum(Usage), 2) as "Usage"
from instance_bill
where ProductCode='sls'
group by BillingItem, t
In the left-side navigation pane of Cost Manager, click Custom Analysis. In the query editor for the aliyun_bill Logstore, enter the preceding SQL query and click Search & Analysis. The Statistics Chart tab displays the daily aggregated usage for each billing item.
Example 3: Detailed usage for Project and Logstore
Use the following query to get detailed usage of each Project and Logstore. Replace ${project_name} with your actual Project name.
* | select
split_part(instanceId, ';', 2) as project,
split_part(instanceId, ';', 3) as logstore,
split_part(instanceId, ';', 4) as region,
BillingItem as "Billing Item",
round(sum(Usage), 2) as "Usage"
FROM instance_bill
where
ProductCode = 'sls'
and split_part(instanceId, ';', 2) like '${project_name}'
group by
BillingItem,
project,
logstore,
region
In the left-side navigation pane of Cost Manager, click Custom Analysis. Select the aliyun_bill Logstore, paste the preceding SQL query into the editor, and click Search & Analysis. The Statistics Chart tab displays the detailed usage results broken down by project, logstore, and region.
SLS storage usage alert
Configure alerts to monitor usage and control costs.
-
In the left-side navigation pane, click Alerts. On the Alert Center page, click Create Alert.
-
On the Create Alert page, configure the Check Frequency, Query Statistics, and Trigger Condition. For other parameters, see Configuration Description.
Configure the following query to check storage space usage. Because billing data is synchronized on a T+1 basis, set the query time range to Yesterday. Since SLS bills are generated daily, set the check frequency to 1 day. Set the trigger condition to data matches the expression and configure the expression to trigger an alert when storage usage exceeds your threshold, such as 400.
* | select round(sum(Usage), 2) as "Storage Usage" from instance_bill where ProductCode='sls' and BillingItem like '%storage space%'For Group Evaluation, select Ungrouped. Set the severity level of the trigger condition to Medium.
In the advanced settings for Query Statistics, set Type to Logstore, enter
aliyun_billin the Logstore field, and set Dedicated SQL to Off. After you complete the configuration, click Confirm. -
After the alert is configured, you can view its trigger history in the alert dashboard. For more information, see Step 4: View alert trigger records.