Firebase Firestore: How to monitor read document count by collection? - firebase

I'm monitoring document read count in Firebase Console > Firestore > Usage section.
However, I want to find a way to see document read count by collection so that I can know which query to optimize.
Is there anyway for that?
I looked into GCP monitoring but I couldn't achieve what I want to do here.
I read documents from js SDK and nodejs Admin SDK

Firestore provides no accounting other than a total running read count for the entire database for the last 30 days. If you need something more specific, you'll have to record it yourself somehow.

Related

Extremely high READ hits on website using Firebase Firestore

I have more than 52k hits on my small project which is using NextJS with Firebase 9.
I don't know what the problem is because the data I am using is very limited and I have only two snapshot listener and one Authentication feature. But somehow in just two days Firestore quota has exceeded and there are more than 52k READ hits.
I don't know why that happened because there are no memory leaks and I am also closing the API listeners which come attached with Firebase.
I am providing github link in case anyone wants to take a look https://github.com/jainChetan81/Todo-List
Attached screenshot of Firebase console:
Use of the Firebase console will incur reads. If you leave the console open on a collection or document with busy write activity then the Firebase console will automatically read the changes that update the console's display. Most of the time this is the reason for unexpected high reads. You can go through this answer. Also, currently there are no tools to trace the reads in Firestore. So to limit the Firestore database reads you have to configure security rules.
So, I would suggest you check your Firestore rules. And if not, it is better to contact Firebase Support as this kind of issue needs visibility into your project and they will have access to it.
I am having the same problem as you with my React app. The solution is to use the useEffect hook and call the function that requests for firestore collection;
useEffect(()=> {
getPosts();
}, []);

how to check firebase cloud firestore size in a project?

how to check firebase cloud firestore size in a project?
according to firebase the free plan gives you 1GB for firebase cloud firestore, i already create some collections with documents inside, but where can i check the total size i am using?
i already check some statistics in firebase console but i can only see the numbers of reads and writes.
You can check your Cloud Firestore size or Cloud Firestore stored data in Google Cloud App Engine Quotas page. You can go direct to Google Cloud using the link because when you create a Firebase project, you're also creating a project in the Google Cloud.
Inside the App Engine Quotas page you can see also the other Cloud Firestore usage information including reads, writes, index writes, deletes, and network egress.
Example images:
UPDATE:
You can check your usage up to last 30 days in Firestore Database > Usage
Go to the Firestore Usage tab
Click "View in Usage and Billing" (bottom right)
This will show a summary of usage including total bytes stored, bandwidth, reads, writes, and deletes.
The answer is you can’t check the usage of bytes stored per month in Firestore. Only per day.
Usage per day can be checked in the app engine
It’s confusing because you don’t know how much data you have stored in total in Firestore.

How can I analyse which collections get the most reads?

I am getting an unusually high amount of reads on my Firebase app and I would like to know precisely where they occur. For example, in which collection, in which document in a collection. If it is a listener that's adding up reads or simple reads.
There are currently no tools to audit Firestore access. You will have to log access from your application code and collect those somewhere for you to analyze.
Realtime updates from the Firestore console is often a source of unexpected reads.

Discrepency in Number of writes in Firebase console and Google cloud console Quota pages

Last couple of weeks, I have been Observing difference between number of writes in Firebase console Firestore Usage tab and Google cloud console Quota page.
Before that, The count fairly used to sync.
Number of writes in Firebase Firestore console usage tab: 9.2K
Number of writes in Google Cloud Console page, Quotas Page: 19307
Which is approximately double the number of writes in Firebase Firestore Usage Tab. Are there any Internal writes happening which google doesn't report?
Firebase Console Firestore Usage Tab Page
Google cloud Console Quotas page
I have attached the screenshots for the same.
Can anyone clear My Query. Is this a valid Scenario?
Note: I Don't have any other project linked to the platform.
From your first screenshot you can see at the top left written on the graph “Does not include Imports/exports and may not match billing and quota usage”. Moreover, Google public documentation states that the Firebase console includes a usage dashboard that shows Cloud Firestore reads, writes, deletes and other metrics over time.
As a result of how the dashboard computes usage, the numbers reported can differ from billing reports. The billing reports are the final usage numbers.
The usage dashboard does not include reads and writes from managed import and export operations.
So,I have to answer my question.
I've found out the root cause. Firestore FieldValue atomic operations causing the double writes.
This double writes happening with any SDK version even in Cloud functions Admin SDK.
I've skipped the use of atomic operations using FieldValue. All Fine now.
Firebase Support Investigating the Issue. Will update When I Got more Info from them.
Edit:2
Response from Firebase support:
"The two writes come from: 1) the initial write and 2) the transformation. This is not a bug, and what is shown in the Cloud console is correct. We do have an internal ticket now to make sure the Firebase console syncs up this information better, as well, so hopefully that'll help."
That means Fieldvalue functions to increment and array Union, servertimestamp will cause two writes and I also found that they are causing extra reads as well. I feel Firebase should reconsider their decision of not considering it as bug or atleast restructure this Atomic Operation. Let's Wait and See.

Firestore Pricing - Does The CRUD In Firebase Console Matter?

I am understand that we have been charges for every read, write and delete operation, but my question are these operation also being counted in the firebase console?
Sometimes, we just wanna see the data through firebase console, and when click at the collection, it will automatically display the documents data and also sub-collection of the documents. Are we gonna get charged through activity in console too?
Are these operation also being counted in the firebase console?
Yes, all read, write or delete operations performed even from the cosole are counted.
Are we gonna get charged through activity in console too?
Yes.

Resources