CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pm2

Production process manager for Node.JS applications with a built-in load balancer.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

monitoring.mddocs/

Monitoring and Information

Comprehensive monitoring, process information retrieval, and performance analysis capabilities for PM2-managed applications. Includes real-time metrics collection, log management, process communication, and debugging tools.

Capabilities

Process Information

Retrieve detailed information about managed processes and their current state.

/**
 * Get list of all managed processes
 * @param callback - Called with error and array of process descriptions
 */
function list(callback: (err: Error, processes: ProcessDescription[]) => void): void;

/**
 * Get detailed information about specific process
 * @param process - Process name or ID
 * @param callback - Called with error and process description array
 */
function describe(process: string | number, callback: (err: Error, description: ProcessDescription[]) => void): void;

/**
 * Get process PIDs
 * @param app_name - Process name (optional, returns all PIDs if not provided)
 * @param callback - Called with PID information
 */
function getPID(app_name?: string, callback?: (err: Error, proc: Proc) => void): void;

Usage Examples:

// List all processes
pm2.list((err, processes) => {
  if (err) throw err;
  processes.forEach(proc => {
    console.log(`${proc.name}: ${proc.pm2_env.status} (PID: ${proc.pid})`);
    console.log(`  Memory: ${proc.monit.memory} bytes`);
    console.log(`  CPU: ${proc.monit.cpu}%`);
  });
});

// Describe specific process
pm2.describe('my-app', (err, description) => {
  if (err) throw err;
  const proc = description[0];
  console.log('Process Details:');
  console.log(`  Name: ${proc.name}`);
  console.log(`  Status: ${proc.pm2_env.status}`);
  console.log(`  Uptime: ${proc.pm2_env.pm_uptime}`);
  console.log(`  Restarts: ${proc.pm2_env.restart_time}`);
  console.log(`  Script: ${proc.pm2_env.pm_exec_path}`);
});

// Get PIDs for all processes
pm2.getPID((err, proc) => {
  if (err) throw err;
  console.log('Process PIDs:', proc);
});

System Monitoring

Launch and manage system-level monitoring for resource usage tracking.

/**
 * Launch system monitoring for CPU and memory usage
 * @param callback - Called when monitoring is launched
 */
function launchSysMonitoring(callback?: (err: Error) => void): void;

/**
 * Launch message bus for process events
 * @param callback - Called with error and bus object for event listening
 */
function launchBus(callback: (err: Error, bus: any) => void): void;

Usage Examples:

// Launch system monitoring
pm2.launchSysMonitoring((err) => {
  if (err) throw err;
  console.log('System monitoring started');
});

// Launch event bus
pm2.launchBus((err, bus) => {
  if (err) throw err;
  
  // Listen to process events
  bus.on('process:msg', (packet) => {
    console.log('Process message:', packet);
  });
  
  bus.on('process:exception', (packet) => {
    console.log('Process exception:', packet);
  });
});

Performance Profiling

CPU and memory profiling capabilities for performance analysis.

/**
 * Profile CPU or memory usage
 * @param type - 'cpu' for CPU profiling, 'mem' for memory profiling
 * @param time - Duration in seconds (default: 10)
 * @param callback - Called when profiling is complete
 */
function profile(type: 'cpu' | 'mem', time?: number, callback?: (err: Error) => void): void;

Usage Examples:

// CPU profiling for 30 seconds
pm2.profile('cpu', 30, (err) => {
  if (err) throw err;
  console.log('CPU profiling completed, check PM2 logs for results');
});

// Memory profiling with default duration
pm2.profile('mem', (err) => {
  if (err) throw err;
  console.log('Memory profiling completed');
});

Process Communication

Send data and communicate with managed processes.

/**
 * Send data to specific process
 * @param proc_id - Process ID
 * @param packet - Data object to send
 * @param callback - Called when data is sent
 */
function sendDataToProcessId(proc_id: number, packet: object, callback: (err: Error, result: any) => void): void;

/**
 * Send data using packet format
 * @param packet - Formatted packet with id, type, topic, and data
 */
function sendDataToProcessId(packet: {id: number, type: 'process:msg', topic: true, data: object}): void;

/**
 * Send line to process stdin
 * @param pm_id - Process ID or name
 * @param line - Line to send
 * @param separator - Line separator (default: '\n')
 * @param callback - Called when line is sent
 */
function sendLineToStdin(pm_id: string | number, line: string, separator?: string, callback?: (err: Error) => void): void;

/**
 * Trigger custom action on process
 * @param pm_id - Process ID or name
 * @param action_name - Name of action to trigger
 * @param params - Parameters to pass to action
 * @param callback - Called when action completes
 */
function trigger(pm_id: string | number, action_name: string, params?: any, callback?: (err: Error) => void): void;

Usage Examples:

// Send data to process
pm2.sendDataToProcessId(0, { message: 'Hello from PM2' }, (err, result) => {
  if (err) throw err;
  console.log('Data sent to process');
});

// Send formatted packet
pm2.sendDataToProcessId({
  id: 0,
  type: 'process:msg',
  topic: true,
  data: { command: 'refresh', config: { timeout: 5000 } }
});

// Send line to stdin
pm2.sendLineToStdin(0, 'reload-config', '\n', (err) => {
  if (err) throw err;
  console.log('Command sent to process stdin');
});

// Trigger custom action
pm2.trigger('my-app', 'graceful-shutdown', { timeout: 30000 }, (err) => {
  if (err) throw err;
  console.log('Graceful shutdown triggered');
});

Signal Management

Send system signals to managed processes.

