UNPKG

@flarelabs-net/workers-observability-utils

Version:

A collection of Utilities for Capturing Logs and Metrics from Cloudflare Workers

42 lines (41 loc) 1.23 kB
import { type HistogramAggregates, type MetricPayload, type ExportedMetricPayload, MetricType, type Tags } from "./types"; interface BaseStoredMetric { name: string; tags: Tags; lastUpdated: number; } interface StoredCountMetric extends BaseStoredMetric { type: MetricType.COUNT; value: number; } interface StoredGaugeMetric extends BaseStoredMetric { type: MetricType.GAUGE; value: number; } interface StoredHistogramMetric extends BaseStoredMetric { type: MetricType.HISTOGRAM; value: number[]; percentiles?: number[]; aggregates?: HistogramAggregates[]; } type StoredMetric = StoredCountMetric | StoredGaugeMetric | StoredHistogramMetric; export declare class MetricsDb { private metrics; private getMetricKey; storeMetric(metric: ExportedMetricPayload): void; storeMetrics(metrics: (MetricPayload & { timestamp: number; })[]): void; /** * Get all stored metrics */ getAllMetrics(): StoredMetric[]; clearAll(): void; getMetricCount(): number; /** * Get the Metrics in a format ready to export to various different sinks * @param flushWindowS */ toMetricPayloads(): ExportedMetricPayload[]; } export {};