forked from anuragrana/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_information.py
54 lines (42 loc) · 1.21 KB
/
system_information.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#
# Python script to fetch system information
# Author - ThePythonDjango.Com
# Tested with Python3 on Ubuntu 16.04
#
import platform
# Architecture
print("Architecture: " + platform.architecture()[0])
# machine
print("Machine: " + platform.machine())
# node
print("Node: " + platform.node())
# processor
print("Processors: ")
with open("/proc/cpuinfo", "r") as f:
info = f.readlines()
cpuinfo = [x.strip().split(":")[1] for x in info if "model name" in x]
for index, item in enumerate(cpuinfo):
print(" " + str(index) + ": " + item)
# system
print("System: " + platform.system())
# distribution
dist = platform.dist()
dist = " ".join(x for x in dist)
print("Distribution: " + dist)
# Load
with open("/proc/loadavg", "r") as f:
print("Average Load: " + f.read().strip())
# Memory
print("Memory Info: ")
with open("/proc/meminfo", "r") as f:
lines = f.readlines()
print(" " + lines[0].strip())
print(" " + lines[1].strip())
# uptime
uptime = None
with open("/proc/uptime", "r") as f:
uptime = f.read().split(" ")[0].strip()
uptime = int(float(uptime))
uptime_hours = uptime // 3600
uptime_minutes = (uptime % 3600) // 60
print("Uptime: " + str(uptime_hours) + ":" + str(uptime_minutes) + " hours")