The [Performance Observer][] API can be used to collect basic performance metrics for each Http2Session and Http2Stream instance.

    1. const { PerformanceObserver } = require('perf_hooks');
    2. const obs = new PerformanceObserver((items) => {
    3. const entry = items.getEntries()[0];
    4. console.log(entry.entryType); // prints 'http2'
    5. if (entry.name === 'Http2Session') {
    6. // Entry contains statistics about the Http2Session
    7. } else if (entry.name === 'Http2Stream') {
    8. // Entry contains statistics about the Http2Stream
    9. }
    10. });
    11. obs.observe({ entryTypes: ['http2'] });

    The entryType property of the PerformanceEntry will be equal to 'http2'.

    The name property of the PerformanceEntry will be equal to either 'Http2Stream' or 'Http2Session'.

    If name is equal to Http2Stream, the PerformanceEntry will contain the following additional properties:

    • bytesRead {number} The number of DATA frame bytes received for this Http2Stream.
    • bytesWritten {number} The number of DATA frame bytes sent for this Http2Stream.
    • id {number} The identifier of the associated Http2Stream
    • timeToFirstByte {number} The number of milliseconds elapsed between the PerformanceEntry startTime and the reception of the first DATA frame.
    • timeToFirstByteSent {number} The number of milliseconds elapsed between the PerformanceEntry startTime and sending of the first DATA frame.
    • timeToFirstHeader {number} The number of milliseconds elapsed between the PerformanceEntry startTime and the reception of the first header.

    If name is equal to Http2Session, the PerformanceEntry will contain the following additional properties:

    • bytesRead {number} The number of bytes received for this Http2Session.
    • bytesWritten {number} The number of bytes sent for this Http2Session.
    • framesReceived {number} The number of HTTP/2 frames received by the Http2Session.
    • framesSent {number} The number of HTTP/2 frames sent by the Http2Session.
    • maxConcurrentStreams {number} The maximum number of streams concurrently open during the lifetime of the Http2Session.
    • pingRTT {number} The number of milliseconds elapsed since the transmission of a PING frame and the reception of its acknowledgment. Only present if a PING frame has been sent on the Http2Session.
    • streamAverageDuration {number} The average duration (in milliseconds) for all Http2Stream instances.
    • streamCount {number} The number of Http2Stream instances processed by the Http2Session.
    • type {string} Either 'server' or 'client' to identify the type of Http2Session.