| Line | |
|---|
| 1 |
package Core::BSD::Sensor; |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use warnings; |
|---|
| 5 |
|
|---|
| 6 |
use base 'Resmon::Module'; |
|---|
| 7 |
|
|---|
| 8 |
use Resmon::ExtComm qw(run_command cache_command); |
|---|
| 9 |
|
|---|
| 10 |
=pod |
|---|
| 11 |
|
|---|
| 12 |
=head1 NAME |
|---|
| 13 |
|
|---|
| 14 |
Core::BSD::Sensor - Check values of OpenBSD hardware sensors |
|---|
| 15 |
|
|---|
| 16 |
=head1 SYNOPSIS |
|---|
| 17 |
|
|---|
| 18 |
Core::BSD::Sensor { |
|---|
| 19 |
cpu_temp: chip => admtm0, sensor => temp1 |
|---|
| 20 |
sys_temp: chip => admtm0, sensor => temp2 |
|---|
| 21 |
cpu_fan: chip => fins0, sensor => fan0 |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
=head1 DESCRIPTION |
|---|
| 25 |
|
|---|
| 26 |
This module reads values from hardware sensors using sysctl on OpenBSD. |
|---|
| 27 |
|
|---|
| 28 |
=head1 CONFIGURATION |
|---|
| 29 |
|
|---|
| 30 |
=over |
|---|
| 31 |
|
|---|
| 32 |
=item check_name |
|---|
| 33 |
|
|---|
| 34 |
The check name is a short description of what the particular sensor monitors. |
|---|
| 35 |
|
|---|
| 36 |
=item chip |
|---|
| 37 |
|
|---|
| 38 |
Specifies the desired sensor chip. This argument is mandatory. |
|---|
| 39 |
|
|---|
| 40 |
=item sensor |
|---|
| 41 |
|
|---|
| 42 |
The sensor on the specified chip whose value should be read. This argument is mandatory. |
|---|
| 43 |
|
|---|
| 44 |
=back |
|---|
| 45 |
|
|---|
| 46 |
=head1 METRICS |
|---|
| 47 |
|
|---|
| 48 |
=over |
|---|
| 49 |
|
|---|
| 50 |
=item value |
|---|
| 51 |
|
|---|
| 52 |
The value of the specified sensor. |
|---|
| 53 |
|
|---|
| 54 |
=back |
|---|
| 55 |
|
|---|
| 56 |
=cut |
|---|
| 57 |
|
|---|
| 58 |
sub handler { |
|---|
| 59 |
my $self = shift; |
|---|
| 60 |
my $config = $self->{config}; # All configuration is in here |
|---|
| 61 |
my $check_name = $self->{check_name}; # The check name is in here |
|---|
| 62 |
my $chip = $config->{chip}; |
|---|
| 63 |
my $sensor = $config->{sensor}; |
|---|
| 64 |
|
|---|
| 65 |
my $output = run_command("sysctl -n hw.sensors.$chip.$sensor"); |
|---|
| 66 |
$output =~ m/(-?\d+\.?\d*)\s+\S+/; |
|---|
| 67 |
my $value = $1; |
|---|
| 68 |
|
|---|
| 69 |
return { |
|---|
| 70 |
"value" => [$value, "n"] |
|---|
| 71 |
}; |
|---|
| 72 |
}; |
|---|
| 73 |
|
|---|
| 74 |
1; |
|---|