pandora-metrics
Version:
## Overview
87 lines (86 loc) • 2.75 kB
TypeScript
import { BaseCounter, ICounter } from './Counter';
/**
* 提供分桶计数功能,每个桶统计一定时间间隔内的计数。
* BucketCounter只保留最近N个时间间隔内的计数,再老的会被丢弃。
* 同时保存从创建开始到现在的累计计数。
*/
export interface IBucketCounter extends ICounter {
/**
* update the counter to the given bucket
*/
update(n?: any): any;
/**
* Return the bucket count, keyed by timestamp
* @return the bucket count, keyed by timestamp
*/
getBucketCounts(): any;
/**
* Return the bucket count, keyed by timestamp, since (including) the startTime.
* 返回从startTime开始的分桶统计功能
* @param startTime 查询起始时间, 单位是毫秒
* @return the bucket count, keyed by timestamp
*/
getBucketCounts(startTime: any): any;
/**
* Get the interval of the bucket
* @return the interval of the bucket
*/
getBucketInterval(): any;
}
export interface Bucket {
timestamp: any;
count: any;
}
export declare class BucketDeque {
private queue;
private current;
private size;
constructor(length?: number);
protected createQueueItem(): Bucket;
addLast(e: Bucket): void;
peek(): Bucket;
/**
* Example1:
* 10:00 10:01 10:02 09:57 09:58 09:59
* 70 80 90 40 50 60
* | \
* startPos latestIndex
* Example2:
* 10:00 09:55 09:56 09:57 09:58 09:59
* 70 20 30 40 50 60
* | |
* latestIndex startPos
*/
getBucketList(): Array<Bucket>;
}
export declare class BucketCounter extends BaseCounter implements IBucketCounter {
/**
* 保存从创建开始累积的计数
*/
private totalCount;
/**
* 保存最近N次的精确计数, 采用环形队列避免数据的挪动
*/
private buckets;
/**
* 是否更新总次数
*/
private updateTotalCount;
/**
* 每一次精确计数的之间的时间间隔,单位秒
* 只能是 1,5,10, 30, 60 这几个数字
*/
private interval;
constructor(interval?: number, numberOfBucket?: number, updateTotalCount?: boolean);
update(n?: number): void;
/**
* Return the bucket count, keyed by timestamp
* @return the bucket count, keyed by timestamp
*/
getBucketCounts(startTime?: number): Map<number, number>;
private calculateCurrentTimestamp(timestamp);
getCount(): number;
inc(n?: any): void;
dec(n?: number): void;
getBucketInterval(): any;
}