/**
 * Send signal to process by name
 * @param signal - Signal to send (e.g., 'SIGUSR1', 'SIGTERM')
 * @param process - Process name or ID
 * @param callback - Called when signal is sent
 */
function sendSignalToProcessName(signal: string | number, process: number | string, callback: (err: Error, result: any) => void): void;

/**
 * Send signal to process by ID directly
 * @param signal - Signal to send (e.g., 'SIGUSR1', 'SIGTERM')
 * @param process_id - Process ID
 * @param callback - Called when signal is sent
 */
function sendSignalToProcessId(signal: string | number, process_id: number, callback: (err: Error, result: any) => void): void;

Usage Examples:

// Send SIGUSR1 signal
pm2.sendSignalToProcessName('SIGUSR1', 'my-app', (err, result) => {
  if (err) throw err;
  console.log('Signal sent to process');
});

// Send SIGTERM to process ID
pm2.sendSignalToProcessName('SIGTERM', 0, (err, result) => {
  if (err) throw err;
  console.log('SIGTERM sent to process 0');
});

Log Management

Manage and access process logs.

/**
 * Flush process logs
 * @param process - Process name, ID, or "all"
 * @param callback - Called when logs are flushed
 */
function flush(process: number | string, callback: (err: Error, result: any) => void): void;

/**
 * Rotate log files
 * @param callback - Called when log rotation is complete
 */
function reloadLogs(callback: (err: Error, result: any) => void): void;

/**
 * Attach to process logs
 * @param pm_id - Process ID or name
 * @param separator - Log line separator
 * @param callback - Called when attached
 */
function attach(pm_id: string | number, separator?: string, callback?: (err: Error) => void): void;

Usage Examples:

// Flush all logs
pm2.flush('all', (err, result) => {
  if (err) throw err;
  console.log('All logs flushed');
});

// Rotate log files
pm2.reloadLogs((err, result) => {
  if (err) throw err;
  console.log('Log files rotated');
});

// Attach to process logs
pm2.attach(0, '\n', (err) => {
  if (err) throw err;
  console.log('Attached to process 0 logs');
});

System Information

Get PM2 system information and health status.

/**
 * Get PM2 daemon version
 * @param callback - Called with version information
 */
function getVersion(callback: (err: Error) => void): void;

/**
 * Generate comprehensive system report
 * @returns System report with all process and system information
 */
function report(): void;

/**
 * Ping PM2 daemon to check connectivity
 * @param callback - Called with ping result
 */
function ping(callback: (err: Error) => void): void;

Usage Examples:

// Get PM2 version
pm2.getVersion((err) => {
  if (err) throw err;
  console.log('PM2 version retrieved');
});

// Generate system report
pm2.report(); // Outputs comprehensive system information

// Ping daemon
pm2.ping((err) => {
  if (err) throw err;
  console.log('PM2 daemon is responsive');
});

Environment and Debugging

Access process environment and debugging capabilities.

/**
 * Get process environment variables
 * @param app_id - Process name or ID
 * @param callback - Called with environment variables
 */
function env(app_id: string | number, callback?: (err: Error) => void): void;

/**
 * Inspect process for debugging
 * @param app_name - Process name
 * @param callback - Called with inspect information
 */
function inspect(app_name: string, callback?: (err: Error) => void): void;

Usage Examples:

// Get process environment
pm2.env('my-app', (err) => {
  if (err) throw err;
  console.log('Environment variables retrieved');
});

// Inspect process for debugging
pm2.inspect('my-app', (err) => {
  if (err) throw err;
  console.log('Process inspection started');
});

Core Types

interface ProcessDescription {
  /** Process name */
  name?: string;
  /** System process ID */
  pid?: number;
  /** PM2 internal process ID */
  pm_id?: number;
  /** Real-time monitoring data */
  monit?: {
    /** Memory usage in bytes */
    memory?: number;
    /** CPU usage percentage */
    cpu?: number;
  };
  /** PM2 environment data */
  pm2_env?: {
    /** Working directory */
    pm_cwd?: string;
    /** Stdout log file path */
    pm_out_log_path?: string;
    /** Stderr log file path */
    pm_err_log_path?: string;
    /** Script interpreter */
    exec_interpreter?: string;
    /** Process uptime in milliseconds */
    pm_uptime?: number;
    /** Number of unstable restarts */
    unstable_restarts?: number;
    /** Last restart timestamp */
    restart_time?: number;
    /** Current process status */
    status?: ProcessStatus;
    /** Number of instances */
    instances?: number | 'max';
    /** Executable script path */
    pm_exec_path?: string;
  };
}

interface Monit {
  /** Memory usage in bytes */
  memory?: number;
  /** CPU usage percentage */
  cpu?: number;
}

interface Pm2Env {
  /** Working directory */
  pm_cwd?: string;
  /** Stdout log file path */
  pm_out_log_path?: string;
  /** Stderr log file path */
  pm_err_log_path?: string;
  /** Script interpreter */
  exec_interpreter?: string;
  /** Process uptime in milliseconds */
  pm_uptime?: number;
  /** Number of unstable restarts */
  unstable_restarts?: number;
  /** Last restart timestamp */
  restart_time?: number;
  /** Current process status */
  status?: ProcessStatus;
  /** Number of instances */
  instances?: number | 'max';
  /** Executable script path */
  pm_exec_path?: string;
}

type ProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status' | 'waiting_restart';

Install with Tessl CLI

npx tessl i tessl/npm-pm2

docs

cli-commands.md

configuration.md

docker-integration.md

index.md

module-management.md

monitoring.md

process-management.md

typescript-definitions.md

version-control.md

tile.json