Last active
December 14, 2015 17:29
-
-
Save aont/5122375 to your computer and use it in GitHub Desktop.
parse lm_sensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| my $interval = 2; | |
| my $time_begin = time(); | |
| printf("# time_begin = %d\n", $time_begin); | |
| while (1) { | |
| printf("%d\t", time() - $time_begin); | |
| open(my $sensors, "sensors |"); | |
| while (my $line = readline $sensors) { | |
| my $chip_name; | |
| if ($line =~ /^(coretemp-isa-(\d+))\n$/) { | |
| $chip_name = $1; | |
| } | |
| my $physical_id; | |
| my $physical_temp; | |
| my $coretemp_min = 100; | |
| my $coretemp_max = 0; | |
| while (my $line = readline $sensors) { | |
| if ($line =~ /^Adapter: ([^\n]+)/) { | |
| } elsif ($line =~ /^Physical\s+id\s+(\d+):\s+(\+\d+\.\d+)/) { | |
| $physical_id = $1; | |
| $physical_temp = $2+0.0; | |
| } elsif ($line =~ /^Core\s+(\d+):\s+(\+\d+\.\d+)/) { | |
| my $coretemp = $2+0.0; | |
| $coretemp_min = $coretemp if ($coretemp<$coretemp_min); | |
| $coretemp_max = $coretemp if ($coretemp>$coretemp_max); | |
| } elsif ($line == "\n") { | |
| last; | |
| } | |
| } | |
| printf("%f %f %f\t", $physical_temp, $coretemp_min, $coretemp_max); | |
| } | |
| close($sensors); | |
| printf "\n"; | |
| sleep $interval; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| # -*- coding: utf-8 -*- | |
| interval = 2 | |
| time_begin = Time.now.to_i | |
| printf "# time_begin %d\n", time_begin | |
| printf "# format: time [ physical_temp temp_min temp_max ]+\n" | |
| while true | |
| printf "%d\t", Time.now.to_i - time_begin | |
| IO.popen("sensors", 'r') do |io| | |
| while line = io.gets | |
| if (line =~ /^(coretemp-isa-(\d+))\n$/) | |
| chip_name = $1 | |
| # p chipname | |
| physical_id=nil | |
| physical_temp=nil | |
| coretemp_ary = [] | |
| coretemp_sum = 0 | |
| while line = io.gets | |
| if (line =~ /^Adapter: ([^\n]+)/) | |
| #puts $1 | |
| elsif (line =~ /^Physical\s+id\s+(\d+):\s+(\+\d+\.\d+)°C/) | |
| physical_id = $1.to_i | |
| physical_temp = $2.to_f | |
| elsif (line =~ /^Core\s+(\d+):\s+(\+\d+\.\d+)°C/) | |
| coretemp = $2.to_f | |
| coretemp_sum += coretemp | |
| coretemp_ary << $2.to_f | |
| elsif (line == "\n") | |
| break | |
| end | |
| end | |
| coretemp_avg = coretemp_sum / coretemp_ary.size | |
| printf "%f %f %f\t", physical_temp, coretemp_ary.min, coretemp_ary.max | |
| else | |
| end | |
| end | |
| printf "\n" | |
| $stdout.flush | |
| end | |
| sleep interval | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use IO::Handle; | |
| my $interval = 2; | |
| my $time_begin = time(); | |
| printf("# time_begin = %d\n", $time_begin); | |
| while (1) { | |
| printf("%d\t", time() - $time_begin); | |
| open(my $sensors, "sensors -u |"); | |
| my $line = readline $sensors; | |
| while (1) { | |
| my $chip_name; | |
| my $physical_id; | |
| my $physical_temp; | |
| my $coretemp_min = 100; | |
| my $coretemp_max = 0; | |
| while (1) { | |
| # print $line; | |
| if ($line eq "\n") { | |
| $line = readline $sensors; | |
| last; | |
| }elsif ($line =~ /^(coretemp-isa-\d+)\n$/){ | |
| $chip_name = $1; | |
| $line = readline $sensors; | |
| }elsif ($line =~ /^Adapter: ([^\n]+)/) { | |
| $line = readline $sensors; | |
| }elsif ($line =~ /^Physical\s+id\s+(\d+):/) { | |
| $physical_id = $1; | |
| while ($line = readline $sensors) { | |
| if ($line =~ /^ temp\d_([^:]+): (\d+\.\d+)/) { | |
| my $type = $1; | |
| my $temp_type = $2+"0.0"; | |
| if($type eq "input") { | |
| $physical_temp = $temp_type; | |
| } | |
| }else { | |
| last; | |
| } | |
| } | |
| }elsif ($line =~ /^Core\s+(\d+):/) { | |
| while ($line = readline $sensors) { | |
| if ($line =~ /^ temp\d_([^:]+): (\d+\.\d+)/) { | |
| my $type = $1; | |
| my $temp_type = $2+"0.0"; | |
| if($type eq "input") { | |
| my $coretemp = $temp_type; | |
| $coretemp_min = $coretemp if ($coretemp<$coretemp_min); | |
| $coretemp_max = $coretemp if ($coretemp>$coretemp_max); | |
| #printf " c %f\n", $coretemp; | |
| } | |
| }else { | |
| last; | |
| } | |
| } | |
| }else { | |
| $line = readline $sensors; | |
| } | |
| } | |
| printf "%f %f %f\t", $physical_temp, $coretemp_min, $coretemp_max; | |
| last if(!defined($line)); | |
| } | |
| close($sensors); | |
| print "\n"; | |
| STDOUT->flush; | |
| sleep $interval; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment