forked from luisfpg/argos-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.1s.py
executable file
·38 lines (32 loc) · 1.02 KB
/
net.1s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import psutil
import time
count = psutil.net_io_counters()
recv, sent = count.bytes_recv, count.bytes_sent
time.sleep(1)
count = psutil.net_io_counters()
recv, sent = count.bytes_recv - recv, count.bytes_sent - sent
stats = psutil.net_if_stats()
def size(bytes, high, medium):
suffix = 'B'
if bytes > 1024:
bytes /= 1024
suffix = 'K'
if bytes > 1024:
bytes /= 1024
suffix = 'M'
if bytes > 1024:
bytes /= 1024
suffix = 'G'
color = '#cc575d' if bytes > high else '#d19a66' \
if bytes > medium else '#68b382'
return "<span color='%s'>%3d%s</span>" % (color, bytes, suffix)
print("Net: %s↓ %s↑|font=monospace" %
(size(recv, 1000000, 500000), size(sent, 750000, 350000)))
print("---")
for key in stats:
print("%s (%s)|font=monospace"
% (key, 'up' if stats[key].isup else 'down'))
print("---")
print("Network connections|iconName=preferences-system-network-symbolic" +
" bash=nm-connection-editor terminal=false")