container.ts
Version:
Modular application framework
73 lines (72 loc) • 2.28 kB
TypeScript
/// <reference types="node" />
import { 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 class. */
export declare class ProcessError extends ErrorChain {
constructor(cause?: Error);
}
/** Node.js process interface. */
export declare class Process extends Module {
/** Default module name. */
static readonly moduleName: string;
/** Environment variable names. */
static readonly ENV: {
NAME: string;
VERSION: string;
NODE_ENV: string;
};
/** Log names. */
static readonly LOG: {
INFORMATION: string;
SIGNAL: string;
};
/** Metric names. */
static readonly METRIC: {
USER_CPU_USAGE: string;
SYSTEM_CPU_USAGE: string;
RSS_MEMORY_USAGE: string;
HEAP_TOTAL_MEMORY_USAGE: string;
HEAP_USED_MEMORY_USAGE: string;
};
/** Get Node.js process title. */
static readonly title: string;
/** Set Node.js process title. */
static setTitle(name?: string): string;
readonly title: string;
readonly version: string;
readonly nodeEnvironment: string;
/** Override in subclass to change metric interval. */
readonly metricInterval: number;
readonly information: IProcessInformation;
readonly status: IProcessStatus;
constructor(options: IModuleOptions);
/** Try to read process information asset file, handle process events. */
moduleUp(): void;
protected readonly envName: string;
protected readonly envVersion: string;
protected readonly envNodeEnv: string;
/** Container down when process termination signal received. */
protected onSignal(signal: string): void;
protected getProcessMetrics(status: IProcessStatus): void;
}