Documentation
    Preparing search index...

    Checks for the memory heap size and report warning or error after a certain threshold is exceeded.

    const heapCheck = new MemoryHeapCheck()
    .as('Heap memory usage check')
    .warnWhenExceeds('200 mb')
    .failWhenExceeds('300 mb')
    .cacheFor('30s')

    const result = await heapCheck.run()
    console.log(result.status) // 'ok' | 'warning' | 'error'

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    cacheDuration?: number

    The cache duration for the check result in seconds

    name: string = 'Memory heap check'

    The name of the memory heap check

    Methods

    • Define a custom unique name for the check

      Parameters

      • name: string

        The unique name for the health check

      Returns this

      const check = new MyCheck().as('Database connection check')
      
    • Specify the duration for which the check should be cached for

      Parameters

      • duration: string | number

        The cache duration as a string (e.g., '5s', '1m') or number in seconds

      Returns MemoryHeapCheck

      const check = new MyCheck().cacheFor('5 minutes')
      // or
      const check2 = new MyCheck().cacheFor(300) // 300 seconds
    • Define the heap threshold after which a warning should be created.

      • The value should be either a number in bytes
      • Or it should be a value expression in string.
      .warnWhenExceeds('200 mb')
      

      Parameters

      • value: string | number

        The threshold value as bytes (number) or string expression

      Returns MemoryHeapCheck

    • Define the heap threshold after which an error should be created.

      • The value should be either a number in bytes
      • Or it should be a value expression in string.
      .failWhenExceeds('500 mb')
      

      Parameters

      • value: string | number

        The threshold value as bytes (number) or string expression

      Returns MemoryHeapCheck

    • Define a custom callback to compute the heap size. Defaults to using "process.memoryUsage()" method call

      Parameters

      • callback: () => MemoryUsage

        Function that returns memory usage information

      Returns this

      const heapCheck = new MemoryHeapCheck()
      .compute(() => {
      // Custom memory computation logic
      const usage = process.memoryUsage()
      return { ...usage, heapUsed: usage.heapUsed * 0.8 } // Custom adjustment
      })