-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys_info.py
182 lines (145 loc) · 5.83 KB
/
sys_info.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# sys_info ds ChRIS plugin app
#
# (c) 2021 Fetal-Neonatal Neuroimaging & Developmental Science Center
# Boston Children's Hospital
#
# http://childrenshospital.org/FNNDSC/
#
from chrisapp.base import ChrisApp
import os
import platform
Gstr_title = r"""
_ __
(_) / _|
___ _ _ ___ _ _ __ | |_ ___
/ __| | | / __| | | '_ \| _/ _ \
\__ \ |_| \__ \ | | | | | || (_) |
|___/\__, |___/ |_|_| |_|_| \___/
__/ | ______
|___/ |______|
"""
Gstr_synopsis = """
(Edit this in-line help for app specifics. At a minimum, the
flags below are supported -- in the case of DS apps, both
positional arguments <inputDir> and <outputDir>; for FS and TS apps
only <outputDir> -- and similarly for <in> <out> directories
where necessary.)
NAME
sys_info
SYNOPSIS
docker run --rm fnndsc/pl-sys_info sys_info \\
[-h] [--help] \\
[--json] \\
[--man] \\
[--meta] \\
[--savejson <DIR>] \\
[-v <level>] [--verbosity <level>] \\
[--version] \\
<inputDir> \\
<outputDir>
BRIEF EXAMPLE
* Bare bones execution
docker run --rm -u $(id -u) \
-v $(pwd)/in:/incoming -v $(pwd)/out:/outgoing \
fnndsc/pl-sys_info sys_info \
/incoming /outgoing
DESCRIPTION
`sys_info` ...
ARGS
[-h] [--help]
If specified, show help message and exit.
[--json]
If specified, show json representation of app and exit.
[--man]
If specified, print (this) man page and exit.
[--meta]
If specified, print plugin meta data and exit.
[--savejson <DIR>]
If specified, save json representation file to DIR and exit.
[-v <level>] [--verbosity <level>]
Verbosity level for app. Not used currently.
[--version]
If specified, print version number and exit.
"""
class Sys_info(ChrisApp):
"""
An app to display systen information
"""
PACKAGE = __package__
TITLE = 'An app to display systen information'
CATEGORY = ''
TYPE = 'ds'
ICON = '' # url of an icon image
MIN_NUMBER_OF_WORKERS = 1 # Override with the minimum number of workers as int
MAX_NUMBER_OF_WORKERS = 1 # Override with the maximum number of workers as int
MIN_CPU_LIMIT = 1000 # Override with millicore value as int (1000 millicores == 1 CPU core)
MIN_MEMORY_LIMIT = 200 # Override with memory MegaByte (MB) limit as int
MIN_GPU_LIMIT = 0 # Override with the minimum number of GPUs as int
MAX_GPU_LIMIT = 0 # Override with the maximum number of GPUs as int
# Use this dictionary structure to provide key-value output descriptive information
# that may be useful for the next downstream plugin. For example:
#
# {
# "finalOutputFile": "final/file.out",
# "viewer": "genericTextViewer",
# }
#
# The above dictionary is saved when plugin is called with a ``--saveoutputmeta``
# flag. Note also that all file paths are relative to the system specified
# output directory.
OUTPUT_META_DICT = {}
def define_parameters(self):
"""
Define the CLI arguments accepted by this plugin app.
Use self.add_argument to specify a new app argument.
"""
def run(self, options):
"""
Define the code to be run by this plugin app.
"""
print(Gstr_title)
print('Version: %s' % self.get_version())
# 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]
bogoinfo = [x.strip().split(":")[1] for x in info if "bogomips" in x]
for index, item in enumerate(cpuinfo):
print(" " + str(index) + ": " + item + " bogomips:" + bogoinfo[index])
# system
print("System: " + platform.system())
# distribution
#dist = platform.dist()
#dist = " ".join(x for x in dist)
print("Distribution: " + platform.version())
# 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")
def show_man_page(self):
"""
Print the app's man page.
"""
print(Gstr_synopsis)