Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
core
/
services
/
echo
/
backends
/
File Content:
PerformanceBackend.ts
import { EchoBackend, EchoEvent, EchoEventType } from '@grafana/runtime'; import { backendSrv } from '../../backend_srv'; export interface PerformanceEventPayload { name: string; value: number; } export interface PerformanceEvent extends EchoEvent<EchoEventType.Performance, PerformanceEventPayload> {} export interface PerformanceBackendOptions { url?: string; } /** * Echo's performance metrics consumer * Reports performance metrics to given url (TODO) */ export class PerformanceBackend implements EchoBackend<PerformanceEvent, PerformanceBackendOptions> { private buffer: PerformanceEventPayload[] = []; supportedEvents = [EchoEventType.Performance]; constructor(public options: PerformanceBackendOptions) {} addEvent = (e: EchoEvent) => { this.buffer.push(e.payload); }; flush = () => { if (this.buffer.length === 0) { return; } backendSrv .post( '/api/frontend-metrics', { events: this.buffer, }, { showErrorAlert: false } ) .catch(() => { // Just swallow this error - it's non-critical }); this.buffer = []; }; }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
analytics
---
0755
grafana-javascript-agent
---
0755
PerformanceBackend.ts
1154 bytes
0644
N4ST4R_ID | Naxtarrr