'use strict' ; import { Config } from '@Base/config' ; import { Accounts } from '@Entities/Accounts' ; import { Monitoring } from '@Monitoring/Monitoring' ; import { Stat } from '@Monitoring/Stat' ; import { ValueStat } from '@Monitoring/ValueStat' ; import { ValueHistogram } from '@Monitoring/ValueHistogram' ; import { GenericFilter } from '@Entities/EntityFilters/GenericFilter' ; import { Domains } from '@Entities/Domains' ; import { Logger } from '@Tools/Logging' ; export class StatsMetaverse extends Stat { constructor ( ) { super ( 'metaverse' , 'metaverse' , '' ) ; const totalOnline = new ValueStat ( 'totalOnline' , 'metaverse' , 'count' , async ( stat ) => { const numOnline = await Accounts . accountCount ( new GenericFilter ( { 'timeOfLastHeartbeat' : { '$gte' : Accounts . dateWhenNotOnline ( ) } } ) ) ; stat . Event ( numOnline ) ; } ) ; if ( Config . monitoring . history ) { totalOnline . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; totalOnline . AddHistogram ( 'perWeek' , new ValueHistogram ( 24 * 7 , 60 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( totalOnline ) ; const domainTotalUsers = new ValueStat ( 'domainTotalUsers' , 'metaverse' , 'count' , async ( stat ) => { let totalUsers = 0 ; let anonUsers = 0 ; for await ( const aDomain of Domains . enumerateAsync ( new GenericFilter ( { '$or' : [ { 'numUsers' : { '$gt' : 0 } } , { 'anonUsers' : { '$gt' : 0 } } ] } ) ) ) { totalUsers += aDomain . numUsers ; anonUsers += aDomain . anonUsers ; } ; stat . Event ( totalUsers ) ; Monitoring . getStat ( 'domainAnonUsers' ) ?. Event ( anonUsers ) ; } ) ; if ( Config . monitoring . history ) { domainTotalUsers . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; domainTotalUsers . AddHistogram ( 'perWeek' , new ValueHistogram ( 24 * 7 , 60 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( domainTotalUsers ) ; const domainAnonUsers = new ValueStat ( 'domainAnonUsers' , 'metaverse' , 'count' ) ; if ( Config . monitoring . history ) { domainAnonUsers . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; domainAnonUsers . AddHistogram ( 'perWeek' , new ValueHistogram ( 24 * 7 , 60 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( domainAnonUsers ) ; const activeDomains = new ValueStat ( 'activeDomains' , 'metaverse' , 'count' , async ( stat ) => { const numDomains = await Domains . domainCount ( new GenericFilter ( { 'timeOfLastHeartbeat' : { '$gte' : Domains . dateWhenNotActive ( ) } } ) ) ; stat . Event ( numDomains ) ; } ) ; if ( Config . monitoring . history ) { activeDomains . AddHistogram ( 'perDay' , new ValueHistogram ( 24 * 12 , 5 * 60 * 1000 ) ) ; activeDomains . AddHistogram ( 'perWeek' , new ValueHistogram ( 24 * 7 , 60 * 60 * 1000 ) ) ; } ; Monitoring . addStat ( activeDomains ) ; } ; Event ( pCount ) { throw new Error ( 'Method not implemented.' ) ; } async Gather ( ) { return ; } Report ( pReturnHistogram = true ) { return { 'totalOnline' : Monitoring . getStat ( 'totalOnline' ) ?. Report ( pReturnHistogram ) , 'domainTotalUsers' : Monitoring . getStat ( 'domainTotalUsers' ) ?. Report ( pReturnHistogram ) , 'domainAnonUsers' : Monitoring . getStat ( 'domainAnonUsers' ) ?. Report ( pReturnHistogram ) , 'activeDomains' : Monitoring . getStat ( 'activeDomains' ) ?. Report ( pReturnHistogram ) , } ; } } ;