You are not logged in.

#1 2016-01-02 12:28:53

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 398
Website

Hardware monitor graphs for the system tray (CPU, memory etc)

I put together a small python script to display CPU/memory/network/disk-io graphs in the system tray.

Screenshot:
phwmon.png

Link to the script: https://gitlab.com/o9000/phwmon/blob/master/phwmon.py

Install dependencies with:

sudo apt-get install python-gtk2 python-psutil

Usage:

chmod +x phwmon.py
./phwmon.py

Documentation:

./phwmon.py --help
usage: phwmon.py [-h] [--cpu] [--core] [--mem] [--net] [--io] [--size SIZE]
                 [--bg BG] [--fg_cpu FG_CPU] [--fg_mem FG_MEM]
                 [--fg_net FG_NET] [--fg_io FG_IO]

optional arguments:
  -h, --help       show this help message and exit
  --cpu            Show a CPU activity graph
  --core           Show a CPU activity graph for each logical CPU core
  --mem            Show a memory usage graph
  --net            Show a network usage graph
  --io             Show a disk I/O graph
  --size SIZE      Icon size in pixels. Default: 22.
  --bg BG          Background color (RGBA hex). Default: #00000077.
  --fg_cpu FG_CPU  CPU graph color (RGBA hex). Default: #3f3.
  --fg_mem FG_MEM  CPU graph color (RGBA hex). Default: #ff3.
  --fg_net FG_NET  CPU graph color (RGBA hex). Default: #33f.
  --fg_io FG_IO    CPU graph color (RGBA hex). Default: #3ff.

P.S. Happy New Year!

Offline

#2 2016-01-04 00:32:55

seppalta
Member
Registered: 2015-10-02
Posts: 41
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Potentially a nice script, but I only get the tooltip information for Network and Hard Drives.  No graphs.  Am I missing a sensor, or what?

Offline

#3 2016-01-04 01:43:57

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 398
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

The icons are just blank (gray)?

Edit:
Most of the time, the network and disk activity icons are empty for me too, simply because there is no activity.

But the CPU and memory graphs should display something. What happens if you run the program 'stress -c 1'?

Last edited by o9000 (2016-01-04 01:49:13)

Offline

#4 2016-01-04 02:25:36

seppalta
Member
Registered: 2015-10-02
Posts: 41
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Yes, the CPU and Memory are fine, and I'm not surprised that the disc activity registers as 0.  However, the network can be very active (streaming radio - my Conky indicator is maxed out), but nothing is being picked up by the network graph in the tray.

$ stress -c 1
stress: info: [4258] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd

Last edited by seppalta (2016-01-04 02:33:39)

Offline

#5 2016-01-04 11:09:43

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 398
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

I added two more parameters to set a custom scale for the network and disk I/O graphs:

  --net_scale NET_SCALE
                        Maximum value for the network usage graph, in Mbps.
                        Default: 40.

  --io_scale IO_SCALE   Maximum value for the disk I/O graph, in MB/s.
                        Default: 100.

The value specified there will be the maximum value that can be shown by the graph. For instance, currently the network graph is full at 40 Mb/s of traffic (that is 5 MB/s). Since the graph is 22 pixels high, a pixel shows about 2 Mb/s of traffic. If you have less than that, the graph will be empty.

I think this is what happens in your case, so try lowering the scale, to e.g. 10 Mb/s or whatever your Internet subscription offers:

./phwmon.py --net_scale 10

Offline

#6 2016-01-04 20:14:02

seppalta
Member
Registered: 2015-10-02
Posts: 41
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Thanks.  That solved the problem.  Great script. 

Now, how about a script for launching the openbox pcmanfm-bookmarks.pl pipe from the tray?

Offline

#7 2016-01-04 20:25:51

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,733

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Nice, thanks for sharing.
nice.jpg

Offline

#8 2016-08-24 06:59:49

matmutant
Member
Registered: 2016-07-19
Posts: 39
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Thank you very much for that script,
I forked it to get easy access if i ever need to re-install from scratch my BL
(https://github.com/matmutant/Bunsenlabs-UserConfig)

I used the following args :

./phwmon.py --cpu --mem --fg_mem 555 --fg_cpu d00

phwmon custom config

Offline

#9 2018-01-20 14:45:23

thierrybo
Member
Registered: 2017-11-12
Posts: 10

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Hi,

I just discover your script as I just ditched one month ago my ten years Gnome use for Openbox :-)

