Skip to content

Commit 6e2eb2d

Browse files
committed
- Add support for fahrenheit
- Add support for chart/stats/path only report - Detect OS
1 parent faab332 commit 6e2eb2d

File tree

1 file changed

+131
-78
lines changed

1 file changed

+131
-78
lines changed

tmon/cli.py

Lines changed: 131 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""CLI script for tmon.
24
"""
35

46
import argparse
7+
import platform
58
import textwrap
69
import sys
710

@@ -19,16 +22,25 @@ def __call__(self, parser, namespace, values, option_string=None):
1922

2023

2124
def parse_args():
22-
description = (
23-
"Temperature Monitor (tmon v0.3.8) -- executes a program while\n"
24-
"monitoring CPU temperature, reporting the min, max and mean\n"
25-
"temperatures and plotting an ascii chart at the end to stderr.\n"
26-
"All signals are redirected to the program.\n"
27-
"If no program is passed, %(prog)s runs as expected returning on\n"
28-
"SIGINT (Ctrl-C).\n"
29-
"For full documentation check the repo: https://github.com/gmagno/tmon"
30-
)
25+
description = textwrap.dedent("""
26+
Temperature Monitor (tmon v0.3.8) -- executes a program while
27+
monitoring CPU temperature, reporting the min, max and mean
28+
temperatures and plotting an ascii chart at the end to stderr.
29+
All signals are redirected to the program.
30+
If no program is passed, %(prog)s runs as expected returning on
31+
SIGINT (Ctrl-C).
32+
For full documentation check the repo: https://github.com/gmagno/tmon
33+
""")
3134
epilog = textwrap.dedent("""
35+
/##
36+
| ##
37+
/###### /######/#### /###### /#######
38+
|_ ##_/ | ##_ ##_ ## /##__ ##| ##__ ##
39+
| ## | ## \ ## \ ##| ## \ ##| ## \ ##
40+
| ## /##| ## | ## | ##| ## | ##| ## | ##
41+
| ####/| ## | ## | ##| ######/| ## | ##
42+
\___/ |__/ |__/ |__/ \______/ |__/ |__/
43+
3244
return:
3345
%(prog)s returns when the child program exits, stops, or is
3446
terminated by a signal. The return value of %(prog)s is the return
@@ -38,84 +50,93 @@ def parse_args():
3850
$ %(prog)s echo How can a clam cram in a clean cream can
3951
How can a clam cram in a clean cream can
4052
41-
4253
===================
43-
Temp Monitor Report:
54+
Temp Monitor Report
4455
45-
Temp (°C) for a period of 0:00:00
46-
>> 53.0 °C <<
56+
min: 51.0 °C
57+
avg: 51.0 °C
58+
max: 51.0 °C
4759
48-
/tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
60+
raw: /tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
4961
===================
5062
5163
$ %(prog)s bash -c 'sleep 6; stress -c 4 -t 3; sleep 6'
52-
stress: info: [17832] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
53-
stress: info: [17832] successful run completed in 3s
54-
64+
stress: info: [30357] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
65+
stress: info: [30357] successful run completed in 3s
5566
5667
===================
57-
Temp Monitor Report:
58-
59-
Temp (°C) for a period of 0:00:15
60-
59.00 ┤
61-
58.67 ┤
62-
58.33 ┤
63-
58.00 ┤
64-
57.67 ┤ ╭─╮
65-
57.33 ┤ │ │
66-
57.00 ┤ │ │
67-
56.67 ┤ ╭╯ ╰╮
68-
56.33 ┤ │ │
69-
56.00 ┤ │ │
70-
55.67 ┼─╮ │ │
71-
55.33 ┤ │ │ │
72-
55.00 ┤ ╰───╯ ╰────╮
73-
54.67 ┤ │
74-
54.33 ┤ │
75-
54.00 ┤ ╰
76-
77-
/tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
68+
Temp Monitor Report
69+
70+
temp (°C) for a period of 0:00:15
71+
53.00 ┤
72+
52.67 ┤
73+
52.33 ┤
74+
52.00 ┤
75+
51.67 ┤ ╭─╮
76+
51.33 ┤ │ │
77+
51.00 ┤ │ │
78+
50.67 ┤ │ ╰╮
79+
50.33 ┤ │ │
80+
50.00 ┤ ╭╯ │
81+
49.67 ┤ │ │
82+
49.33 ┤ │ │
83+
49.00 ┼╮ ╭╮│ ╰─╮
84+
48.67 ┤│ │││ │
85+
48.33 ┤│ │││ │
86+
48.00 ┤╰──╯╰╯ ╰───
87+
88+
min: 48.0 °C
89+
avg: 49.1 °C
90+
max: 52.0 °C
91+
92+
raw: /tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
7893
===================
7994
80-
$ %(prog)s -y 5 -x 5 bash -c 'sleep 6; stress -c 4 -t 3; sleep 6'
81-
stress: info: [17181] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
82-
stress: info: [17181] successful run completed in 3s
83-
95+
$ %(prog)s -f -y 5 -x 5 bash -c 'sleep 6;stress -c 4 -t 3;sleep 6'
96+
stress: info: [31055] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
97+
stress: info: [31055] successful run completed in 3s
8498
8599
===================
86-
Temp Monitor Report:
100+
Temp Monitor Report
101+
102+
temp (°F) for a period of 0:00:15
103+
126.00 ┤
104+
124.50 ┤ ╭╮
105+
123.00 ┤ ╭╯│
106+
121.50 ┤ │ ╰╮
107+
120.00 ┼─╯ ╰
87108
88-
Temp (°C) for a period of 0:00:15
89-
60.00 ┤
90-
59.00 ┤ ╭╮
91-
58.00 ┼╮╭╯│
92-
57.00 ┤╰╯ │
93-
56.00 ┤ ╰─
109+
min: 120.2 °F
110+
avg: 122.2 °F
111+
max: 127.4 °F
94112
95-
/tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
113+
raw: /tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
96114
===================
97115
98116
$ %(prog)s -l 40 70 -x 10 -y 10 bash -c 'stress -c 4 -t 3; sleep 6'
99-
stress: info: [19677] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
100-
stress: info: [19677] successful run completed in 3s
101-
117+
stress: info: [853] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
118+
stress: info: [853] successful run completed in 3s
102119
103120
===================
104-
Temp Monitor Report:
105-
106-
Temp (°C) for a period of 0:00:09
107-
70.00 ┤
108-
66.67 ┤
109-
63.33 ┤
110-
60.00 ┤
111-
56.67 ┼───╮
112-
53.33 ┤ ╰─────
113-
50.00 ┤
114-
46.67 ┤
115-
43.33 ┤
116-
40.00 ┤
117-
118-
/tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
121+
Temp Monitor Report
122+
123+
temp (°C) for a period of 0:00:09
124+
70.00 ┤
125+
66.67 ┤
126+
63.33 ┤
127+
60.00 ┤
128+
56.67 ┤
129+
53.33 ┤
130+
50.00 ┼────╮ ╭
131+
46.67 ┤ ╰───╯
132+
43.33 ┤
133+
40.00 ┤
134+
135+
min: 49.0 °C
136+
avg: 50.6 °C
137+
max: 53.0 °C
138+
139+
raw: /tmp/tmon-YYYYMMDD@HHhMMmSS-XXXXXXXX.txt
119140
===================
120141
121142
copyright:
@@ -130,24 +151,44 @@ def parse_args():
130151
)
131152
parser.add_argument(
132153
"-v", "--version", required=False, action='store_true',
133-
help="Shows %(prog)s version."
154+
help="shows %(prog)s version"
155+
)
156+
parser.add_argument(
157+
"-f", "--fahrenheit", required=False, action='store_true',
158+
help="shows temperatures in °F instead of °C (the default)"
159+
)
160+
parser.add_argument(
161+
"-c", "--chart-only", required=False, action='store_true',
162+
help=(
163+
"only shows the temperature chart. Ignored if there is only one "
164+
"data point"
165+
)
166+
)
167+
parser.add_argument(
168+
"-s", "--stats-only", required=False, action='store_true',
169+
help="Only shows temperature stats"
134170
)
171+
parser.add_argument(
172+
"-p", "--path-only", required=False, action='store_true',
173+
help="only shows the path to raw data"
174+
)
175+
135176
parser.add_argument(
136177
"command", metavar='CMD', nargs=argparse.REMAINDER,
137178
help="Command args to run."
138179
)
139180
parser.add_argument(
140181
"-y", "--ysize", required=False, default=15, type=int,
141-
help="Y-axis size in number terminal characters", action=AxisSizeAction
182+
help="y-axis size in number terminal characters", action=AxisSizeAction
142183
)
143184
parser.add_argument(
144185
"-x", "--xsize", required=False, default=70, type=int,
145-
help="X-axis size in number terminal characters", action=AxisSizeAction
186+
help="x-axis size in number terminal characters", action=AxisSizeAction
146187
)
147188
parser.add_argument(
148189
"-l", "--ylim", nargs=2, required=False, metavar=('MIN', 'MAX'),
149190
type=float, help=(
150-
"Y-axis view limits with min and max values. It is ignored if the "
191+
"y-axis view limits with min and max values. It is ignored if the "
151192
"measured temperatures fall outside the specified range."
152193
)
153194
)
@@ -156,15 +197,27 @@ def parse_args():
156197

