'use strict' ; import { Config } from '@Base/config' ; import { Histogram } from '@Monitoring/Histogram' ; import { Logger } from '@Tools/Logging' ; import { VKeyedCollection } from '@Tools/vTypes' ; export type updateValueFunction = ( pStat : Stat ) => Promise < void > ; export abstract class Stat { public name : string ; public category : string ; public unit : string ; public value : number ; public pullAction : updateValueFunction ; public secondsBetweenPulls : number ; public pullCount : number ; _histograms : Map < string , Histogram > ; constructor ( pName , pCategory , pUnit , pPullAction ? ) { this . name = pName ; this . category = pCategory ; this . unit = pUnit ; this . value = 0 ; this . pullAction = pPullAction ; this . _histograms = new Map < string , Histogram > ( ) ; } ; AddHistogram ( pHistogramName , pHistogram ) { this . _histograms . set ( pHistogramName , pHistogram ) ; } ; async DoPullAction ( ) { if ( this . pullAction ) { if ( this . secondsBetweenPulls ) { if ( this . pullCount -- < 0 ) { await this . pullAction ( this ) ; this . pullCount = this . secondsBetweenPulls ; } ; } else { await this . pullAction ( this ) ; } ; } ; } ; abstract Event ( pCount ) ; abstract Gather ( ) ; Report ( pReturnHistogram = true ) { const report = { 'name' : this . name , 'category' : this . category , 'unit' : this . unit , 'value' : this . value } ; if ( pReturnHistogram && this . _histograms . size > 0 ) { const history = { } ; this . _histograms . forEach ( ( histo , name ) => { history [ name ] = histo . GetHistogram ( ) ; } ) ; report . history = history ; } ; return report ; } ; } ;