import numeral from '@elastic/numeral' ; import { LogMeta } from '@kbn/logging' ; import { OpsMetrics } from '..' ; internal export function getEcsOpsMetricsLog ( metrics ) { const { process , os } = metrics ; const processMemoryUsedInBytes = process ?. memory ?. heap ?. used_in_bytes ; const processMemoryUsedInBytesMsg = processMemoryUsedInBytes ? `memory: ${ numeral ( processMemoryUsedInBytes ) . format ( '0.0b' ) } ` : '' ; const uptimeVal = process ?. uptime_in_millis ? Math . floor ( process . uptime_in_millis / 1000 ) : undefined ; const uptimeValMsg = uptimeVal ? `uptime: ${ numeral ( uptimeVal ) . format ( '00:00:00' ) } ` : '' ; const eventLoopDelayVal = process ?. event_loop_delay ; const eventLoopDelayValMsg = eventLoopDelayVal ? `mean delay: ${ numeral ( process ?. event_loop_delay ) . format ( '0.000' ) }` : '' ; const eventLoopDelayPercentiles = process ?. event_loop_delay_histogram ?. percentiles ; const eventLoopDelayHistVals = eventLoopDelayPercentiles ? { 50 : eventLoopDelayPercentiles [ 50 ] , 95 : eventLoopDelayPercentiles [ 95 ] , 99 : eventLoopDelayPercentiles [ 99 ] , } : undefined ; const eventLoopDelayHistMsg = eventLoopDelayPercentiles ? ` delay histogram: { 50: ${ numeral ( eventLoopDelayPercentiles [ '50' ] ) . format ( '0.000' ) }; 95: ${ numeral ( eventLoopDelayPercentiles [ '95' ] ) . format ( '0.000' ) }; 99: ${ numeral ( eventLoopDelayPercentiles [ '99' ] ) . format ( '0.000' ) } }` : '' ; const loadEntries = { '1m' : os ?. load ? os ?. load [ '1m' ] : undefined , '5m' : os ?. load ? os ?. load [ '5m' ] : undefined , '15m' : os ?. load ? os ?. load [ '15m' ] : undefined , } ; const loadVals = [ ... Object . values ( os ?. load ?? [ ] ) ] ; const loadValsMsg = loadVals . length > 0 ? `load: [${ loadVals . map ( ( val ) => { return numeral ( val ) . format ( '0.00' ) ; } ) }] ` : '' ; const meta = { event : { kind : 'metric' , category : [ 'process' , 'host' ] , type : [ 'info' ] , } , process : { uptime : uptimeVal , memory : { heap : { usedInBytes : processMemoryUsedInBytes , } , } , eventLoopDelay : eventLoopDelayVal , eventLoopDelayHistogram : eventLoopDelayHistVals , } , host : { os : { load : loadEntries , } , } , } ; return { message : [ processMemoryUsedInBytesMsg , uptimeValMsg , loadValsMsg , eventLoopDelayValMsg , eventLoopDelayHistMsg , ] . join ( '' ) , meta , } ; }