import {InternalLog, logger} from '../../internal/log';
import {Tags} from '../../util';
import {Gauge} from '../gauge';
import {LocalSettable} from './settable';
export class LocalGauge extends LocalSettable<number> implements Gauge<number> {
protected readonly log: InternalLog = logger('LocalGauge');
decrement(value = 0, tags: Tags = {}): void {
const update = (this.raw || 0) - value;
this.log.debug('%d - %d = %d', this.raw, value, update);
this.set(update, tags);
}
increment(value = 1, tags: Tags = {}): void {
const update = (this.raw || 0) + value;
this.log.debug('%d + %d = %d', this.raw, value, update);
this.set(update, tags);
}
get raw(): number {
return this._val?.value || 0;
}
reset(): void {
this.set(0);
}
}
export class LocalBigIntGauge extends LocalSettable<bigint> implements Gauge<bigint> {
decrement(value?: bigint, tags: Tags = {}): void {
value = value || BigInt(1);
const update = (this.raw || BigInt(0)) - value;
this.set(update, tags);
}
increment(value?: bigint, tags: Tags = {}): void {
value = value || BigInt(1);
const update = (this.raw || BigInt(0)) + value;
this.set(update, tags);
}
get raw(): bigint {
return this._val.value || BigInt(0);
}
reset(): void {
this.set(BigInt(0));
}
}
|