File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import argparse
2
+ import sys
3
+ import socket
4
+ import psutil
5
+
6
+ def python_version ():
7
+ return sys .version_info
8
+
9
+ def ip_addresses ():
10
+ hostname = socket .gethostname ()
11
+ addresses = socket .getaddrinfo (hostname , None )
12
+
13
+ address_info = []
14
+ for address in addresses :
15
+ address_info .append ((address [0 ].name , address [4 ][0 ]))
16
+ return address_info
17
+
18
+ def cpu_load ():
19
+ return psutil .cpu_percent (interval = 0.1 )
20
+
21
+ def ram_available ():
22
+ return psutil .virtual_memory ().available
23
+
24
+ def ac_connected ():
25
+ return psutil .sensors_battery ().power_plugged
26
+
27
+ def show_sensors ():
28
+ print ("Python Version:{0.major}.{0.minor}" .format (python_version ()))
29
+ for address in ip_addresses ():
30
+ print ("IP Addresses: {0[1]} ({0[0]})" .format (address ))
31
+ print ("CPU Load: {:.1f}" .format (cpu_load ()))
32
+ print ("RAM Available: {} MiB" .format (ram_available () / 1024 ** 2 ))
33
+ print ("AC Connected: {}" .format (ac_connected ()))
34
+
35
+ def command_line (argv ):
36
+ parser = argparse .ArgumentParser (
37
+ description = 'Display the values of the sensors' ,add_help = True ,
38
+ )
39
+ arguments = parser .parse_args ()
40
+ show_sensors ()
41
+
42
+ if __name__ == '__main__' :
43
+ command_line (sys .argv )
You can’t perform that action at this time.
0 commit comments