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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
package Loadbars::HelpDispatch;
use strict;
use warnings;
use Loadbars::Constants;
use Loadbars::Shared;
sub create () {
my $hosts = '';
my $textdesc = <<END;
CPU stuff:
st = Steal in % [see man proc] (extended)
Color: Red
gt = Guest in % [see man proc] (extended)
Color: Red
sr = Soft IRQ usage in % (extended)
Color: White
ir = IRQ usage in % (extended)
Color: White
io = IOwait cpu sage in %
Color: Purple
id = Idle cpu usage in % (extended)
Color: Black
ni = Nice cpu usage in %
Color: Green
us = User cpu usage in %
Color: Yellow, dark yellow if to>50%, orange if to>50%
sy = System cpu sage in %
Blue, lighter blue if >30%
to = Total CPU usage, which is (100% - id)
pk = Max us+sy peak of last avg. samples (extended)
avg = System load average; desc. order: 1, 5 and 15 min. avg.
1px horizontal line: Maximum sy+us+io of last 'avg' samples (extended)
Extended means: text display only if extended mode is turned on
Memory stuff:
Ram: System ram usage in %
Color: Dark grey
Swp: System swap usage in %
Color: Grey
Config file support:
Loadbars tries to read ~/.loadbarsrc and it's possible to configure any
option you find in --help but without leading '--'. For comments just use
the '#' sign. Sample config:
showcores=1 # Always show cores on startup
showtext=0 # Always don't display text on startup
extended=1 # Always use extended mode on startup
will always show all CPU cores in extended mode but no text display.
Examples:
loadbars --extended 1 --showcores 1 --height 300 --hosts localhost
loadbars --hosts localhost,server1.example.com,server2.example.com
loadbars --cluster foocluster (foocluster is in /etc/clusters [ClusterSSH])
END
# mode 1: Option is shown in the online help menu (stdout not sdl)
# mode 2: Option is shown in the 'usage' screen from the command line
# mode 4: Option is used to generate the GetOptions parameters for Getopt::Long
# Combinations: Like chmod(1)
my %d = (
cpuaverage => {
menupos => 3,
help => 'Num of cpu samples for avg. (more fluent animations)',
mode => 6,
type => 'i'
},
cpuaverage_hot_up => {
menupos => 4,
cmd => 'a',
help => 'Increases number of cpu samples for calculating avg. by 1',
mode => 1
},
cpuaverage_hot_dn => {
menupos => 5,
cmd => 'y',
help => 'Decreases number of cpu samples for calculating avg. by 1',
mode => 1
},
netaverage => {
menupos => 6,
help => 'Num of net samples for avg. (more fluent animations)',
mode => 6,
type => 'i'
},
netaverage_hot_up => {
menupos => 7,
cmd => 'd',
help => 'Increases number of net samples for calculating avg. by 1',
mode => 1
},
netaverage_hot_dn => {
menupos => 8,
cmd => 'c',
help => 'Decreases number of net samples for calculating avg. by 1',
mode => 1
},
netint => {
menupos => 6,
help => 'Interface to show netstats for (default: eth0)',
mode => 6,
type => 's'
},
netlink => {
menupos => 6,
help =>
'Force interface link speed (mbit, 10mbit, 100mbit, gbit, 10gbit or mbytes/s number',
mode => 6,
type => 's'
},
netlink_hot_up => {
menupos => 9,
cmd => 'f',
help => 'Doubles net interface link speed reference',
mode => 1
},
netlink_hot_dn => {
menupos => 10,
cmd => 'v',
help => 'Halfs net interface link speed reference',
mode => 1
},
barwidth => {
menupos => 11,
help => 'Set bar width',
mode => 6,
type => 'i'
},
windowwidth_hot_up => {
menupos => 90,
help => 'Increase window width by 100px',
cmd => 'right',
mode => 1,
},
windowwidth_hot_dn => {
menupos => 91,
help => 'Decrease window width by 100px',
cmd => 'left',
mode => 1,
},
windowheight_hot_up => {
menupos => 92,
help => 'Increase window height by 100px',
cmd => 'down',
mode => 1,
},
windowheight_hot_dn => {
menupos => 93,
help => 'Decrease window height by 100px',
cmd => 'up',
mode => 1,
},
cluster => {
menupos => 6,
help => 'Cluster name from /etc/clusters',
var => \$C{cluster},
mode => 6,
type => 's'
},
configuration => {
menupos => 6,
cmd => 'c',
help => 'Show current configuration',
mode => 4
},
extended => {
menupos => 6,
help => 'Toggle extended display (0 or 1)',
mode => 7,
type => 'i'
},
extended_hot => {
menupos => 23,
cmd => 'e',
help => 'Toggle extended mode',
mode => 1
},
factor => {
menupos => 7,
help => 'Set graph scale factor (1.0 means 100%)',
mode => 6,
type => 's'
},
factor_hot_up => {
menupos => 12,
cmd => 's',
help => 'Increases graph scale factor by 0.1',
mode => 1
},
factor_hot_dn => {
menupos => 13,
cmd => 'x',
help => 'Decreases graph scale factor by 0.1',
mode => 1
},
hasagent => {
menupos => 10,
help => 'SSH key is already known by the SSH agent (0 or 1)',
mode => 6,
type => 'i'
},
height => {
menupos => 10,
help => 'Set windows height',
mode => 6,
type => 'i'
},
help_hot => {
menupos => 11,
cmd => 'h',
help => 'Prints this help screen',
mode => 1
},
hosts => {
menupos => 12,
help =>
'Comma sep. list of hosts; optional: user@ in front to each host',
var => \$hosts,
mode => 6,
type => 's'
},
maxwidth => {
menupos => 16,
help => 'Set max width',
mode => 6,
type => 'i'
},
quit_hot => { menupos => 16, cmd => 'q', help => 'Quits', mode => 1 },
writeconfig_hot => {
menupos => 16,
cmd => 'w',
help => 'Write config to config file',
mode => 1
},
showcores => {
menupos => 17,
help => 'Toggle core display (0 or 1)',
mode => 7,
type => 'i'
},
showcores_hot =>
{ menupos => 17, cmd => '1', help => 'Toggle show cores', mode => 1 },
showmem => {
menupos => 17,
help => 'Toggle mem display (0 or 1)',
mode => 7,
type => 'i'
},
showmem_hot =>
{ menupos => 17, cmd => 'm', help => 'Toggle show mem', mode => 1 },
shownet => {
menupos => 17,
help => 'Toggle net display (0 or 1)',
mode => 7,
type => 'i'
},
shownet_hot =>
{ menupos => 17, cmd => 'n', help => 'Toggle show net', mode => 1 },
showtexthost => {
menupos => 18,
help => 'Toggle hostname/num text display (0 or 1)',
mode => 7,
type => 'i'
},
showtexthost_hot => {
menupos => 18,
cmd => 'u',
help => 'Toggle hostname/num text display',
mode => 1
},
showtext => {
menupos => 19,
help => 'Toggle text display (0 or 1)',
mode => 7,
type => 'i'
},
showtext_hot => {
menupos => 19,
cmd => 't',
help => 'Toggle text display',
mode => 1
},
sshopts =>
{ menupos => 20, help => 'Set SSH options', mode => 6, type => 's' },
title => {
menupos => 21,
help => 'Set title bar text',
mode => 6,
type => 's'
},
);
my %d_by_short = map {
$d{$_}{cmd} => $d{$_}
} grep {
exists $d{$_}{cmd}
} keys %d;
my $closure = sub ($;$) {
my ( $arg, @rest ) = @_;
if ( $arg eq 'command' ) {
my ( $cmd, @args ) = @rest;
my $cb = $d{$cmd};
$cb = $d_by_short{$cmd} unless defined $cb;
unless ( defined $cb ) {
system $cmd;
return 0;
}
if ( length $cmd == 1 ) {
for my $key ( grep { exists $d{$_}{cmd} } keys %d ) {
do { $cmd = $key; last } if $d{$key}{cmd} eq $cmd;
}
}
}
elsif ( $arg eq 'hotkeys' ) {
$textdesc . "Hotkeys:\n" . (
join "\n",
map {
"$_\t- $d_by_short{$_}{help}"
} grep {
$d_by_short{$_}{mode} & 1 and exists $d_by_short{$_}{help};
} sort { $d_by_short{$a}{menupos} <=> $d_by_short{$b}{menupos} }
sort keys %d_by_short
);
}
elsif ( $arg eq 'usage' ) {
$textdesc . (
join "\n",
map {
if ( $_ eq 'help' )
{
"--$_\t\t- $d{$_}{help}";
}
else {
"--$_ <ARG>\t- $d{$_}{help}";
}
} grep {
$d{$_}{mode} & 2
and exists $d{$_}{help}
} sort { $d{$a}{menupos} <=> $d{$b}{menupos} } sort keys %d
);
}
elsif ( $arg eq 'options' ) {
map {
"$_="
. $d{$_}{type} => (
defined $d{$_}{var}
? $d{$_}{var}
: \$C{$_}
);
} grep {
$d{$_}{mode} & 4 and exists $d{$_}{type};
} sort keys %d;
}
};
$d{configuration}{cb} = sub {
Loadbars::Main::say sort map {
"$_->[0] = $_->[1]"
} grep {
defined $_->[1]
} map {
[
$_ => exists $d{$_}{var}
? ${ $d{$_}{var} }
: $C{$_}
]
} keys %d;
};
return ( \$hosts, $closure );
}
1;
|