"Fossies" - the Fresh Open Source Software Archive

Member "munin-2.0.52/plugins/node.d/hddtempd.in" (20 Nov 2019, 3082 Bytes) of package /linux/misc/munin-2.0.52.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!@@PERL@@ -w
    2 # -*- perl -*-
    3 #
    4 # Munin plugin to monitor hdd temperature from a hddtemp daemon.
    5 #
    6 # This plugin is an alternative to the hddtemp_smartctl, which is the
    7 # preferred one.
    8 #
    9 # Author: Stein Magnus Jodal <jodal at users.sourceforge.net>
   10 #
   11 # Depends on `hddtemp` <http://coredump.free.fr/linux/hddtemp.php> by
   12 # Emmanuel Varagnat <coredump@free.fr> running as a daemon.
   13 #
   14 # If fetching temp from another machine, remember to bind hddtempd to the right
   15 # interface. Loopback only is default.
   16 #
   17 # Parameters understood:
   18 #
   19 # 	host   - Change which host to graph (default localhost)
   20 # 	port   - Change which port to connect to (default 7634)
   21 # 	scale  - C for Celsius, F for Farenheit (default C)
   22 #
   23 # This plugin is based on the apt plugin.
   24 #
   25 #
   26 # Usage: place in /etc/munin/node.d/ (or link it there using ln -s)
   27 #
   28 # Parameters understood:
   29 # 	config   (required)
   30 # 	autoconf (optional - used by munin-config)
   31 #
   32 #
   33 # v1.2 2004-06-07
   34 #  - Renamed to hddtempd
   35 #  - Now more generic, not only localhost
   36 # v1.1 2004-05-23
   37 #  - Fixed support for multiple disks
   38 # v1.0 2004-05-17
   39 #  - Initial version
   40 #
   41 #
   42 # Magic markers - optional - used by installation scripts and
   43 # munin-config:
   44 #
   45 #%# family=contrib
   46 #%# capabilities=autoconf
   47 
   48 use strict;
   49 use IO::Socket::INET;
   50 
   51 # Config
   52 our $address = $ENV{host}  || "localhost";	# Default: localhost
   53 our $port    = $ENV{port}  || 7634;		# Default: 7634
   54 our $scale   = $ENV{scale} || "C";		# C (celcius) or F (fahrenheit)
   55 
   56 # Don't edit below this line
   57 
   58 if ($ARGV[0] and $ARGV[0] eq "autoconf") {
   59 	# Try to connect to the daemon
   60 	my $socket = IO::Socket::INET->new("$address:$port")
   61 		or my $failed = 1;
   62 
   63 	if ($failed) {
   64 		print "no (failed to connect to $address port $port)\n";
   65 		exit 0;
   66 	} else {
   67 		print "yes\n";
   68 		exit 0;
   69 	}
   70 }
   71 
   72 if ($ARGV[0] and $ARGV[0] eq "config") {
   73         print "graph_title HDD temperature\n";
   74 	print "graph_args --base 1000 -l 0\n";
   75 	print "graph_vlabel Degrees $scale\n";
   76 
   77 	my @data = get_data();
   78 
   79 	for my $this (@data) {
   80 		print "${$this}[0].label ";
   81 		${$this}[0] =~ tr#_#/#;
   82 		print "${$this}[0]\n";
   83 	}
   84 
   85         exit 0;
   86 }
   87 
   88 my @data = get_data();
   89 
   90 for my $this (@data) {
   91 	# device.value temp
   92 	print "${$this}[0].value ${$this}[2]\n";
   93 }
   94 
   95 # Connect to hddtemp daemon and collect data from it
   96 sub get_data {
   97 	my($socket, @raw, @data);
   98 
   99 	# Connect to the hddtemp daemon
  100 	$socket = IO::Socket::INET->new("$address:$port")
  101 		or die("Couldn't connect to $address port $port: $!");
  102 
  103 	# Read data and split into an array
  104 	@raw = split(/\|/, <$socket>);
  105 
  106 	# Parse data
  107 	for (my $i = 1; $i < scalar @raw; $i+=5) {
  108 		my @this = @raw[$i..$i+3];
  109 
  110 		# Remove /dev/-prefix on device
  111 		#$this[0] =~ s#.*/([^/]+)#$1#;
  112 
  113 		# Or, replace / with _
  114 		$this[0] =~ tr#/#_#;
  115 
  116 		# Adjust temp to the right scale
  117 		if ($scale eq "C" and $this[3] eq "F") {
  118 			# Convert from F to C
  119 			$this[2] = (5/9) * ($this[2] - 32);
  120 		} elsif ($scale eq "F" and $this[3] eq "C") {
  121 			# Convert from C to F
  122 			$this[2] = (9/5) * $this[2] + 32;
  123 		}
  124 
  125 		# Put @this into @data
  126 		push @data, [ @this ];
  127 	}
  128 
  129 	close($socket);
  130 
  131 	return @data;
  132 }
  133 
  134 # vim:syntax=perl