#!/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