Py3status: sysdata: show process name that consumes most CPU / mem

Created on 5 Sep 2018  ·  7Comments  ·  Source: ultrabug/py3status

Creating as an issue because the number of open PRs is still prevailing 😛

I was thinking, part of the reason I use sysdata module is to spot anomalies, when CPU or memory usage is higher than I expect. In such situations what I usually do is I open new terminal, launch htop and see which process is using most CPU / memory.

What could be cool is to let py3status show this information for me. It could be an on-click notification, or simply a couple of new format placeholders.

My personal vote would probably go for format placeholder for process name alone (no CLI arguments), to keep the string short (e.g. chromium instead of /usr/lib/chromium/chromium --type=renderer --enable-accelerated-video --enable-features=NativeNotifications --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --num-raster-threads=4 --enable-zero-copy ...).

Most helpful comment

# Top 3 most memory consuming processes
order += "external_script"
external_script {
    script_path = "python -c \"from psutil import process_iter; print('⛁ '"
    script_path += "+ ', '.join(['{name} {memory_percent:.2f}%'.format(**x) "
    script_path += "for x in reversed([p.info for p in sorted(process_iter("
    script_path += "attrs=['name', 'memory_percent']), key=lambda p: p.info"
    script_path += "['memory_percent'])][-3:])]))\""
}

All 7 comments

I've just realized that I would really like to have the same for net_rate module as well, I would like to have a format placeholder for the application that is using the most network traffic (as per nethogs for example). The purpose is the same, to spot suspicious activity, sometimes I see bursts of high bandwidth usage but I have no idea what process is doing that.

when CPU or memory usage is higher than I expect. In such situations what I usually do is I open new terminal, launch htop and see which process is using most CPU / memory.

I'd love this for remote servers not sure how easy that would be though - remote sys_data :)

Maybe do a glances https://github.com/nicolargo/glances client module?

# Top 3 most memory consuming processes
order += "external_script"
external_script {
    script_path = "python -c \"from psutil import process_iter; print('⛁ '"
    script_path += "+ ', '.join(['{name} {memory_percent:.2f}%'.format(**x) "
    script_path += "for x in reversed([p.info for p in sorted(process_iter("
    script_path += "attrs=['name', 'memory_percent']), key=lambda p: p.info"
    script_path += "['memory_percent'])][-3:])]))\""
}

@maximbaz Did conky resolve this issue?

Yep, conky is just awesome 👍 Here's what I came up with so far:

group cpu {
  button_next = 1
  button_prev = 0

  sysdata {
    cache_timeout = 1
    thresholds = { 'cpu': [(0, 'good'), (25, 'degraded'), (80, 'bad')] }
    format = '[\?color=cpu CPU {cpu_usage:.0f}%]'
  }

  conky {
    format = 'Top CPU: {top name 1} {top cpu 1}%'
  }
}

group ram {
  button_next = 1
  button_prev = 0

  sysdata {
    cache_timeout = 1
    thresholds = { 'mem': [(0, 'good'), (60, 'degraded'), (80, 'bad')] }
    format = '[\?color=mem RAM {mem_used_percent:.0f}%]'
  }

  conky {
    format = 'Top RAM: {top_mem name 1} {top_mem mem 1}%'
  }
}
Was this page helpful?
0 / 5 - 0 ratings