Firestore Monitoring JS
This is a library which uses the Cloud Monitoring API v3 to view Firestore Metrics
Pre-requisites
- Service account with permission to access the API.
- Project must be billing enabled
- This might be more of a bug as requests that use the bearer token obtained from a service account results in a 403 error when the project is not billing enabled.
How to use
- Create a service account
- Download the service account credentials
- Pass the path to the service account in
FirestoreMonitoring
async function testApi() {
const firestoreMonitoring = new FirestoreMonitoring({
serviceAccountPath: "../service-account.json",
});
const readUsage = await firestoreMonitoring.getFirestoreReadCount(
"2023-07-22T08:00:00Z",
"2023-07-22T22:42:15Z"
);
console.log(JSON.stringify(readUsage));
}
testApi();
Output would look like:
{
"status": 200,
"statusText": "OK",
"data": [
{
"interval": {
"startTime": "2023-07-22T21:37:00Z",
"endTime": "2023-07-22T21:38:00Z"
},
"count": "48"
},
{
"interval": {
"startTime": "2023-07-22T21:36:00Z",
"endTime": "2023-07-22T21:37:00Z"
},
"count": "25"
},
{
"interval": {
"startTime": "2023-07-22T20:47:00Z",
"endTime": "2023-07-22T20:48:00Z"
},
"count": "28"
},
{
"interval": {
"startTime": "2023-07-22T08:15:00Z",
"endTime": "2023-07-22T08:16:00Z"
},
"count": "14"
}
]
}