Thank you for tips and solution. I was going to experiment by myself but I
I'm going to try your solution. Thank you. Best.

On Sat, Oct 24, 2020, 09:05 elParaguayo <[email protected]> wrote:

> This is untested but should work. You need to edit the get_stats function
> of the net widget.
>
>     def get_stats(self):
>         interfaces = {}
>         if self.interface == ["all"]:
>             net = psutil.net_io_counters(pernic=False)
>             interfaces["all"] = {'down': net[1], 'up': net[0]}
>             return interfaces
> *        elif self.interface == ["all_active"]:*
> *            nics = pustil.net_if_stats()*
> *            active = [nic for nic in nics if nics[nic].isup]*
> *            net = psutil.net_io_counters(pernic=True)*
> *            for iface in active:*
> *                down = net[iface].bytes_recv*
> *                up = net[iface].bytes_sent*
> *                interfaces[iface] = {'down': down, 'up': up}*
> *            return interfaces*
>         else:
>             net = psutil.net_io_counters(pernic=True)
>             for iface in net:
>                 down = net[iface].bytes_recv
>                 up = net[iface].bytes_sent
>                 interfaces[iface] = {'down': down, 'up': up}
>             return interfaces
>
> You'll see that I've added an option for "all_active". This includes all
> connected interfaces but will include the loopback device so you may want
> to add a line to remove it.
> On Friday, 23 October 2020 at 07:16:42 UTC+1 elParaguayo wrote:
>
>> Actually, using psutil.net_if_stats() (
>> https://psutil.readthedocs.io/en/latest/#psutil.net_if_stats) will let
>> you see which interfaces are connected. You can then use those names to
>> display stats for the active interfaces.
>>
>> On Thu, 22 Oct 2020, 15:24 el Paraguayo, <[email protected]> wrote:
>>
>>> That's not quite how it works.
>>>
>>> When you use the 'all' interface name, the widget uses the psutil module
>>> to get the io data but passes pernic=False (i.e. all NICs are aggregated -
>>> giving you the active numbers).
>>>
>>> If you set pernic=True then you'll include inactive NICs.
>>>
>>> You'd need to modify the widget code to only show NICs that have some
>>> activity (and maybe include some method to remember past activity in a
>>> certain period so interfaces didn't constantly appear or disappear). Psutil
>>> does also have net_connections which might give you what you need to filter
>>> active connections.
>>>
>>> Is there a problem with naming your interfaces in the config.py file?
>>>
>>> On Thu, 22 Oct 2020, 12:05 Artur, <[email protected]> wrote:
>>>
>>>> yes, but the name of the interface in that case is "all".
>>>> But I would expect the name of the active interface displayed.
>>>> If more than one interface is active then, I'd like to see each
>>>> separately.
>>>>
>>>> Is it possible to achieve?
>>>>
>>>> On Thu, 22 Oct 2020 at 12:50, Guillaume Gelin <[email protected]> wrote:
>>>>
>>>>> Hi Artur,
>>>>>
>>>>> IIRC this is the default behavior when you don't provide an
>>>>> "interface" argument.
>>>>>
>>>>> Le jeu. 22 oct. 2020 à 12:47, Artur <[email protected]> a écrit :
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Could you advice how I could display only active net interface in the
>>>>>> bar in Net Widget?
>>>>>>
>>>>>>
>>>>>> Best
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "qtile-dev" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/qtile-dev/70e08e17-d227-4d46-a7ed-8db5f76abf32n%40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/qtile-dev/70e08e17-d227-4d46-a7ed-8db5f76abf32n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Guillaume Gelin
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the
>>>>> Google Groups "qtile-dev" group.
>>>>> To unsubscribe from this topic, visit
>>>>> https://groups.google.com/d/topic/qtile-dev/TGQS79EDjXE/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>> [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/qtile-dev/CAPn4x%2BooUjAQk2xu466zf2ZrNPT4%3DJVYZ%3D%3Dt1ePFP2%2BbbMzbbg%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/qtile-dev/CAPn4x%2BooUjAQk2xu466zf2ZrNPT4%3DJVYZ%3D%3Dt1ePFP2%2BbbMzbbg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "qtile-dev" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/qtile-dev/CAGudEj4GVNp40xpaM_mx7bCrq0PG0PbYnuQZEoBzNP5ATtVrZw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/qtile-dev/CAGudEj4GVNp40xpaM_mx7bCrq0PG0PbYnuQZEoBzNP5ATtVrZw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "qtile-dev" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/qtile-dev/TGQS79EDjXE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/qtile-dev/f7733edb-b4de-4841-973d-d99d007c4776n%40googlegroups.com
> <https://groups.google.com/d/msgid/qtile-dev/f7733edb-b4de-4841-973d-d99d007c4776n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/qtile-dev/CAGudEj4KOFkNAQxB2ba%2B9s5KTxWENZ85138n-CEY52Gm_s4Y9g%40mail.gmail.com.

Reply via email to