Skip to content

Commit 8bba34b

Browse files
Create SystemMonitoringScript.py
1 parent 92c353c commit 8bba34b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

SystemMonitoringScript.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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}%")

0 commit comments

Comments
 (0)