'use strict' ; import { Config } from '@Base/config' ; import os from 'os' ; import { Monitoring } from '@Monitoring/Monitoring' ; import { Stat } from '@Monitoring/Stat' ; import { ValueStat } from '@Monitoring/ValueStat' ; import { ValueHistogram } from '@Monitoring/ValueHistogram' ; import { Logger } from '@Tools/Logging' ; export class StatsOs extends Stat { constructor ( ) { super ( 'os' , 'os' , '' ) ; const cpuBusy = new ValueStat ( 'cpuBusy' , 'os' , 'percent' , async ( stat ) => { const cpuInfo = os . cpus ( ) ; let totalBusy = 0 ; let totalIdle = 0 ; cpuInfo . forEach ( element => { totalIdle += element . times . idle ; totalBusy += element . times . user + element . times . nice + element . times . sys + element . times . irq ; } ) ; stat . Event ( totalBusy / ( totalIdle + totalBusy ) * 100 ) ; } ) ; if ( Config . monitoring . history ) { cpuBusy . AddHistogram ( '5mins' , new ValueHistogram ( 60 , 5 * 1000 ) ) ; cpuBusy . AddHistogram ( 'perHour' , new ValueHistogram ( 60 , 60 * 1000 ) ) ; cpuBusy . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( cpuBusy ) ; const memUsage = new ValueStat ( 'memUsage' , 'os' , 'percent' , async ( stat ) => { stat . Event ( os . freemem ( ) / os . totalmem ( ) * 100 ) ; } ) ; if ( Config . monitoring . history ) { memUsage . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; memUsage . AddHistogram ( 'perWeek' , new ValueHistogram ( 7 * 24 , 60 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( memUsage ) ; } ; Event ( pCount ) { throw new Error ( 'Method not implemented.' ) ; } Gather ( ) { return ; } Report ( pReturnHistogram = true ) { return { 'cpus' : os . cpus ( ) , 'freemem' : os . freemem ( ) , 'totalmem' : os . totalmem ( ) , 'loadavg' : os . loadavg ( ) , 'uptime' : os . uptime ( ) , 'cpuBusy' : Monitoring . getStat ( 'cpuBusy' ) ?. Report ( pReturnHistogram ) , 'memUsage' : Monitoring . getStat ( 'memUsage' ) ?. Report ( pReturnHistogram ) } ; } } ;