[null,null,["最后更新时间 (UTC):2025-08-04。"],[],[],null,["While [simple budget alert emails](/docs/projects/billing/avoid-surprise-bills)\nare a relatively easy way to receive billing updates, there may be times when\nyou want to create more sophisticated alerts that include more customized logic.\nHere are two approaches to consider:\n\n- Use Cloud Monitoring to create more sophisticated and timely alerts\n\n- Use a billing Pub/Sub notification along with a corresponding\n Cloud Function to create custom behavior in response to changes in your\n spending\n\nWhile both of these techniques require more work on your part, they give you the\npower to control exactly what kinds of alerts you're receiving and how to\nrespond to them.\n\nThis page offers an overview for each of these approaches.\n| All Firebase projects are actually Google Cloud projects behind the scenes, which means billing is shared across Firebase and Google Cloud and you can view the same project in both the Firebase console and the Google Cloud console.\n| When your project is on the Blaze pricing plan, [**set up budget alerts**](/docs/projects/billing/avoid-surprise-bills#set-up-budget-alert-emails) using the console. You can use the [Blaze plan calculator](/pricing#blaze-calculator) to estimate your monthly costs.\n|\n| Be aware that **budget alerts do *not* cap your usage or\n| charges** --- they are *alerts* about your costs so that you can\n| take action, if needed. For example, you might consider\n| [using\n| budget notifications to programmatically disable Cloud Billing on a\n| project](https://cloud.google.com/billing/docs/how-to/disable-billing-with-notifications).\n\nCreate more sophisticated alerts with Cloud Monitoring\n\nSimple budget alert emails let you know when your overall billing has reached\ncertain thresholds. However, you might also be interested in knowing whether\nindividual services are increasing unexpectedly --- before they've had a chance\nto significantly affect your budget. For more sophisticated use cases like this,\nwe recommend learning about Cloud Monitoring, which is a Google Cloud tool\navailable for your Firebase project.\n\nCloud Monitoring is useful for several different types of alerts:\n\n- If a resource that your project relies upon is unavailable (for both\n Firebase and Google Cloud services, but even for external services, like\n AWS)\n\n- If services like Cloud Functions are taking longer than expected to\n respond\n\n- If your Cloud Storage bucket, Realtime Database instance, or\n Cloud Firestore instance is rejecting too many requests (an indication that your\n Firebase Security Rules might be incorrect).\n\n- If the amount of resources used by some of your Firebase products\n have increased above a certain threshold\n\nAlerts created through Cloud Monitoring are usually sent more quickly than\nsimple budget alert emails, which are typically sent once per day. Alerts can\ntake the form of SMS messages, Slack channel messages, PagerDuty notifications,\nwebhooks, and more. These options enable you to send alerts with higher and more\nactionable levels of visibility.\n\nUsing Cloud Monitoring\n\nTo get started with Cloud Monitoring, we recommend starting with the\n[Metrics Explorer](//cloud.google.com/monitoring/charts/metrics-explorer),\nwhich allows you to create graphs of custom metrics within your\nFirebase/Google Cloud project and visualize their usage.\n\nSpecifically, you can look at resources such as your Cloud Firestore,\nRealtime Database, or Cloud Function instances. You can view usage information about\nthese products (like number of document reads, bytes sent, or function\ninvocations) that would have an effect on your billing.\n\nAfter you're comfortable visualizing your resource usage in the Metrics\nExplorer, we recommend creating an\n[alerting policy](//cloud.google.com/monitoring/alerts) on the\nmetrics you care about most. Here are some example alerting policies:\n\n- If the number of document reads in a 30-minute time period is greater than a\n particular value\n\n- If the usage of a specific resource (like a function invocation) seems to be\n increasing too quickly in a certain timeframe\n\nCreate additional billing logic\n\nBudget alerts send out emails automatically when your budget reaches certain\nthresholds, but for more sophisticated alerting or programmatic reactions to\nspending increases, you might consider setting up additional custom logic based\non Google Cloud Pub/Sub messages.\n\nFor example, you can send alerts to Slack channels or via text message, or you\nmake programmatic changes to your app or project depending on spend levels.\n\nPub/Sub is a message-passing service that allows other services to send\nmessages --- usually in the form of JSON data --- in an asynchronous manner\nthrough channels known as Pub/Sub topics. You can set up authorized\nservices, like Cloud Functions, to listen to messages in these topics and\nact on the data appropriately.\n\nNote that Pub/Sub notifications for billing are sent about once every\n20 minutes whether or not your billing usage has changed, and they are\nstateless (meaning that they provide no context as to what preceded them). If\nyou want to keep track of unusual increases in spending over time, or compare\nyour spending to the previous cycle, you will need to manage that historical\ndata yourself using a database like Cloud Firestore or the Realtime Database.\n\nUsing Pub/Sub topics with Cloud Functions\n\nYou can set up a Pub/Sub topic for your billing data by visiting the\nbudget associated with your Firebase project in the Google Cloud console (under\n*Billing* \\\u003e *Budgets and alerts* ), then clicking the checkbox for\n**Connect a Pub/Sub topic to this budget** . This will create a\nPub/Sub topic that you can listen to later. For detailed steps, refer to\nthe [full documentation](//cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications).\n\nAfter you've created your Pub/Sub billing topic, you can write a\nCloud Function to listen to this topic and act on the data accordingly. The\ndata is sent as JSON data and includes helpful information like the amount\nyou've spent so far, your budget amount, and the start date of your current\nbilling cycle.\n\nThe Google Cloud documentation has full details on how to receive this data\nusing a Cloud Function. However, if you're using Cloud Functions for Firebase to\ndeploy your functions, the general process is a little simpler (check out\nthe [Firebase documentation](/docs/functions/pubsub-events)).\nYou can also refer to [this video](//www.youtube.com/watch?v=NWrZwXK92IM)\nfor a sample walkthrough of the process.\n\nOnce you've received this data, there are a number of different ways you can\nrespond to it. Here are some options:\n\n- [Sending alerts to Slack channels](//cloud.google.com/billing/docs/how-to/notify#set_up_a_slack_channel_and_permissions),\n Discord channels, or sending text messages when your spending has reached a\n certain threshold.\n\n- Analyzing your spending compared to historical data and alerting you if\n anything seems out of the ordinary\n\n- [Making changes to your app via\n Remote Config](/docs/remote-config/automate-rc)\n if billing levels have gotten too high\n\n- Disabling your Firebase project entirely by\n [programmatically removing your billing service](//cloud.google.com/billing/docs/how-to/notify#cap_disable_billing_to_stop_usage)\n from your account"]]