Socket
Socket
Sign inDemoInstall

pm2-process-manager

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pm2-process-manager

Manage pm2 process(es) with style and ease. Cache the pm2 process(es) Datas and access them at any time to get almost live stats!


Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Built with Love Made with Javascript

Discord server NPM version NPM downloads Get Started Now Patreon

npm installnfo

Pm2 Process Manager

Manage pm2 process(es) with style and ease. Cache the pm2 process(es) Datas and access them at any time to get almost live stats!

Why to use it?

  • Display Pm2 Process Stats (memory-Usage, Cpu-Usage, uptime, restart amounts, etc.)
  • Easily restart, stop & manage pm2 Processes

Planned Features:

  • Optional Web-Dashboard
  • Process-Database-Management with Environment Variables [e.g. for Discord Bots]
  • Process Grouping via Users and Name-Group Prefixes & Suffixes

Installation

npm install pm2-process-manager

Usage

If you have on your System pm2 as a process manager, and wanna show stats or manage the processes via the pm2 api, on a modern and efficient, cached way. Then use this package!

  • It's caching the pm2 process datas, which makes it possible to show the statusses of each process individually.
  • It's making it easy to restart, stop, delete processes
  • It's possible to get the logs via strings!
  • Soon you'll be able to use all pm2 functions!

How to use it?

  • Initialize the Manager
import { Pm2Manager } from "./pm2CacheManager/lib/index.js"
const pm2 = new Pm2Manager({ updateCacheInterval: 5000 });
  • How to access the cache

After a couple moments, it's already cached (less than 500ms) Every updateCacheInterval-ms it's updating the Cache!

const data1 = pm2.cache.get("processName");
const data2 = pm2.cache.get(11) // or with process Id
  • Most important Datas are parsed and easily accessable, here is an example!

Example output when getting the cache data, if it's available

{
  pm2Id: 11,
  pm2Name: "Project Great",
  status: "online",
  processId: 1472,
  memoryUsage: {
    pm2Raw: 90128384,
    megaBytes: 85.95,
    formatted: "85.95 MB",
  },
  cpuUsage: {
    percent: 0.7,
    formatted: "70%"
  },
  execPath: "/usr/bin/node", 
  cwd: "/home/project/great", 
  logOutputPath: "/root/.pm2/logs/Project-Great-out.log",
  logErrorsPath: "/root/.pm2/logs/Project-Great-error.log",
  execMode: "fork", // 'fork' | 'cluster'
  uptime: {
    pm2Raw: 1682751244258,
    startTimestamp: 1682751244258,
    startDate: 2023-04-29T06:54:04.258Z,
    upSinceSec: 8847.245
  },
  pm2Env: {  },
}
  • How to restart/stop/delete a process?
pm2.restart(11); // via pm2 id
pm2.delete("name") // via pm2 name
pm2.stop("Other Name") // via a different Name

List of Methods and Properties

  • Import-able (what you can import { ... } from "pm2-process-manager")
NameTypeUsageDescription
Pm2ManagerMain Class - Pm2 Process Managerconst pm2 = new Pm2Manager({ updateCacheInterval :number })Pm2 Process Manager, to cache pm2 system data and much more
formatPM2DataFunction - UtilityformatPM2Data(Partial<pm2Api.ProcessDescription>)Format pm2Api.list() process-data
formatBytesFunction - UtilityformatBytes(bytes: number, decimals: number = ", noString: boolean = false)Format Bytes to KB, MB, GB (with or without string)
existFileAsync Function - Utilityawait existFile(path: string)Check if a Path actually exists
  • Methods on the Pm2Manager Class:
const pm2 = new Pm2Manager({ updateCacheInterval: 5000 });
NameTypeUsageDescription
cacheProperty = Map<pm2Id, pm2Data>()pm2.cache.get(pm2Id)The Cached Pm2 Process Data
cachePm2DataFunctionpm2.cachePm2Data()Caches the Pm2 Data of the System into pm2.cache Note: If Pm2Manager#updateCacheInterval > 5000, it does this automatically every N milliseconds
findIdFunctionpm2.findId(process: string | name)Return the Pm2 ID (from the cache), of a given Process-name / process-Id
restartAsync Functionawait pm2.restart(process: string | name)Restart a Pm2 Process, by providing a Process-Name / Process-ID
stopAsync Functionawait pm2.stop(process: string | name)Stop a pm2 Process, by providing a Process-Name / Process-ID P

Keywords

FAQs

Last updated on 29 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc