-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_logs.5s.py
executable file
·105 lines (97 loc) · 7.08 KB
/
server_logs.5s.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /your/path/to/python
import subprocess
import plistlib
# Base64 encoded icon for displaying the built-in GPU
BUILTIN_GPU_ICON = ('iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJ'
'QAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD'
'0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1'
'sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAg'
'ICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0ia'
'HR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj'
'4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkR'
'GPgo8L3g6eG1wbWV0YT4KTMInWQAAA3JJREFUWAntlsmKFEEQhtt9X8cVlZHxKvgQend5HG+efAof'
'QRS9ztw9DvgAIigqMrjv6/dV1+9kTVdXV40gDPjD3xkVGRkZERlZ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FuO8ISbgCN6Dg/hntw/xnGLRuTDZtbCNbeMd'
'E3gXrqL13sdzV99wxU6KqIyEvBo18Mz45TSiFlvhikVUU9gOn22CZ8O2cbV+c3rv1b7sczyMZOzYskJV'
'odJzZCIeuOlwWavgXnuuPHe2cd/r4KoYo/A5PDO2cxWGwlXKX92+1pR97IUJdeQPNXVJ+LA8LXvxP2cy'
'HMhD6/U4/NOMaKHgapTiBOzbL8sDnb/ah89tFxNykidFrJgHby6cbb9GJJAd1LrObEVajvOVfZSfVU9t'
'su17Kuf76KlNUvevf+e9vnn6wf9pBf4BZd5O0exv758AAAAASUVORK5CYII=')
def main():
user_name = 'USERNAME'
instance_name = 'INSTANCENAME'
gpu_id = 0
cmd = "ssh {}@{} \'nvidia-smi\'".format(user_name, instance_name).split(" ")
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
tmp = proc.stdout.read()
upStatus = str(tmp).find('Could not resolve')
if upStatus == -1:
nameIdx = str(tmp).find("| {}".format(gpu_id)) + 6
name = str(tmp[nameIdx-9:nameIdx+10])[2:-1]
result = str(tmp[594:656])[2:]
logs = list(filter(lambda x: x != '', result.split()))
gpu_fan, gpu_temp, gpu_power_usage, gpu_power_cap, gpu_mem_usage, gpu_mem_cap, gpu_util = \
logs[0], logs[1], logs[3], logs[5], logs[7], logs[9], logs[11][:-1]
template_image_icon = PCIE_GPU_ICON
print('|templateImage={}'.format(PCIE_GPU_ICON))
print('---')
print('Connected to {}'.format(instance_name))
print('---')
print(name)
print('Fan: {}'.format(gpu_fan))
print('Temp: {}'.format(gpu_temp))
print('Power: {}/{}'.format(gpu_power_usage, gpu_power_cap))
print('Memory: {}/{}'.format(gpu_mem_usage, gpu_mem_cap))
print('Util: {}'.format(gpu_util))
else:
output = subprocess.check_output(["system_profiler", "-xml", "SPDisplaysDataType"])
plist = plistlib.readPlistFromBytes(output)
cards = [g for g in plist[0]['_items']]
gpu_in_use = [x for x in cards if 'spdisplays_ndrvs' in x][0]
if gpu_in_use['sppci_bus'] == 'spdisplays_builtin':
template_image_icon = BUILTIN_GPU_ICON
if gpu_in_use['sppci_bus'] == 'spdisplays_pcie_device':
template_image_icon = PCIE_GPU_ICON
print('| templateImage={}'.format(template_image_icon))
print('---')
print(gpu_in_use['sppci_model'])
if __name__ == '__main__':
main()