This page covers creating and silencing Billing alerts and alert rules.

## Before you begin

Before continuing, ensure you have the following required role:

- **MonitoringRule PA Creator** : create and manage `MonitoringRule` custom resources. Ask your IAM Org Admin to grant you the `monitoringrule-pa-creator` role.

## Create alert rules

You can create alert rules based on invoice metrics and your spend thresholds
using the [`MonitoringRule`](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/apis/service/monitoring/v1/monitoring-v1.md.txt#monitoringrule)
resource in the [Observability API](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/apis/service/observability/observability-api-overview.md.txt). See [Create alert rules](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/platform/pa-user/create-alert-rules.md.txt#define-alert-rules) for more information about defining `MonitoringRule` custom resources.

To create an alert rule, work through the following steps:

1. Create a YAML file, and add in the `MonitoringRule` resource and the
   following contents:

   ```yaml
   apiVersion: monitoring.gdc.goog/v1
   kind: MonitoringRule
   metadata:
     name: MONITORING_RULE_NAME
     namespace: platform-obs
   spec:
     interval: INTERVAL
     limit: LIMIT
     alertRules:
     - alert: ALERT
       expr: EXPRESSION
       labels:
         severity: SEVERITY
         code: BILLING_CODE
         resource: BILLING
       annotations:
         message: MESSAGE
   ```

   Replace the following variables:

   | Variable | Description |
   |---|---|
   | <var translate="no">MONITORING_RULE_NAME</var> | The name of the monitoring rule. For example: `invoice-total-cost`. |
   | <var translate="no">INTERVAL</var> | The length of time the alert re-runs in a given period. For example: `60s` defines that the alert runs every sixty seconds. |
   | <var translate="no">LIMIT</var> | The amount of times an alert can run. For example: `0` for no limit. |
   | <var translate="no">ALERT</var> | The alert name. For example: `invoice_total_cost_approaching_limit`. |
   | <var translate="no">EXPRESSION</var> | The PromQL expression to describe the alert rule. To retrieve a PromQL expression, see [View and filter open alerts](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/platform/pa-user/query-and-view-alerts.md.txt#view-and-filter-alerts). For example, to set an alert rule with a spend threshold at 80% of your $500,000 budgeted amount, use the following expression: `sum(billing_total_cost{account_id="platform/BILLING_ACCOUNT_NAME"}) / 500000 > 0.8` Replace <var translate="no">BILLING_ACCOUNT_NAME</var> with your billing account name. |
   | <var translate="no">SEVERITY</var> | The severity of the alert rule. Severity values include `error`, `critical`, `warning`, and `info`. |
   | <var translate="no">BILLING_CODE</var> | The billing code you define for the alert rule. For example: `"BILLING-100"`. |
   | <var translate="no">MESSAGE</var> | A description of the alert that appears when the alert rule runs. For example: `"Spending exceeded limit"`. |

2. Apply the contents of the YAML file and set the alert rule:

   ```bash
   kubectl apply -f FILENAME.yaml --kubeconfig=MANAGEMENT_API_SERVER -n platform-obs
   ```

   Replace the following:
   - <var translate="no">FILENAME</var>: the name of the YAML file that defines the `MonitoringRule` resource.
   - <var translate="no">MANAGEMENT_API_SERVER</var>: the path to the management API server kubeconfig file.
3. Verify that the alert rule exists:

   ```bash
   kubectl get monitoringrule -n platform-obs --kubeconfig=MANAGEMENT_API_SERVER
   ```

   The output is similar to the following:

       NAME                 AGE
       invoice-total-cost   10s

## Create spend threshold alerts

Your Infrastructure Operator (IO) creates spend threshold alert policies in
the GDC console. Spend threshold alerts are custom billing alerts that indicate
when the billing costs exceed the threshold you set. For example, your IO creates billing
total cost alerts and configures the alerts based on a fixed dollar amount, or as
a percentage of the initial budgeted amount.

To create spend threshold alerts and other organization-level billing alerts,
submit a request to your IO. Include the following parameters in your request:

- Billing account ID.
- The total budget amount for the specified billing account.
- The budget threshold.

## Silence alerts

You can silence and unsilence alert rules through the GDC console.
Follow the instructions in [Silence an alert](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/platform/pa-user/manage-alerts-and-policies.md.txt#silence-an-alert).

## Configure billing notifications

To configure billing notifications, follow the instructions in
[Configure notification channels](https://docs.cloud.google.com/distributed-cloud/hosted/docs/1.16/gdcag/platform/pa-user/configure-notification-channels.md.txt).