157198

158199
def main():
159-
args = parse_args()
160-
if args['version']:
200+
kwargs = parse_args()
201+
if kwargs['version']:
161202
print("Temperature Monitor -- tmon v0.3.8")
162203
return 0
163-
t = tmon.TMon(
164-
config={k: args[k] for k in args if k in ['ysize', 'xsize', 'ylim']}
204+
205+
if platform.system() != 'Linux':
206+
print(textwrap.dedent("""
207+
You seem to be running a non linux operating system. tmon is a
208+
proud-to-be-linux-only tool, {} is not supported and will
209+
probably never be. Please take the next step for a better tech
210+
life and download a real operating system :)
211+
https://mirrors.kernel.org/
212+
""".format(platform.system())))
213+
return 1
214+
215+
return tmon.run(
216+
cmd=kwargs['command'],
217+
xsize=kwargs['xsize'], ysize=kwargs['ysize'], ylim=kwargs['ylim'],
218+
fahrenheit=kwargs['fahrenheit'], stats_only=kwargs['stats_only'],
219+
chart_only=kwargs['chart_only'], path_only=kwargs['path_only']
165220
)
166-
ret = t.run(args['command'])
167-
return ret
168221

169222

170223
if __name__ == "__main__":

0 commit comments

Comments
 (0)