Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu usage always 0% in "pm2 status" #5182

Open
mermao1 opened this issue Sep 23, 2021 · 3 comments
Open

cpu usage always 0% in "pm2 status" #5182

mermao1 opened this issue Sep 23, 2021 · 3 comments

Comments

@mermao1
Copy link

mermao1 commented Sep 23, 2021

What's going wrong?

If I try to see CPU usage using "pm2 status" command, all processes always marked as 0% CPU usage.
I can see the correct CPU usage using "pm2 monit" or even "pm2 report"

How could we reproduce this issue?

Everything was working on my old server, with the same hardware, distro (Ubuntu 18), scripts and commands.
The only difference in this new server is that I used a different image to install the system (New server provider), and also using old versions for pm2, node, npm:

OldServer (pm2 status working):
root@old:~# pm2 --version
5.1.0
root@old:~# node --version
v12.22.5
root@old:~# npm --version
6.14.14

NewServer (pm2 status not working):
root@new:~# pm2 --version
5.1.1
root@new:~# node --version
v12.22.6
root@new:~# npm --version
6.14.15

I tried to downgrade pm2 to 5.1.0 on the new server but the issue persisted.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Thu Sep 23 2021 10:54:44 GMT-0300 (Brasilia Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.1
node version         : 12.22.6
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
uptime               : 5min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.1
node version         : 12.22.6
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : AMD Ryzen 7 3700X 8-Core Processor
cpus nb              : 16
freemem              : 20384501760
totalmem             : 67472343040
home                 : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name          │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ PytParser1    │ default     │ N/A     │ fork    │ 11364    │ 5m     │ 0    │ online    │ 0%       │ 319.9mb  │ root     │ disabled │
│ 1   │ PytParser2    │ default     │ N/A     │ fork    │ 11365    │ 5m     │ 0    │ online    │ 0%       │ 311.9mb  │ root     │ disabled │
│ 2   │ PytParser3    │ default     │ N/A     │ fork    │ 11366    │ 5m     │ 0    │ online    │ 18.6%    │ 313.4mb  │ root     │ disabled │
│ 3   │ PytParser4    │ default     │ N/A     │ fork    │ 11369    │ 5m     │ 0    │ online    │ 2.6%     │ 319.0mb  │ root     │ disabled │
│ 4   │ PytParser5    │ default     │ N/A     │ fork    │ 11370    │ 5m     │ 0    │ online    │ 0.1%     │ 314.5mb  │ root     │ disabled │
│ 5   │ PytParser6    │ default     │ N/A     │ fork    │ 11371    │ 5m     │ 0    │ online    │ 15.4%    │ 318.0mb  │ root     │ disabled │
└─────┴───────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2        | 2021-09-23T10:49:03: PM2 log: RPC socket file      : /root/.pm2/rpc.sock
PM2        | 2021-09-23T10:49:03: PM2 log: BUS socket file      : /root/.pm2/pub.sock
PM2        | 2021-09-23T10:49:03: PM2 log: Application log path : /root/.pm2/logs
PM2        | 2021-09-23T10:49:03: PM2 log: Worker Interval      : 30000
PM2        | 2021-09-23T10:49:03: PM2 log: Process dump file    : /root/.pm2/dump.pm2
PM2        | 2021-09-23T10:49:03: PM2 log: Concurrent actions   : 2
PM2        | 2021-09-23T10:49:03: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-09-23T10:49:03: PM2 log: ===============================================================================
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser1:0] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser1:0] online
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser2:1] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser2:1] online
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser3:2] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser3:2] online
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser4:3] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser4:3] online
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser5:4] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser5:4] online
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser6:5] starting in -fork mode-
PM2        | 2021-09-23T10:49:03: PM2 log: App [PytParser6:5] online

@turboboost55
Copy link

I'm seeing the same thing on Ubuntu 18.04. It was working previously, with an older version of pm2 (can't remember the version) and Node 10, but this problem started when I upgraded to Node 16.13.0 and pm2 5.1.2.

@rslucena
Copy link

same problem here

@titanism
Copy link

titanism commented Jun 6, 2024

I did some digging, it looks like pm2 status by default without options calls that.speedList(null) which is defined in lib/API.js. This function then uses a variable called proc_list to render the pm2 status table in CLI/terminal.

The issue is that in proc_list all processes are reported as having 0 for the value (e.g. monit: { memory: 1852067840, cpu: 0 }). My assumption is that the timer is not being set properly (or it's getting reset). It's calling getMonitorData twice basically when pm2 status gets called, which is super unoptimal.

pm2/lib/API.js

Line 622 in 5e0eb40

return cb ? cb(null, list) : that.speedList(null);

getMonitorData is defined in lib/God/ActionMethods.js and it calls pidusage which is defined here:

pidusage(pids, function retPidUsage(err, statistics) {

The issue is that statistics has values of cpu: 0. This means the issue is related to pidusage module

As reported in GitHub issues for pidusage, the cpu value sometimes returns 0. See soyuka/pidusage#169. This is a known bug. An alternative might be to use the project https://www.npmjs.com/package/node-ps-data and then replace pidusage in this PM2 codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants