Есть ли способ показать вывод nethogs в conky?

1201
koogee

Я много искал, но я не могу найти способ показать сучков в conky. nethogs печатает на терминал, и, похоже, нет способа записать вывод в режиме реального времени. Это одна вещь, которую я хотел получить от conky FOR AGES.

5

2 ответа на вопрос

2
suprjami

I don't think so.

nethogs is an interactive process using the ncurses library. It expects to launch in a terminal window and get input from the user.

Conky can run programs using the exec/execi/execp/execpi directives, but these are supposed to be "run once" programs which output text then exit. Conky takes that text and displays it.

Try writing to the nethogs developer and see if he'll add "batched" mode, like the batched mode of the top command. If you could get nethogs to run for a second then display its text and exit, you could use that text output in Conky.

0
user269748

I've tried to do the same with conky on Ubuntu 12.10. But then i had a better idea:

  • create a new profile for gnome-terminal (transparent, small font size, whatever you like)
  • install package devilspie (you can also try the GTK version gdevilspie
  • create a new config file for devilspie which will help to get rid of the window frame border and menu

e.g. /home/<user>/.devilspie/gnome-terminal.ds

contents:

(if (is (window_role) "borderless") (begin (undecorate) (geometry "-0-0") (below) (skip_tasklist) ) ) 

(geometry "-0-0") will place the window at the bottom right

When the configuration file gnome-terminal.ds has not been written/changed you have to create it and stop/restart the devilspie deamon to see any changes. Dont forget to add the daemon to your startup scripts (XFCE: Setting > Session and Startup).

Now we need a startup bash script which you can add to your autostart just like devilspie. Something like this:

#!/bin/bash if [ $# -lt 1 ] then echo "Usage: `basename $0` <iface>" exit 1 fi killall -9 nethogs 2>/dev/null sleep 5 `sudo -H -u <username> gnome-terminal -e "/usr/bin/nethogs -d 4 $1" --profile=<profile-name> --role=borderless` exit 0 

You must pass an argument to the script to specify the target device. Notice that there is a sleep command within the script, just to make sure that previous nethogs processes are not running.

Красиво сделано. Кстати, у conky, кажется, есть опция `out_to_ncurses`, но я не играл с ней. koogee 10 лет назад 0