import { type Server } from "node:http"; import { type S3Client } from "@aws-sdk/client-s3"; import { type BackupConfig } from "./config.js"; /** * `backupdrill exporter`:按 Prometheus 文本格式暴露桶里备份与演练的状态。 * 规矩照 https://prometheus.io/docs/instrumenting/writing_exporters/ : * - 每次抓取现读桶,不按自己的定时器预取,不报旧值; * - 读不了桶时照样回 200,backupdrill_up 为 0,其余业务指标不出(半套数据比没有更误导); * - 指标不带标签(一个 exporter 进程只看一个项目,项目名属于 Prometheus 那边的 target 标签), * 连接串、key、桶名一律不进指标。 */ /** 10059:Prometheus wiki「Default port allocations」上 10058 之后的第一个空位(2026-10-20 查)。 */ export declare const DEFAULT_EXPORTER_PORT = 10059; /** 最新一份完整快照里 exporter 要用的数,不留整份 manifest(Storage 文件多时 manifest 很大) */ export interface SnapshotSummary { createdAt: number; dumpBytes: number; storageFiles: number; storageBytes: number; tables: number; estimatedRows: number; } export interface BucketState { /** // 下的快照目录数,含没写完 manifest 的 */ snapshots: number; /** 最新一份有 manifest.json 的快照;一份都没有时为 null */ latest: SnapshotSummary | null; /** 最近一次记下的演练(drill --record);没有时为 null */ lastDrill: { finishedAt: number; pass: boolean; } | null; /** 最近一次通过的演练;restoreSeconds 来自它的记录内容 */ lastPassedDrill: { finishedAt: number; restoreSeconds?: number; } | null; } /** * 读桶的函数。每次调用都现读;唯一记住的是最新一份 manifest 的 ETag 和摘要: * 下次带 If-None-Match 去问,没变就是 304、不传正文。快照写完就不再改,而一份 manifest 列着 * 每个 Storage 文件,可能有几十 MB,每 30 秒整份下载一遍会变成用户账单上的流量。 */ export declare function createBucketReader(s3: S3Client, config: BackupConfig): (abortSignal: AbortSignal) => Promise; /** state 为 null = 这次没读成桶。全部是 gauge:都是"某一刻的状态",没有一个会只增不减。 */ export declare function renderMetrics(state: BucketState | null, scrapeSeconds: number): string; /** * 读桶的时限跟着 Prometheus 走:它在请求头里告诉我们这次抓取最多等多久,留半秒余量, * 好让超时的这次还能回一个 up=0,而不是被 Prometheus 当成 exporter 挂了。 */ export declare function scrapeTimeoutMs(header: string | string[] | undefined): number; export declare function createExporterServer(read: (abortSignal: AbortSignal) => Promise): Server; /** CLI 的 `backupdrill exporter`:起 HTTP 服务,直到进程被停掉。 */ export declare function startExporter(config: BackupConfig, opts: { host: string; port: number; }): Promise;