export type GetApiMetricsArgs = {anonymize?: boolean | undefined, per_collection?: boolean | undefined, timeout?: number | undefined}; export type GetApiMetricsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Collect Prometheus metrics data * * GET /metrics * * Also accepts auth: bearerAuth */ export const getApiMetrics = async (args: GetApiMetricsArgs, options?: GetApiMetricsOptions) => { const {baseUrl = "http://localhost:6333", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.anonymize != null) query.append("anonymize", String(args.anonymize)) if (args.per_collection != null) query.append("per_collection", String(args.per_collection)) if (args.timeout != null) query.append("timeout", String(args.timeout)) if (apiKey !== undefined) headers.set("api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/metrics${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };