container.ts
Version:
Modular application framework
78 lines (77 loc) • 2.62 kB
TypeScript
/// <reference types="node" />
import { IModuleHook, IModuleOptions, Module } from "../../../container";
import { ErrorChain } from "../../error";
/** Process runtime information interface. */
export interface IProcessInformation {
name: string;
title: string;
version: string;
environment: string;
arch: string;
platform: NodeJS.Platform;
nodeVersion: string;
pid: number;
type: string;
release: string;
endianness: "BE" | "LE";
hostname: string;
}
/** Process status interface. */
export interface IProcessStatus {
uptime: number;
cpuUsage: NodeJS.CpuUsage;
memoryUsage: NodeJS.MemoryUsage;
}
/** Process error codes. */
export declare enum EProcessError {
Signal = "ProcessError.Signal"
}
/** Process error class. */
export declare class ProcessError extends ErrorChain {
constructor(code: EProcessError, cause?: Error, context?: object);
}
/** Process environment variable names. */
export declare enum EProcessEnv {
Name = "PROCESS_NAME",
Version = "PROCESS_VERSION",
NodeEnv = "NODE_ENV"
}
/** Process log names. */
export declare enum EProcessLog {
Information = "Process.Information",
Signal = "Process.Signal"
}
/** Process metric names. */
export declare enum EProcessMetric {
UserCpuUsage = "Process.UserCpuUsage",
SystemCpuUsage = "Process.SystemCpuUsage",
RssMemoryUsage = "Process.RssMemoryUsage",
HeapTotalMemoryUsage = "Process.HeapTotalMemoryUsage",
HeapUsedMemoryUsage = "Process.HeapUsedMemoryUsage"
}
/** Node.js process interface. */
export declare class Process extends Module {
/** Default module name. */
static readonly moduleName: string;
/** Get Node.js process title. */
static get title(): string;
/** Set Node.js process title. */
static setTitle(name?: string): string;
get envTitle(): string;
readonly envVersion: string;
readonly envNodeEnv: string;
/** Override in subclass to change metric interval. */
get metricInterval(): number;
/** Get Node.js process information. */
get information(): IProcessInformation;
/** Get Node.js process status. */
get status(): IProcessStatus;
constructor(options: IModuleOptions);
/** Try to read process information asset file, handle process events. */
moduleUp(...args: IModuleHook[]): Promise<void>;
/** Kill this process with "SIGINT" signal. */
kill(): void;
/** Container down when process termination signal received. */
protected processOnSignal(signal: string): Promise<void>;
protected processMetrics(status: IProcessStatus): void;
}