Monitor Database Usage

Both the Usage tab in the Firebase console and the metrics available through Stackdriver Monitoring can help you estimate your billed Realtime Database usage. Keep in mind, however, that the usage statistics available in the Firebase console and through Stackdriver are estimates only. See Understand Realtime Database billing for more information about billing.

Firebase console

To see your current Realtime Database usage and estimate your bill, check the Usage tab in the Firebase console. You can check usage over the current billing period, the last 30 days, or the last 24 hours.

Firebase shows usage statistics for the following metrics:

  • Connections: The number of simultaneous, currently open, realtime connections to your database. This includes the following realtime connections: WebSocket, long polling, and HTML server-sent events. It does not include RESTful requests.
  • Storage: How much data is stored in your database. This doesn't include Firebase hosting or data stored through other Firebase products.
  • Downloads: All bytes downloaded from your database, including protocol and encryption overhead.
  • Load: This graph shows how much of your database is in use, processing requests, over a given 1-minute interval. You might see performance issues as your database approaches 100%.

The Realtime Database usage dashboard in the Firebase console.

Stackdriver Monitoring

Usage metrics

To use Stackdriver Monitoring to monitor your billed usage, track the following metrics. Note all metric type names are prefixed with firebasedatabase.googleapis.com/.

Metric Name Description
Sent Payload Byte Count

network/sent_payload_bytes_count. This metric reflects the size of the data requested through database operations (including gets, queries, writes, realtime listener updates, and broadcasts). It does not include any connection overhead (protocol or encryption). The `sent_payload_bytes_count` contributes to your outgoing bandwidth costs, but it doesn't account for the total billed costs. It's an estimate of the data sent from your database in response to requests, but, since it measures the payload size of the data requested, not the data actually sent, it may not always be accurate.

Sent Payload and Protocol Bytes Count

network/sent_payload_and_protocol_bytes_count. This metric reflects the size of both the payload data described above and the protocol overhead necessitated by the connection (for example, HTTP headers, WebSocket frames, and Firebase realtime protocol frames). It doesn't account for encryption costs on secure connections.

Sent Bytes Count network/sent_bytes_count. This metric reflects an estimate of the total size of data sent out from your database through reads. It includes the payload data that is actually sent to clients, in addition to the protocol and encryption overhead that results in connection costs. This most accurately reflects the total outgoing bandwidth on your Realtime Database bill.
Total Bytes

storage/total_bytes. Use this metric to monitor how much data you're storing in your database. Data you store in Realtime Database contributes to your billing costs.

Combine metrics in charts on your dashboard for helpful insights and overviews. For example, try the following combinations:

  • Outgoing data: Use the network/sent_bytes_count, network/sent_payload_and_protocol_bytes_count, and network/sent_payload_bytes_count metrics to spot potential issues with protocol or encryption overhead contributing to unexpected costs on your bill. If you see a large discrepancy between the size of the data payloads requested and the other metrics reflecting connection overhead, you might want to troubleshoot issues that might be leading to timeouts or frequent connections. If you're not using TLS session tickets, you might try implementing them to reduce SSL connection overhead for resumed connections.
  • Operations: Use the io/database_load metric to see how much of your total database load is used by each operation type. Make sure to group io/database_load by type to troubleshoot different operation types.
  • Storage: Use the storage/limit and storage/total_bytes to monitor your storage utilization in relation to the Realtime Database storage limits.

See the full list of Realtime Database metrics available through Stackdriver Monitoring.

Create a Stackdriver workspace

To monitor Realtime Database with Stackdriver Monitoring, you must set up a Stackdriver workspace for your project. A workspace organizes monitoring information from one or more projects. After setting up a workspace, you can create custom dashboards and alerting policies.

Skip these steps if your project is already part of a workspace.

  1. Create a Workspace from the Stackdriver Console

    Enter your GCP project ID and click Create workspace.

  2. Optionally, select additional projects to monitor in the same workspace. Click Continue.

  3. Skip the steps to Add AWS accounts and Install Stackdriver agents. These steps are not required to monitor Realtime Database. Click Continue.

  4. Configure your preference for email reports. Click Continue.

  5. Click Launch Monitoring.

Create a dashboard and add a chart

Display the Realtime Database metrics collected from Stackdriver Monitoring in your own charts and dashboards.

Before you proceed, make sure your project is part of a Stackdriver workspace.

  1. In the Stackdriver Console, open your workspace and go to Dashboards > Create dashboard.

    Go to the Create Dashboard page

  2. In the upper-right hand corner, click Add Chart.

  3. In the Add Chart window, click the Metric tab.

  4. In the Find resource type and metric field, enter Firebase Realtime Database. From the auto-populated dropdown, select one of the Realtime Database metrics..

  5. To add more metrics to the same chart, click Add Metric and repeat the previous step.

  6. Optionally, tailor your chart as needed. For example, in the Filter field, click + Add a filter. Scroll down, then select a value or range for the metric of interest you wish to filter the chart on.

  7. Click Save.

For more on Stackdriver Monitoring charts, see Working with charts.

Create an alerting policy

You can create an alerting policy based on the Realtime Database metrics. Follow the steps below can create an alerting policy that emails you whenever a specific Realtime Database metric meets a certain threshold.

Before you proceed, make sure your project is part of a Stackdriver workspace.

  1. In the Stackdriver Console, open your workspace and go to Alerting > Create a Policy.

    Go to the Create New Alerting Policy page

  2. Add an alerting condition based on one of the Realtime Database metrics. Click Add Condition.

  3. Select a Target. In the Find resource type and metric field, enter Realtime Database. From the auto-populated dropdown, select one of the Realtime Database metrics.

  4. Under Configuration, use the dropdown fields to define your alerting condition.

  5. Click Save.

  6. Add a notification channel to your alerting policy. Under Notifications, select Email from the Notification Channel Type.

  7. Enter your email in the Email address field. Click Add Notification Channel.

  8. Optionally, fill out the documentation field to include additional information in your email notification.

  9. Under Name this policy, enter a name for your alerting policy.

  10. Click Save.

If your Realtime Database usage exceeds the configured threshold, you will receive an email alert.

For more on alerting policies, see Introduction to alerting.

What's next