UNPKG

firestore-metrics

Version:

A library which uses the Cloud Monitoring API v3 to view Firestore metrics.

141 lines (140 loc) 6.59 kB
import { GoogleAuthOptions } from "google-auth-library"; export interface Interval { startTime: string; endTime: string; } export interface TimeIntervalMetric { interval: Interval; count: number; [key: string]: any; } export type DateTimeStringISO = `${number}-${number}-${number}T${number}:${number}:${number}Z`; interface FirestoreMetricsArgs extends Omit<GoogleAuthOptions, "scopes"> { } export declare class FirestoreMetrics { projectId: string | null; private accessToken; private googleAuth; private googleAuthArgs; private baseUrl; private scopes; constructor(params: FirestoreMetricsArgs); /** * Helper function to compose the metric type filter. * @param {string} metricName Name of the metric type. * @returns {string} A string filter to be passed to the request. */ private metricFilter; /** * Creates a Google Auth instance if null. */ private createGoogleAuthInstance; /** * Gets the project ID and sets its value if it is still null. */ getProjectId(): Promise<string>; /** * Generates an access token. * @param {boolean} overwriteExisting If true, overwrites the existing access token. * @returns {Promise<string>} Access token used to authenticate requests. */ generateToken(overwriteExisting?: boolean): Promise<string>; /** * Sets the access token. * @param {boolean} accessToken Value of the new access token. */ setAccessToken(accessToken: string): void; /** * Makes a request to the Cloud monitoring API. * @param {string} filter A monitoring filter that specifies which time series should be returned. * @param {string} startTime The beginning of the time interval. * @param {string} endTime The end of the time interval. * @returns */ private makeRequest; /** * Check if the list contains an the object. * @param obj Object. * @param list List of objects. * @returns True if the list contains the object. */ private containsObject; /** * Removes keys in an object with null, undefined, etc. value. * @param obj Object. * @param args Additional values to be removes. * @returns An object with keys with invalid values removed. */ private cleanObject; /** * Cleans/formats the response into something more understandable. * @param {Response} response Fetch response. * @returns {Promise<Array<TimeIntervalMetric>>} An array of time intervals and count of transactions for that time. */ private cleanResponseTimeSeries; /** * Get Firestore read count metrics. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getReadCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore write count metrics. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getWriteCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore delete count metrics. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getDeleteCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore snapshot listeners count metrics. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getSnapshotListeners(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore active connections count metrics. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getActiveConnections(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore documents deleted by TTL services count. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getTTLDeletionCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore Security Rule evaluations count performed in response to write read requests. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getRulesEvaluationCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; /** * Get Firestore API calls count. * @param {DateTimeStringISO} startTime The beginning of the time interval. * @param {DateTimeStringISO} endTime The end of the time interval. * @param {string?} accessToken Access token used to authenticate. * @returns {Promise<Array<TimeIntervalMetric>>} */ getRequestCount(startTime: DateTimeStringISO, endTime: DateTimeStringISO, accessToken?: string | null): Promise<Array<TimeIntervalMetric>>; } export {};