As I am not fond of Conky, I like not having to show desktop to have a look at my system, so your script is perfect for that.

I just would like to have an option to show Text instead of graph (or text on top of the graph). For example I would like to see "1.21 Gb" onto memory graph, without having to move constantly the mouse to show the tooltip.

Offline

#10 2018-01-20 17:46:07

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 398
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

I'm using PyGtk to show the icon, adding text like that won't work.

You can use a tint2 executor instead, which shows the output of a command, executed every n seconds. The following command will print the amount of memory in use:

grep -E 'MemAvailable:|MemTotal:' /proc/meminfo | awk '{ print $2 }' | paste -sd ' ' - | awk '{printf("Used: %.1f GB %.0f%%", ($1 - $2) / 1024 / 1024, ($1 - $2)/$1*100);}'

Offline

#11 2018-01-20 22:27:10

thierrybo
Member
Registered: 2017-11-12
Posts: 10

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Ok, thanks, I will use both graph and executors. I was just exploring executors as well for a textual output. I end up  with a more simple command that fit my needs :

free -m | awk '/Mem:/ { print $1 " " $3+$5 " MB"}'

at least the result is the same as htop. Don't know what your command exactly do, but the memory used is 1.4 higher.

Offline

#12 2018-01-20 22:56:26

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 398
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

thierrybo wrote:

Don't know what your command exactly do, but the memory used is 1.4 higher.

See https://git.kernel.org/pub/scm/linux/ke … 722c9da773

Offline

#13 2019-02-17 16:26:17

thierrybo
Member
Registered: 2017-11-12
Posts: 10

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Hi,

phwmon suddenly fails since yesterday, any idea?

phwmon.py
Traceback (most recent call last):
  File "/home/thierrybo/bin/phwmon.py", line 341, in <module>
    HardwareMonitor()
  File "/home/thierrybo/bin/phwmon.py", line 128, in __init__
    self.initDiskIo()
  File "/home/thierrybo/bin/phwmon.py", line 274, in initDiskIo
    v = psutil.disk_io_counters(perdisk=False)
  File "/usr/lib/python2.7/dist-packages/psutil/__init__.py", line 1981, in disk_io_counters
    rawdict = _psplatform.disk_io_counters()
  File "/usr/lib/python2.7/dist-packages/psutil/_pslinux.py", line 988, in disk_io_counters
    raise ValueError("not sure how to interpret line %r" % line)
ValueError: not sure how to interpret line '   8      32 sdc 127 0 8348 660 0 0 0 0 0 632 648 0 0 0 0\n'

Offline

#14 2019-02-18 21:36:32

thierrybo
Member
Registered: 2017-11-12
Posts: 10

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

I found the solution. The problem appeared after I upgraded my kernel from 4.9 to 4.18 and 4.19.

There is a bug reported in python:

disk_io_counters() fails on Linux kernel 4.18+ (#1360)
Linux kernel 4.18+ added 4 fields, ignore them and parse the rest as
usual.

For Python 2.7 you have to edit one line of code, the two others are comments :

--- /usr/lib/python2.7/dist-packages/psutil/_pslinux-bak.py
+++ /usr/lib/python2.7/dist-packages/psutil/_pslinux.py
@@ -963,6 +963,8 @@
         # ...unless (Linux 2.6) the line refers to a partition instead
         # of a disk, in which case the line has less fields (7):
         # "3    1   hda1 8 8 8 8"
+        # 4.18+ has 4 fields added:
+        # "3    0   hda 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0"
         # See:
         # https://www.kernel.org/doc/Documentation/iostats.txt
         # https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
@@ -974,7 +976,7 @@
             reads = int(fields[2])
             (reads_merged, rbytes, rtime, writes, writes_merged,
                 wbytes, wtime, _, busy_time, _) = map(int, fields[4:14])
-        elif fields_len == 14:
+        elif fields_len == 14 or fields_len == 18:
             # Linux 2.6+, line referring to a disk
             name = fields[2]

Offline

#15 2019-02-18 21:40:05

malm
jgmenu developer
Registered: 2016-10-13
Posts: 330
Website

Re: Hardware monitor graphs for the system tray (CPU, memory etc)

Good effort!

Offline

Board footer

Powered by FluxBB