Added POD and comments to top_n.
Added script sensorstemmpplot.
This commit is contained in:
parent
16c6001409
commit
d1284de05d
|
@ -0,0 +1,66 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
sensorstempplot - plot temperatures from (lm_)sensors output
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
This program expects output from lm_sensors where each line is prepended
|
||||||
|
with a timestamp, like this:
|
||||||
|
|
||||||
|
2006-07-22T15:52:01 adm1023-i2c-0-18
|
||||||
|
2006-07-22T15:52:01 Adapter: SMBus I801 adapter at 1100
|
||||||
|
2006-07-22T15:52:01 Board: +33°C (low = -55°C, high = +127°C)
|
||||||
|
2006-07-22T15:52:01 CPU: +35°C (low = -55°C, high = +127°C)
|
||||||
|
2006-07-22T15:52:01
|
||||||
|
2006-07-22T15:52:01 max1617-i2c-0-1a
|
||||||
|
2006-07-22T15:52:01 Adapter: SMBus I801 adapter at 1100
|
||||||
|
2006-07-22T15:52:01 Board: +37°C (low = -55°C, high = +127°C)
|
||||||
|
2006-07-22T15:52:01 CPU: +40°C (low = -55°C, high = +127°C)
|
||||||
|
2006-07-22T15:52:01
|
||||||
|
|
||||||
|
Note that there are two lines for "Board" and "CPU" temperature with
|
||||||
|
different values. We distinguish them by noting the section identifier
|
||||||
|
and prepending it to the series names.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use TimeSeries;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
binmode STDOUT, ':raw';
|
||||||
|
|
||||||
|
my %series;
|
||||||
|
my $ns;
|
||||||
|
my %data;
|
||||||
|
|
||||||
|
my $ts = TimeSeries->new();
|
||||||
|
my $section = "";
|
||||||
|
while (<>) {
|
||||||
|
chomp;
|
||||||
|
if (/^[-0-9T:]* ([\w-]+)$/) {
|
||||||
|
$section = $1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
if (/^([-0-9T:]*) ([\w-]+):\s+([+-]?[0-9.]*)°C /) {
|
||||||
|
my ($timestamp, $series, $value) = ($1, "$section $2", $3);
|
||||||
|
$series{$series} = ++$ns unless ($series{$series});
|
||||||
|
$data{$timestamp}{$series} = $value;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my @series = sort { $series{$a} <=> $series{$b} } keys %series;
|
||||||
|
$ts->legend(@series);
|
||||||
|
$ts->legend_position("below");
|
||||||
|
$ts->stacked(0);
|
||||||
|
$ts->output_format('ps');
|
||||||
|
for my $timestamp (sort keys %data) {
|
||||||
|
my %d = %{$data{$timestamp}};
|
||||||
|
my @values = @d{@series};
|
||||||
|
$ts->add_timestring($timestamp, @values);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $g = $ts->plot();
|
||||||
|
print $g
|
43
top_n
43
top_n
|
@ -1,6 +1,39 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
top_n - get top n (of many) time series
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
top_n n f v
|
||||||
|
|
||||||
|
This script expects a file in tab-separated format containing all series mixed together in
|
||||||
|
"normalized" or "vertical" format,
|
||||||
|
e.g.,
|
||||||
|
|
||||||
|
2006-07-22T20:00:00 Wien/Innere Stadt 31.5
|
||||||
|
2006-07-22T20:00:00 Wien/Hohe Warte 29.5
|
||||||
|
2006-07-22T21:00:00 Wien/Innere Stadt 30.9
|
||||||
|
2006-07-22T21:00:00 Wien/Hohe Warte 27.9
|
||||||
|
2006-07-22T22:00:00 Wien/Innere Stadt 30.1
|
||||||
|
2006-07-22T22:00:00 Wien/Hohe Warte 26.2
|
||||||
|
...
|
||||||
|
|
||||||
|
n is the number of time series to extract.
|
||||||
|
|
||||||
|
f is the number of the column with the series names, starting at 0. In the example above, this would be 1.
|
||||||
|
|
||||||
|
v is the number of the column with values to be used for sorting. In the example above, this would be 2
|
||||||
|
(there is only one column with values in this example).
|
||||||
|
|
||||||
|
All values for a given series are added, and the the n series with the highest sum are selected.
|
||||||
|
Finally all records from the selected series and an additional series "OTHER" representing the sum
|
||||||
|
of all other series are printed.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
my $n = shift;
|
my $n = shift;
|
||||||
my $f = shift;
|
my $f = shift;
|
||||||
my $v = shift;
|
my $v = shift;
|
||||||
|
@ -21,6 +54,16 @@ my %index;
|
||||||
|
|
||||||
for my $i (0 .. $#data) {
|
for my $i (0 .. $#data) {
|
||||||
unless ($top_n{$data[$i][$f]}) {
|
unless ($top_n{$data[$i][$f]}) {
|
||||||
|
|
||||||
|
# this is a bit tricky, as records for the same point in time for
|
||||||
|
# different series can be scattered all over the place. We assume
|
||||||
|
# that all columns except $f and $v are relevant to the point in
|
||||||
|
# time (or some other distinguishing criterium), so we save the value,
|
||||||
|
# set $v and $f to fixed values and concatenate all columns.
|
||||||
|
# This will get a unique value iff all columns except $f and $v are unique.
|
||||||
|
# If we have seen this value before, we add the current value to
|
||||||
|
# the record with this value and undef the current value. Otherwise we
|
||||||
|
# record the index of the current record.
|
||||||
my $val = $data[$i][$v];
|
my $val = $data[$i][$v];
|
||||||
$data[$i][$v] = 0;
|
$data[$i][$v] = 0;
|
||||||
$data[$i][$f] = 'OTHER';
|
$data[$i][$f] = 'OTHER';
|
||||||
|
|
Loading…
Reference in New Issue