Custom bill alert cases
Prerequisite for use
Cost Manager is activated.
Create Alert Monitoring Rule
The alerting feature of Simple Log Service is an end-to-end intelligent O&M system that can monitor alerts based on alert rules, reduce alert noises, manage events, and send alert notifications. You can use the alerting feature to monitor the resource usage of Simple Log Service in real time. Cost Manager is integrated with the alerting feature, which allows you to access Alert Center in an efficient manner. To create a custom alert, click Create Alert on the Alert Rules tab of the Alert Center page.
In addition, you can go to the Custom Analysis page and configure the query statement that you want to execute as an alert. To perform this operation, enter the query statement, select Yesterday as the query time range, and then click the Save as Alert icon to configure an alert. 
You can select Yesterday as the query time range of the query statement because billing data is synchronized on a T+1 basis. Bills of many cloud services are generated by day. Therefore, you must set the alert check frequency to a fixed interval of one day. The following section provides common sample alerts for fees and usage for reference.
Configure an alert for the total fee of the previous day
To configure an alert for the total fee of the previous day, you can use the following query statement. Select Yesterday as the query time range. When you configure the alert rule, set the Trigger Condition parameter to data matches the expression, and set the expression to "cost">Alert threshold.
* | select
sum(PretaxAmount) as cost
FROM instance_billConfigure an alert for the total fee of a single cloud service of the previous day
To configure an alert for the total fee of a single cloud service of the previous day, you can use the following query statement and set the ProductCode parameter to the code of the cloud service that you want to monitor. Select Yesterday as the query time range. When you configure the alert rule, set the Trigger Condition parameter to data matches the expression, and set the expression to "cost">Alert threshold.
* | select
sum(PretaxAmount) as cost
FROM instance_bill
where
ProductCode = '${ProductCode}'Configure an alert for the total resource usage of the previous day
To configure an alert for the total resource usage of the previous day, you can use the following query statement, set the ProductCode parameter to the code of the cloud service that you want to monitor, and set the BillingItem parameter to the billable item that you want to monitor. In this example, a storage usage alert of Simple Log Service is used. Select Yesterday as the query time range. When you configure the alert rule, set the Trigger Condition parameter to data matches the expression, and set the expression to "cost">Alert threshold.
* | select
sum(Usage) as Usage
FROM instance_bill
where
ProductCode = 'sls'
and BillingItem like '%Storage%'Configure an alert for the resource usage of an instance
To configure an alert for the resource usage of an instance, you can use the following query statement, set the ProductCode parameter to the code of the cloud service that you want to monitor, set the BillingItem parameter to the billable item that you want to monitor, and set the InstanceId parameter to the cloud service instance that you want to monitor. In this example, a storage usage alert of a project of Simple Log Service is used. Select Yesterday as the query time range. When you configure the alert rule, set the Trigger Condition parameter to data matches the expression, and set the expression to "cost">Alert threshold.
* | select
sum(Usage) as Usage
FROM instance_bill
where
ProductCode = 'sls'
and BillingItem like '%Storage%'
and InstanceId like '%project%'Configure a fee comparison alert
To configure a fee comparison alert, you can use the following query statement. Select Yesterday as the query time range. When you configure the alert rule, set the Trigger Condition parameter to data matches the expression, and set the expression to "Increased by">Alert threshold.
* |
SELECT
diff [1] AS "Fees of the previous day",
diff [2] AS "Fees of the day before yesterday",
diff [3] * 100 -100 as "Increased by"
FROM (
SELECT
compare(amount, 86400) as diff
FROM (
SELECT
sum(PretaxAmount) AS amount
FROM instance_bill
)
)