forked from enderek/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbg
executable file
·112 lines (92 loc) · 1.85 KB
/
tbg
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
#!/usr/bin/perl -w
use strict;
use warnings;
# simple txt bar graph
# (c) by Ender <[email protected]> 2010
# changelog:
# 2012-02-18 added support for "time value" input
# read from stdin or as parameters
# todo:
# parameters (width etc., autoscaling, terminal size)
my $localmax = 10;
my $localmin = 0;
my $max=0;
my $min=100000000;
my $step=1;
my @vals;
# help
if(defined($ARGV[0]) && ($ARGV[0] eq '-h' || $ARGV[0] eq '--help')){
print qq{$0 (txt bar graph) by Ender
under GPL v2
Usage:
$0 arg1 arg2 arg3 ... argN
or
redirect "time val" to tbg | $0
args - numbers
example:
ldavg-1
sar -q | awk '{print \$4}' | perl tbg
or (time val format)
sar -q | awk '{print \$1," ",\$4}' | perl tbg
};
exit;
};
if(defined @ARGV){
@vals=@ARGV;
}
else{
@vals=<>;
};
my @time_arr;
my @val_arr;
for my $val (@vals){
$val =~ s/,/./;
$val =~ s/\n//;
my $time = '';
# detect time:
if($val =~ /(^[0-9:]*\.*[0-9:]+)\s+([+-]?[0-9]*\.*[0-9]+)/){
$time = $1;
$val = $2;
push @time_arr, $time;
};
if($val =~ /^[+-]?[0-9]*\.*[0-9]+$/){
$max=$val if $val>$max;
$min=$val if $val<$min;
}
else{
$val='';
};
push @val_arr,$val;
};
$step=($max-$min)/$localmax;
print "Max: $max\tStep: $step\n";
for(my $i=$max;$i>$min;$i=$i-$step){
for(@val_arr){
next if $_ eq '';
print "#" if $_>=$i;
print "." if $_<$i;
};
printf "\t\t %.2f\n",$i;
};
for(my $i=0;$i<9;$i=$i+1){
for(@time_arr){
if(length($_)>$i){
print substr($_,$i,1);
}
else{
print " ";
};
};
print $/;
};
#for(@vals){
# print "#" if $_ ne '';
#};
#
#printf "\t\t %.2f\n",$min;
print $/;
print "Min: $min\n";
=eat
this software is licensed under the GNU General Public License version 2. For the
full license information, please visit http://www.gnu.org/copyleft/gpl.html
=cut