cjbassi / gotop

A terminal based graphical activity monitor inspired by gtop and vtop
GNU Affero General Public License v3.0
7.37k stars 440 forks source link

Processes widget fails with ps from BusyBox #110

Open Mikiya83 opened 5 years ago

Mikiya83 commented 5 years ago

Required information:

Logs : "11:19:36 proc_linux.go:14: failed to retrieve processes: failed to execute 'ps' command: exit status 1"

On QNAP devices, ps command used Busybox version :

BusyBox v1.24.1 (2018-12-28 02:26:16 CST) multi-call binary.

Usage: ps [-o COL1,COL2=HEADER] [-T]

Show list of processes

        -o COL1,COL2=HEADER     Select columns for display
        -T                      Show threads

QNAP Options:
        --columns N

This version does not have "-axo" options so it fails. By default it shows processes of all users. Is it possible to have a version for BusyBox users ? Thanks !

cjbassi commented 5 years ago

Busbox support sounds good to me. It would probably require us to do some check on the environment on start and adjust the ps flags. I'm curious what the adjustments would be. Is that actually the entirety of the man page? :joy: If not, could you copy the contents into a gist or link it?

So can you test this command: ps -o pid,comm,pcpu,pmem,args? Also, there's been some issues with the ps columns being cropped, so if that happens when running that, then you can try doing ps -o pid,comm=superlongheaderasdfasdfasdfsdaf etc.

Mikiya83 commented 5 years ago

Unfortunately it is the complete manpage :(

[~] # ps -h
ps: invalid option -- 'h'
BusyBox v1.24.1 (2018-12-28 02:26:16 CST) multi-call binary.

Usage: ps [-o COL1,COL2=HEADER] [-T]

Show list of processes

        -o COL1,COL2=HEADER     Select columns for display
        -T                      Show threads

QNAP Options:
        --columns N
[~] #

With yours commands i get :

ps -o pid,comm,pcpu,pmem,args 
ps: bad -o argument 'pcpu', supported arguments: user,group,comm,args,pid,ppid,pgid,etime,nice,rgroup,ruser,time,tty,vsz,stat,rss

I removed pcpu and pmem (because it's not recognized) and i get things like this :

[~] # ps -o pid,comm,args
  PID  COMMAND          Command
    1 init             init
    2 kthreadd         [kthreadd]
    3 ksoftirqd/0      [ksoftirqd/0]
    5 kworker/0:0H     [kworker/0:0H]
    7 rcu_sched        [rcu_sched]
...

I don't see any problems with cropping (i have some very long "Command" entries).

cjbassi commented 5 years ago

So it looks like ps on busybox doesn't support per process cpu usage or memory reporting. So we should check if we're on busybox and then our only option is to remove the unsupported flags and only show PID and command.

Mikiya83 commented 5 years ago

The only way i find to get cpu or memory reporting is to use top. If you need other tests, i'm available ;)

cjbassi commented 5 years ago

Some new ideas about different ways to fix this:

  1. detect when a system uses busybox, then use cli args appropriate for ps on a busybox system, but we won't be able to get per-process cpu or memory usage
  2. require users to download and install procps on their system as a workaround
  3. directly gather process information ourselves by traversing /proc, or use the implementation provided by gopsutil

3 sounds best to me. We were originally using gopsutil to gather process information but I forget why we switched of it. And it should be easy to test gopsutil's implementation (I've just been busy).