-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatsE16.py
More file actions
55 lines (47 loc) · 1.48 KB
/
statsE16.py
File metadata and controls
55 lines (47 loc) · 1.48 KB
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
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import platform
import requests
import shutil
import subprocess
import sys
import datetime
import psutil
import platform
from urllib.parse import urlparse
__all__ = ["statsE16"]
def get_server_info():
"""Gets network metadata for the machine calling the function.
see http://ipinfo.io for more info.
Returns:
dict: A dictionary with keys ip, hostname, city, region, country, loc, org, postal
"""
uri = 'http://ipinfo.io'
raw = requests.get(uri)
data = raw.json()
return data
def statsE16():
""" Gets stats about the device.
Raises:
ValueError: if the location info or local device info cannot be discovered.
Returns:
dict: A dictionary containing device info.
"""
info = {
'server': get_server_info(),
'cpu_count': psutil.cpu_count(),
'cpu_used_percent': psutil.cpu_percent(interval=1),
'memory_total': psutil.virtual_memory().total,
'memory_used_percent': psutil.virtual_memory().percent,
'disk_total': psutil.disk_usage('/').total,
'disk_used_percent': psutil.disk_usage('/').percent,
'platform_system': platform.system(),
'platform_release': platform.release(),
'platform_dist': platform.dist()[0] + " " + platform.dist()[1]
}
return info
if __name__ == '__main__':
data = statsE16()
formatted_data = json.dumps(data, indent=4, sort_keys=True)
print(formatted_data)