Difference between revisions of "Myth sensors.pl"

From MythTV Official Wiki
Jump to: navigation, search
(Add script info tag)
m (add version info, admit to authoring hack)
 
Line 1: Line 1:
 
{{Wrongtitle|myth_sensors.pl}}
 
{{Wrongtitle|myth_sensors.pl}}
 
{{Script info
 
{{Script info
|author=unknown
+
|author=Michael T. Dean
 
|short=Adds temp/fan info to the backend status page
 
|short=Adds temp/fan info to the backend status page
 
|long=Retrieves sensors output (thermal/fan information) and formats it for inclusion in the MythTV backend status page,
 
|long=Retrieves sensors output (thermal/fan information) and formats it for inclusion in the MythTV backend status page,
 
|category=Miscellaneous Status Information Scripts
 
|category=Miscellaneous Status Information Scripts
|file=myth_sensors.pl}}
+
|file=myth_sensors.pl
 +
|S21=yes|S22=yes|S23=yes|S24=yes}}
  
 
'''myth_sensors.pl''' retrieves sensors output and formats it for inclusion in the MythTV backend status page
 
'''myth_sensors.pl''' retrieves sensors output and formats it for inclusion in the MythTV backend status page

Latest revision as of 02:02, 12 November 2010

Important.png Note: The correct title of this article is myth_sensors.pl. It appears incorrectly here due to technical restrictions.


Author Michael T. Dean
Description Retrieves sensors output (thermal/fan information) and formats it for inclusion in the MythTV backend status page,
Supports Version21.png  Version22.png  Version23.png  Version24.png  


myth_sensors.pl retrieves sensors output and formats it for inclusion in the MythTV backend status page


Script.png myth_sensors.pl

#!/usr/bin/perl -w
# myth_sensors.pl
#
# Retrieves sensors output and formats it for inclusion in the MythTV backend
# status page.
#
# You may specify the sensors_command_line as well as the data to retrieve and
# the output information as described in the comments, below.


# Change the command line required to execute the sensors program, below.
# The default value should work as long as sensors is in the PATH for the user
# running mythbackend
    my $sensors_command_line = 'sensors';

# Specify the data to retrieve and the output information in the format:
#
# [ "<sensors label>", "<display output>", "<XML output name>" ]
#
# where <sensors label> is the label used by the sensors program for the
# value you wish to include and <display output> may contain "%v" at the
# location where the value should be placed.  If <display output> does not
# contain "%v", the value will be appended to the end.  The <XML output name>
# is an optional value for the "name" attribute, which can be used to make
# machine parsing easier.
    my @output = (
                  [ "CPU Temp", "Current CPU Temperature: %v &#8451;", "temperature-CPU" ],
                  [ "CPU Fan", "Current CPU Fan Speed:", "fan-CPU" ],
                  [ "M/B Temp", "Current Motherboard Temperature: %v &#8451;", "temperature-MB" ],
                  [ "Case Fan", "Current Case Fan Speed:", "fan-case" ],
    );

# Editing the following code should not be necessary.
    my $line = 0;
    my %data = ();
    my ($label, $display, $value, $name);

    my @sensors_data = `$sensors_command_line`;

    while ($sensors_data[$line])
    {
        $sensors_data[$line] =~ /^(.+):\s+(?:\+|-)?(\d+\.?\d*)/;
        if ($1 && $2)
        {
            $data{ $1 } = $2;
        }
        $line++;
    }
    for $i (0 .. $#output) {
        $label = $output[$i][0];
        $value = $data{$label}; 
        if ($value)
        {
            $display = $output[$i][1];
            $name = $output[$i][2];
            $display = "$display %v" unless ($display =~ /%v/);
            $display =~ s/%v/$value/;
            print("${display}");
            print("[]:[]${name}") if ($name);
            print("[]:[]${value}") if ($name && $value);
            print("\n");
        }
    }

Getting sensors Data from Remote Systems

With appropriate authentication in place (i.e. using SSH Certificate Authentication, Kerberos Authentication, ...), you may also retrieve sensors data from remote systems (i.e. remote backends, remote frontends, etc.). Do so with commands of the format below (provide an appropriate host name in place of remote and either specify a full path for myth_sensors.pl or ensure the script is located in the user's PATH):

ssh -q remote myth_sensors.pl

Alternatively, this information could be retrieved from an appropriate monitoring program (monit, mrtg) or by using SNMP, depending on the system and network configuration.