File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import psutil
2
+
3
+ # Get the current CPU usage
4
+ cpu_usage = psutil .cpu_percent ()
5
+
6
+ # Get the current memory usage
7
+ memory_usage = psutil .virtual_memory ().percent
8
+
9
+ # Get the current disk usage
10
+ disk_usage = psutil .disk_usage ("/" ).percent
11
+
12
+ # Get the network activity
13
+ # Get the current input/output data rates for each network interface
14
+ io_counters = psutil .net_io_counters (pernic = True )
15
+ for interface , counters in io_counters .items ():
16
+ print (f"Interface { interface } :" )
17
+ print (f" bytes sent: { counters .bytes_sent } " )
18
+ print (f" bytes received: { counters .bytes_recv } " )
19
+
20
+ # Get a list of active connections
21
+ connections = psutil .net_connections ()
22
+ for connection in connections :
23
+ print (f"{ connection .laddr } <-> { connection .raddr } ({ connection .status } )" )
24
+
25
+ # Print the collected data
26
+ print (f"CPU usage: { cpu_usage } %" )
27
+ print (f"Memory usage: { memory_usage } %" )
28
+ print (f"Disk usage: { disk_usage } %" )
You can’t perform that action at this time.
0 commit comments