///
import { Instance } from "../instance";
import { CircuitBreakerPlugin, WeightAdjusterPlugin, StatReporterPlugin } from "../plugins";
import { Health } from "./health";
import { LocalRegistry } from "../registry";
import { Logger } from "../logging";
export interface StatProp {
/**
* 总调用量,其值可为 0
*/
count: number;
/**
* 总耗时,其值可为 0
*/
cost: number;
}
export declare type InstanceStat = Record<"success" | "error", StatProp>;
export interface ComputedStat {
/**
* 统计周期
*/
statWindow: number;
/**
* 汇总统计值
*/
summaryStat: Map;
}
/**
* 采用滑动窗口,分桶方式进行
*/
interface BucketStat extends InstanceStat {
/**
* 所在统计周期
*/
period: number;
}
declare const kDefaultOptions: {
/**
* 统计周期
*
* 与统计单元数,共同确定了统计数据的计算间隔(监控子的系统最小分辨率)
*/
statWindow: number;
/**
* 统计单元数
*
* 与统计周期,共同确定了统计数据的计算间隔(监控子的系统最小分辨率)
*/
bucketsCount: number;
/**
* 是否开启动态权重
*
* 仅 `InternalMonitor` 有效
*/
enableDynamicWeights: boolean;
/**
* 节点熔断插件开启状态
*
* 仅 `InternalMonitor` 有效
*/
breakerSwitch: {
/**
* 实时熔断是否开启
*/
realtime: boolean;
/**
* 周期熔断是否开启
*/
period: boolean;
};
};
export declare type MonitorOptions = typeof kDefaultOptions;
/** 统计要求 */
declare const enum StatisticalBitfield {
/** 不做任何统计 */
None = 0,
/** 统计全量数据 */
Full = 1,
/** 仅统计存活数据,实例状态不为 `Fused` */
Alive = 2
}
declare class StatStore {
store: Partial>>>>;
get(namespace: string, service: string): Map;
}
export declare abstract class Monitor {
protected currentPeriod: number;
protected timer: NodeJS.Timeout | undefined;
protected disposed: boolean;
protected fullStat?: StatStore;
protected aliveStat?: StatStore;
protected abstract options: MonitorOptions;
constructor(requisite?: StatisticalBitfield);
dispose(): void;
update(namespace: string, service: string, instance: Instance, success: boolean, cost: number, code?: string): void;
private performUpdate;
protected abstract compute(): void;
}
export declare class InternalMonitor extends Monitor {
protected options: MonitorOptions;
private readonly health;
private readonly logger;
private readonly registry;
private readonly breaker?;
private readonly adjusters;
private readonly reporters;
constructor(logger: Logger, health: Health, registry: LocalRegistry, adjusters: WeightAdjusterPlugin[], reporters: StatReporterPlugin[], breaker?: CircuitBreakerPlugin, options?: Partial);
update(namespace: string, service: string, instance: Instance, success: boolean, cost: number, code?: string): void;
protected performCompute({ store }: StatStore, handle: (namespace: string, service: string, computed: ComputedStat) => void): void;
protected compute(): void;
private performFullStat;
private performAliveStat;
}
export declare class ExternalMonitor extends Monitor {
protected options: MonitorOptions;
private readonly logger;
private readonly reporters;
private nowPeriod;
constructor(logger: Logger, reporters: StatReporterPlugin[], options?: Partial);
compute(): Promise;
}
export {};