mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
More housekeeping.
This commit is contained in:
parent
038c3ce96b
commit
e5ce74926d
43 changed files with 0 additions and 0 deletions
190
plugins/sensors/power/acpi_batt_
Executable file
190
plugins/sensors/power/acpi_batt_
Executable file
|
@ -0,0 +1,190 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
acpi_batt_ Munin plugin to monitor the (note|net)book battery states through procfs
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Notebooks and netbooks with avialable /proc/acpi/battery
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Configured change the name of symbolic link
|
||||
|
||||
acpi_batt_X_capacity - chart of Design capacity, Last full capacity, Design capacity low,
|
||||
Design capacity warning, Capacity granularity 1, Capacity granularity 2,
|
||||
Remaining capacity, Present rate (mA)
|
||||
acpi_batt_X_percents - percentage chart of Current voltage, Current capacity, Full capacity (of design)
|
||||
acpi_batt_X_voltage - chart of Design voltage, Present voltage
|
||||
Where X is the number of battery from /proc/acpi/battery/BATX
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin shows:
|
||||
Design capacity
|
||||
Last full capacity
|
||||
Design capacity low
|
||||
Design capacity warning
|
||||
Capacity granularity 1
|
||||
Capacity granularity 2
|
||||
Remaining capacity
|
||||
Present rate (mA)
|
||||
Percentage Current/design voltage
|
||||
Percentage Full/current capacity
|
||||
Percentage Design/full capacity
|
||||
Design voltage
|
||||
Present voltage
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=power
|
||||
|
||||
=head1 VERSION
|
||||
=head1 BUGS
|
||||
|
||||
None known.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gorlow Maxim <sheridan@sheridan-home.ru>
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
use strict;
|
||||
#use Data::Dumper;
|
||||
|
||||
my ($graph_type, $batt_num);
|
||||
if ($0 =~ /^(?:|.*\/)acpi_batt_([^_]+)_(.+)$/)
|
||||
{
|
||||
$graph_type = $2;
|
||||
$batt_num = $1;
|
||||
}
|
||||
elsif (!defined($batt_num) or !defined($graph_type)) {
|
||||
die "# Error: couldn't understand what I'm supposed to monitor."; }
|
||||
|
||||
#print "$batt_num, $graph_type \n";
|
||||
|
||||
sub trim
|
||||
{
|
||||
my($string)=@_;
|
||||
for ($string)
|
||||
{
|
||||
s/^\s+//;
|
||||
s/\s+$//;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
sub read_data
|
||||
{
|
||||
my $file = $_[0];
|
||||
my ($fh, $var, $val);
|
||||
my @tmp;
|
||||
my $result = {};
|
||||
open($fh, '<', "/proc/acpi/battery/BAT${batt_num}/${file}") or die $!;
|
||||
foreach my $line (<$fh>)
|
||||
{
|
||||
chomp ($line);
|
||||
($var, $val) = split(':', $line);
|
||||
if ( $val =~ m/^\s*$/ )
|
||||
{
|
||||
$val = "unknown";
|
||||
}
|
||||
elsif ( $var ne "batery type" or $var ne "serial number" or $var ne "OEM info" )
|
||||
{
|
||||
@tmp = split(" " ,$val);
|
||||
$val = trim($tmp[0]);
|
||||
}
|
||||
$result->{$var} = $val;
|
||||
#print "$var, -$val- \n";
|
||||
}
|
||||
close($fh);
|
||||
return $result;
|
||||
}
|
||||
|
||||
my $batt_data = {};
|
||||
$batt_data->{'info'} = read_data("info" );
|
||||
$batt_data->{'state'} = read_data("state");
|
||||
|
||||
#print Dumper($batt_data);
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||
{
|
||||
my $batt_name = sprintf("%s %s %s", $batt_data->{'info'}{'OEM info'}, $batt_data->{'info'}{'battery type'}, $batt_data->{'info'}{'model number'});
|
||||
print ("graph_args --base 1000\n");
|
||||
printf ("graph_title Battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||||
printf ("graph_info This graph shows battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||||
print ("graph_category power\n");
|
||||
if ($graph_type eq "capacity")
|
||||
{
|
||||
print ("graph_vlabel Capacity, mAh\n");
|
||||
print ("dc.label Design capacity\ndc.type GAUGE\ndc.draw AREA\n");
|
||||
print ("lfc.label Last full capacity\nlfc.type GAUGE\nlfc.draw AREA\n");
|
||||
print ("dcl.label Design capacity low\ndcl.type GAUGE\ndcl.draw LINE2\n");
|
||||
print ("dcw.label Design capacity warning\ndcw.type GAUGE\ndcw.draw LINE2\n");
|
||||
print ("cg1.label Capacity granularity 1\ncg1.type GAUGE\ncg1.draw LINE2\n");
|
||||
print ("cg2.label Capacity granularity 2\ncg2.type GAUGE\ncg2.draw LINE2\n");
|
||||
print ("rc.label Remaining capacity\nrc.type GAUGE\nrc.draw LINE2\n");
|
||||
print ("pr.label Present rate (mA)\npr.type GAUGE\npr.draw LINE2\n");
|
||||
}
|
||||
elsif ($graph_type eq "voltage")
|
||||
{
|
||||
print ("graph_vlabel Voltage, mV\n");
|
||||
print ("d.label Design voltage\nd.type GAUGE\nd.draw AREA\n");
|
||||
print ("p.label Present voltage\np.type GAUGE\np.draw AREA\n");
|
||||
}
|
||||
elsif ($graph_type eq "percents")
|
||||
{
|
||||
print ("graph_vlabel %\n");
|
||||
print ("cv.label Current voltage\ncv.type GAUGE\ncv.draw LINE2\n");
|
||||
print ("cc.label Current capacity\ncc.type GAUGE\ncc.draw LINE2\n");
|
||||
print ("fc.label Full capacity (of design)\nfc.type GAUGE\nfc.draw LINE2\n");
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
#$batt_data->{'info'}{''}
|
||||
sub percent
|
||||
{
|
||||
my ($full, $current) = @_[0..1];
|
||||
return $current/($full/100);
|
||||
}
|
||||
|
||||
if ($graph_type eq "capacity")
|
||||
{
|
||||
printf ("dc.value %s\n", $batt_data->{'info'}{'design capacity'});
|
||||
printf ("lfc.value %s\n", $batt_data->{'info'}{'last full capacity'});
|
||||
printf ("dcl.value %s\n", $batt_data->{'info'}{'design capacity low'});
|
||||
printf ("dcw.value %s\n", $batt_data->{'info'}{'design capacity warning'});
|
||||
printf ("cg1.value %s\n", $batt_data->{'info'}{'capacity granularity 1'});
|
||||
printf ("cg2.value %s\n", $batt_data->{'info'}{'capacity granularity 2'});
|
||||
printf ("rc.value %s\n", $batt_data->{'state'}{'remaining capacity'});
|
||||
printf ("pr.value %s\n", $batt_data->{'state'}{'present rate'});
|
||||
}
|
||||
elsif ($graph_type eq "voltage")
|
||||
{
|
||||
printf ("d.value %s\n", $batt_data->{'info'}{'design voltage'});
|
||||
printf ("p.value %s\n", $batt_data->{'state'}{'present voltage'});
|
||||
}
|
||||
elsif ($graph_type eq "percents")
|
||||
{
|
||||
printf ("cv.value %s\n", percent($batt_data->{'info'}{'design voltage'},$batt_data->{'state'}{'present voltage'}));
|
||||
printf ("cc.value %s\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'state'}{'remaining capacity'}));
|
||||
printf ("fc.value %s\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'info'}{'last full capacity'}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
167
plugins/sensors/power/acpi_sys_batt_
Executable file
167
plugins/sensors/power/acpi_sys_batt_
Executable file
|
@ -0,0 +1,167 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
acpi_sys_batt_ Munin plugin to monitor the (note|net)book battery states through sysfs
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Notebooks and netbooks with avialable /sys/class/power_supply
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Configured change the name of symbolic link
|
||||
|
||||
acpi_sys_batt_X_capacity - chart of Charge full by design, Charge full and Charge now
|
||||
acpi_sys_batt_X_current - chart of battery current
|
||||
acpi_sys_batt_X_percents - percentage chart of Current/design voltage, Full/current capacity, Design/full capacity
|
||||
acpi_sys_batt_X_voltage - chart of Design min voltage and Current voltage
|
||||
Where X is the number of batteries from /sys/class/power_supply/BATX
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin shows:
|
||||
Charge full by design
|
||||
Charge full
|
||||
Charge now
|
||||
Battery current
|
||||
Percentage Current/design voltage
|
||||
Percentage Full/current capacity
|
||||
Percentage Design/full capacity
|
||||
Design min voltage
|
||||
Current voltage
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=power
|
||||
|
||||
=head1 VERSION
|
||||
=head1 BUGS
|
||||
|
||||
None known.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gorlow Maxim <sheridan@sheridan-home.ru>
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
#use Data::Dumper;
|
||||
|
||||
my ($graph_type, $batt_num);
|
||||
if ($0 =~ /^(?:|.*\/)acpi_sys_batt_([^_]+)_(.+)$/)
|
||||
{
|
||||
$graph_type = $2;
|
||||
$batt_num = $1;
|
||||
}
|
||||
elsif (!defined($batt_num) or !defined($graph_type)) {
|
||||
die "# Error: couldn't understand what I'm supposed to monitor."; }
|
||||
|
||||
my $sys_path=sprintf("/sys/class/power_supply/BAT%s", $batt_num);
|
||||
|
||||
#print "$batt_num, $graph_type \n";
|
||||
|
||||
sub cat_file
|
||||
{
|
||||
my $file = $_[0];
|
||||
my $fh;
|
||||
my $file_content = "--";
|
||||
open($fh, '<', "${sys_path}/${file}") or die $!;
|
||||
foreach my $line (<$fh>)
|
||||
{
|
||||
chomp ($line);
|
||||
$file_content = $line;
|
||||
}
|
||||
close($fh);
|
||||
return $file_content;
|
||||
}
|
||||
|
||||
#print Dumper($batt_data);
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||
{
|
||||
|
||||
#manufacturer
|
||||
#model_name
|
||||
#serial_number
|
||||
# ----------- status
|
||||
#technology
|
||||
#type
|
||||
|
||||
|
||||
my $batt_name = sprintf("%s %s %s %s (sn: %s)", cat_file('technology'), cat_file('type'), cat_file('manufacturer'), cat_file('model_name'), cat_file('serial_number'));
|
||||
print ("graph_args --base 1000\n");
|
||||
printf ("graph_title Battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||||
printf ("graph_info This graph shows battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||||
print ("graph_category power\n");
|
||||
if ($graph_type eq "capacity")
|
||||
{
|
||||
print ("graph_vlabel Charge\n");
|
||||
print ("cfd.label Charge full design\ncfd.type GAUGE\ncfd.draw AREA\n");
|
||||
print ("cf.label Charge full\ncf.type GAUGE\ncf.draw AREA\n");
|
||||
print ("cn.label Charge now\ncn.type GAUGE\ncn.draw AREA\n");
|
||||
}
|
||||
elsif ($graph_type eq "current")
|
||||
{
|
||||
print ("graph_vlabel Current, mAh\n");
|
||||
print ("currn.label Current\ncurrn.type GAUGE\ncurrn.draw AREA\n");
|
||||
}
|
||||
elsif ($graph_type eq "voltage")
|
||||
{
|
||||
print ("graph_vlabel Voltage, mV\n");
|
||||
print ("vmd.label Design min voltage\nvmd.type GAUGE\nvmd.draw AREA\n");
|
||||
print ("vn.label Voltage now\nvn.type GAUGE\nvn.draw AREA\n");
|
||||
}
|
||||
elsif ($graph_type eq "percents")
|
||||
{
|
||||
print ("graph_vlabel %\n");
|
||||
print ("cv.label Current/design voltage\ncv.type GAUGE\ncv.draw LINE2\n");
|
||||
print ("cc.label Full/current capacity\ncc.type GAUGE\ncc.draw LINE2\n");
|
||||
print ("fc.label Design/full capacity\nfc.type GAUGE\nfc.draw LINE2\n");
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
#$batt_data->{'info'}{''}
|
||||
sub percent
|
||||
{
|
||||
my ($full, $current) = @_[0..1];
|
||||
return $current/($full/100);
|
||||
}
|
||||
|
||||
#charge_full
|
||||
#charge_full_design
|
||||
#charge_now
|
||||
#current_now
|
||||
#voltage_min_design
|
||||
#voltage_now
|
||||
|
||||
if ($graph_type eq "capacity")
|
||||
{
|
||||
printf ("cfd.value %s\n", cat_file('charge_full_design'));
|
||||
printf ("cf.value %s\n", cat_file('charge_full'));
|
||||
printf ("cn.value %s\n", cat_file('charge_now'));
|
||||
}
|
||||
elsif ($graph_type eq "voltage")
|
||||
{
|
||||
printf ("vmd.value %s\n", cat_file('voltage_min_design'));
|
||||
printf ("vn.value %s\n", cat_file('voltage_now'));
|
||||
}
|
||||
elsif ($graph_type eq "current")
|
||||
{
|
||||
printf ("currn.value %s\n", cat_file('current_now'));
|
||||
}
|
||||
elsif ($graph_type eq "percents")
|
||||
{
|
||||
printf ("cv.value %s\n", percent(cat_file('voltage_min_design'),cat_file('voltage_now')));
|
||||
printf ("cc.value %s\n", percent(cat_file('charge_full'),cat_file('charge_now')));
|
||||
printf ("fc.value %s\n", percent(cat_file('charge_full_design'),cat_file('charge_full')));
|
||||
}
|
||||
|
||||
|
359
plugins/sensors/power/batteries
Executable file
359
plugins/sensors/power/batteries
Executable file
|
@ -0,0 +1,359 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
batteries Munin plugin to monitor the battery states through procfs and sysfs
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Systems with avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
none
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin shows:
|
||||
Design capacity -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Last full capacity -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Design capacity low -> avialable only if avialable /proc/acpi/battery/BATx
|
||||
Design capacity warning -> avialable only if avialable /proc/acpi/battery/BATx
|
||||
Capacity granularity 1 -> avialable only if avialable /proc/acpi/battery/BATx
|
||||
Capacity granularity 2 -> avialable only if avialable /proc/acpi/battery/BATx
|
||||
Remaining capacity -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Present rate -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Percentage Current/design voltage -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Percentage Current/full capacity -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Percentage Full/design capacity -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Design voltage -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
Present voltage -> avialable if avialable /proc/acpi/battery/BATx or /sys/class/power_supply/BATx
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=power
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
1.0
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gorlow Maxim aka Sheridan <sheridan@sheridan-home.ru> - email and jabber
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IO::Dir;
|
||||
use Munin::Plugin;
|
||||
|
||||
need_multigraph();
|
||||
|
||||
my $proc_path = '/proc/acpi/battery';
|
||||
my $sys_path = '/sys/class/power_supply';
|
||||
|
||||
my $proc_data_exists;
|
||||
my $sys_data_exists;
|
||||
my $batteryes_count;
|
||||
|
||||
sub trim
|
||||
{
|
||||
my($string)=@_;
|
||||
for ($string)
|
||||
{
|
||||
s/^\s+//;
|
||||
s/\s+$//;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
sub get_batteryes_count
|
||||
{
|
||||
my $path = $_[0];
|
||||
return 0 unless (-e $path);
|
||||
my $count = 0;
|
||||
my $dir = IO::Dir->new($path);
|
||||
if(defined $dir)
|
||||
{
|
||||
my $d;
|
||||
while (defined ($d = $dir->read))
|
||||
{
|
||||
next unless $d =~ m/BAT\d+/;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
else { return 0; }
|
||||
return $count;
|
||||
}
|
||||
|
||||
sub init
|
||||
{
|
||||
my $proc_batt_count = get_batteryes_count($proc_path);
|
||||
my $sys_batt_count = get_batteryes_count($sys_path );
|
||||
#print "$proc_batt_count $sys_batt_count\n";
|
||||
$proc_data_exists = $proc_batt_count > 0;
|
||||
$sys_data_exists = $sys_batt_count > 0;
|
||||
if ($proc_data_exists and $sys_data_exists and ($proc_batt_count != $sys_batt_count))
|
||||
{
|
||||
die "Something wrong, batteryes count from $proc_path and $sys_path not equal (proc: $proc_batt_count, sys: $sys_batt_count)!"
|
||||
}
|
||||
if ($proc_data_exists) { $batteryes_count = $proc_batt_count; }
|
||||
elsif ($sys_data_exists) { $batteryes_count = $sys_batt_count; }
|
||||
unless ($batteryes_count)
|
||||
{
|
||||
die "Batteryes not found."
|
||||
}
|
||||
}
|
||||
|
||||
sub read_proc_data
|
||||
{
|
||||
my ($batt_num, $file) = @_[0..1];
|
||||
my ($var, $val, $result);
|
||||
open(FH, '<', "${proc_path}/BAT${batt_num}/${file}") or die $!;
|
||||
foreach my $line (<FH>)
|
||||
{
|
||||
chomp ($line);
|
||||
($var, $val) = split(':', $line);
|
||||
if ($val =~ m/^\s*$/ ) { $val = "nan"; }
|
||||
elsif ($val =~ m/\w\s+\w/) { $val = (split(" " ,$val))[0]; }
|
||||
$result->{$var} = trim($val);
|
||||
#print "var $var - val $val\n";
|
||||
}
|
||||
close(FH);
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub read_sys_data
|
||||
{
|
||||
my ($batt_num, $file) = @_[0..1];
|
||||
my $file_content = "nan";
|
||||
open(FH, '<', "${sys_path}/BAT${batt_num}/${file}") or die $!;
|
||||
$file_content = <FH>;
|
||||
close(FH);
|
||||
chomp ($file_content);
|
||||
if($file_content =~ m/^\s*$/) { return 'nan'; }
|
||||
return $file_content;
|
||||
}
|
||||
|
||||
sub percent
|
||||
{
|
||||
my ($full, $current) = @_[0..1];
|
||||
return $current/($full/100);
|
||||
}
|
||||
|
||||
sub read_info
|
||||
{
|
||||
my $info;
|
||||
for (my $i = 0; $i < $batteryes_count; $i++)
|
||||
{
|
||||
if($sys_data_exists)
|
||||
{
|
||||
$info->{$i}{'manufacturer'} = read_sys_data($i, 'manufacturer');
|
||||
$info->{$i}{'battery_type'} = read_sys_data($i, 'technology' );
|
||||
$info->{$i}{'model_name'} = read_sys_data($i, 'model_name' );
|
||||
$info->{$i}{'serial_number'} = read_sys_data($i, 'serial_number');
|
||||
}
|
||||
else
|
||||
{
|
||||
my $proc_info = read_proc_data($i, 'info');
|
||||
$info->{$i}{'manufacturer'} = $proc_info->{'OEM info' };
|
||||
$info->{$i}{'battery_type'} = $proc_info->{'battery type' };
|
||||
$info->{$i}{'model_name'} = $proc_info->{'model number' };
|
||||
$info->{$i}{'serial_number'} = $proc_info->{'serial number'};
|
||||
}
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
sub read_data
|
||||
{
|
||||
my $data;
|
||||
for (my $i = 0; $i < $batteryes_count; $i++)
|
||||
{
|
||||
if($sys_data_exists)
|
||||
{
|
||||
my $divider = 1000000; # need for equvivalent sys and proc data
|
||||
$data->{$i}{'design_capacity'} = read_sys_data($i, 'charge_full_design')/$divider;
|
||||
$data->{$i}{'last_full_capacity'} = read_sys_data($i, 'charge_full') /$divider;
|
||||
$data->{$i}{'remaining_capacity'} = read_sys_data($i, 'charge_now') /$divider;
|
||||
$data->{$i}{'design_voltage'} = read_sys_data($i, 'voltage_min_design')/$divider;
|
||||
$data->{$i}{'present_voltage'} = read_sys_data($i, 'voltage_now') /$divider;
|
||||
$data->{$i}{'present_rate'} = read_sys_data($i, 'current_now') /$divider;
|
||||
}
|
||||
if($proc_data_exists)
|
||||
{
|
||||
my $divider = 1000; # need for equvivalent sys and proc data
|
||||
my $proc_info = read_proc_data($i, 'info');
|
||||
unless($sys_data_exists)
|
||||
{
|
||||
my $proc_state = read_proc_data($i, 'state');
|
||||
$data->{$i}{'design_capacity'} = $proc_info ->{'design capacity'} /$divider;
|
||||
$data->{$i}{'last_full_capacity'} = $proc_info ->{'last full capacity'}/$divider;
|
||||
$data->{$i}{'remaining_capacity'} = $proc_state->{'remaining capacity'}/$divider;
|
||||
$data->{$i}{'design_voltage'} = $proc_info ->{'design voltage'} /$divider;
|
||||
$data->{$i}{'present_voltage'} = $proc_state->{'present voltage'} /$divider;
|
||||
$data->{$i}{'present_rate'} = $proc_state->{'present rate'} /$divider;
|
||||
}
|
||||
$data->{$i}{'design_capacity_low'} = $proc_info ->{'design capacity low'} /$divider;
|
||||
$data->{$i}{'design_capacity_warning'} = $proc_info ->{'design capacity warning'}/$divider;
|
||||
$data->{$i}{'capacity_granularity_1'} = $proc_info ->{'capacity granularity 1'} /$divider;
|
||||
$data->{$i}{'capacity_granularity_2'} = $proc_info ->{'capacity granularity 2'} /$divider;
|
||||
}
|
||||
$data->{$i}{'current_voltage_percent'} = percent($data->{$i}{'design_voltage'} , $data->{$i}{'present_voltage'});
|
||||
$data->{$i}{'current_capacity_percent'} = percent($data->{$i}{'last_full_capacity'}, $data->{$i}{'remaining_capacity'});
|
||||
$data->{$i}{'full_capacity_percent'} = percent($data->{$i}{'design_capacity'} , $data->{$i}{'last_full_capacity'});
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
my $graphs =
|
||||
{
|
||||
'batteryes_capacity' => { 'vlabel' => 'Capacity, Ah', 'title' => '%s capacity', 'args' => '--base 1000',
|
||||
'fields' => [qw/design_capacity last_full_capacity design_capacity_low design_capacity_warning capacity_granularity_1 capacity_granularity_2 remaining_capacity/] },
|
||||
'batteryes_voltage' => { 'vlabel' => 'Voltage, V' , 'title' => '%s voltage' , 'args' => '--base 1000',
|
||||
'fields' => [qw/design_voltage present_voltage/] },
|
||||
'batteryes_percents' => { 'vlabel' => '%' , 'title' => '%s percents', 'args' => '--base 1000 --upper-limit 100 -l 0',
|
||||
'fields' => [qw/current_voltage_percent current_capacity_percent full_capacity_percent/] },
|
||||
'batteryes_current' => { 'vlabel' => 'Current, A' , 'title' => '%s current' , 'args' => '--base 1000',
|
||||
'fields' => [qw/present_rate/] }
|
||||
};
|
||||
|
||||
my $fields =
|
||||
{
|
||||
'design_capacity' => { 'source' => 'both', 'draw' => 'AREA' , 'label' => 'Design capacity' , 'info' => 'Battery design capacity' },
|
||||
'last_full_capacity' => { 'source' => 'both', 'draw' => 'AREA' , 'label' => 'Last full capacity' , 'info' => 'Battery full charge capacity' },
|
||||
'design_capacity_low' => { 'source' => 'proc', 'draw' => 'LINE2', 'label' => 'Design capacity low' , 'info' => 'Low battery level' },
|
||||
'design_capacity_warning' => { 'source' => 'proc', 'draw' => 'LINE2', 'label' => 'Design capacity warning', 'info' => 'Warning battery level' },
|
||||
'capacity_granularity_1' => { 'source' => 'proc', 'draw' => 'LINE2', 'label' => 'Capacity granularity 1' , 'info' => 'Capacity granularity 1' },
|
||||
'capacity_granularity_2' => { 'source' => 'proc', 'draw' => 'LINE2', 'label' => 'Capacity granularity 2' , 'info' => 'Capacity granularity 2' },
|
||||
'remaining_capacity' => { 'source' => 'both', 'draw' => 'LINE2', 'label' => 'Remaining capacity' , 'info' => 'Current battery charge' },
|
||||
'present_rate' => { 'source' => 'both', 'draw' => 'LINE2', 'label' => 'Present rate' , 'info' => 'Current battery rate' },
|
||||
'design_voltage' => { 'source' => 'both', 'draw' => 'AREA' , 'label' => 'Design voltage' , 'info' => 'Battery design voltage' },
|
||||
'present_voltage' => { 'source' => 'both', 'draw' => 'AREA' , 'label' => 'Present voltage' , 'info' => 'Current battery voltage' },
|
||||
'current_voltage_percent' => { 'source' => 'both', 'draw' => 'LINE2', 'label' => 'Current/design voltage' , 'info' => 'Current battery voltage / ( Battery design voltage / 100 )' },
|
||||
'current_capacity_percent' => { 'source' => 'both', 'draw' => 'LINE2', 'label' => 'Current/full capacity' , 'info' => 'Current battery charge / ( Battery full charge capacity / 100 )' },
|
||||
'full_capacity_percent' => { 'source' => 'both', 'draw' => 'LINE2', 'label' => 'Full/design capacity' , 'info' => 'Battery full charge capacity / ( Battery design capacity / 100 )' },
|
||||
};
|
||||
|
||||
# ------------------------------------ start here -----------------------------------
|
||||
|
||||
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf'))
|
||||
{
|
||||
printf("%s\n", (-e $proc_path or -e $sys_path) ? "yes" : "no ($proc_path and $sys_path not exists)");
|
||||
exit (0);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||
{
|
||||
my %config;
|
||||
my $info = read_info();
|
||||
foreach my $graph (keys %{$graphs})
|
||||
{
|
||||
my @order;
|
||||
$config{$graph}{'graph'}{'title'} = sprintf($graphs->{$graph}{'title'}, 'Mean batteryes');
|
||||
$config{$graph}{'graph'}{'args'} = $graphs->{$graph}{'args'};
|
||||
$config{$graph}{'graph'}{'vlabel'} = $graphs->{$graph}{'vlabel'};
|
||||
$config{$graph}{'graph'}{'category'} = 'power';
|
||||
foreach my $field (@{$graphs->{$graph}{'fields'}})
|
||||
{
|
||||
if(($proc_data_exists and $fields->{$field}{'source'} eq 'proc') or $fields->{$field}{'source'} eq 'both')
|
||||
{
|
||||
$config{$graph}{'fields'}{$field}{'label'} = $fields->{$field}{'label'};
|
||||
$config{$graph}{'fields'}{$field}{'info'} = $fields->{$field}{'info'};
|
||||
$config{$graph}{'fields'}{$field}{'draw'} = $fields->{$field}{'draw'};
|
||||
$config{$graph}{'fields'}{$field}{'type'} = 'GAUGE';
|
||||
push(@order, $field);
|
||||
}
|
||||
}
|
||||
$config{$graph}{'graph'}{'order'} = join(' ', @order);
|
||||
for (my $i = 0; $i < $batteryes_count; $i++)
|
||||
{
|
||||
my @b_order;
|
||||
my $battery_name = sprintf("BAT%s", $i);
|
||||
my $graph_name = sprintf("%s.%s", $graph, $battery_name);
|
||||
$config{$graph_name}{'graph'}{'title'} = sprintf($graphs->{$graph}{'title'}, $battery_name);
|
||||
$config{$graph_name}{'graph'}{'info'} = sprintf("%s battery %s %s (sn: %s)", $info->{$i}{'battery_type'}, $info->{$i}{'manufacturer'}, $info->{$i}{'model_name'}, $info->{$i}{'serial_number'});
|
||||
$config{$graph_name}{'graph'}{'args'} = '--base 1000';
|
||||
$config{$graph_name}{'graph'}{'vlabel'} = $graphs->{$graph}{'vlabel'};
|
||||
$config{$graph_name}{'graph'}{'category'} = 'power';
|
||||
foreach my $field (@{$graphs->{$graph}{'fields'}})
|
||||
{
|
||||
if(($proc_data_exists and $fields->{$field}{'source'} eq 'proc') or $fields->{$field}{'source'} eq 'both')
|
||||
{
|
||||
$config{$graph_name}{'fields'}{$field}{'label'} = $fields->{$field}{'label'};
|
||||
$config{$graph_name}{'fields'}{$field}{'info'} = $fields->{$field}{'info'};
|
||||
$config{$graph_name}{'fields'}{$field}{'draw'} = $fields->{$field}{'draw'};
|
||||
$config{$graph_name}{'fields'}{$field}{'type'} = 'GAUGE';
|
||||
push(@b_order, $field);
|
||||
}
|
||||
}
|
||||
$config{$graph_name}{'graph'}{'order'} = join(' ', @b_order);
|
||||
}
|
||||
}
|
||||
# ---------------- print ------------------
|
||||
foreach my $graph (sort keys %config)
|
||||
{
|
||||
printf("multigraph %s\n", $graph);
|
||||
foreach my $g_option(sort keys %{$config{$graph}{'graph'}})
|
||||
{
|
||||
printf("graph_%s %s\n", $g_option, $config{$graph}{'graph'}{$g_option});
|
||||
}
|
||||
foreach my $field (sort keys %{$config{$graph}{'fields'}})
|
||||
{
|
||||
foreach my $f_option (sort keys %{$config{$graph}{'fields'}{$field}})
|
||||
{
|
||||
printf("%s.%s %s\n", $field, $f_option, $config{$graph}{'fields'}{$field}{$f_option});
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
# ----------------------------- values ---------------------------------------------
|
||||
my $data = read_data();
|
||||
foreach my $graph (sort keys %{$graphs})
|
||||
{
|
||||
printf ("multigraph %s\n", $graph);
|
||||
foreach my $field (sort @{$graphs->{$graph}{'fields'}})
|
||||
{
|
||||
my $field_summ = 0;
|
||||
if(($proc_data_exists and $fields->{$field}{'source'} eq 'proc') or $fields->{$field}{'source'} eq 'both')
|
||||
{
|
||||
for (my $i = 0; $i < $batteryes_count; $i++)
|
||||
{
|
||||
$field_summ += $data->{$i}{$field};
|
||||
}
|
||||
printf("%s.value %s\n", $field, $field_summ/$batteryes_count);
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
for (my $i = 0; $i < $batteryes_count; $i++)
|
||||
{
|
||||
my $graph_name = sprintf("%s.BAT%s", $graph, $i);
|
||||
printf ("multigraph %s\n", $graph_name);
|
||||
foreach my $field (sort @{$graphs->{$graph}{'fields'}})
|
||||
{
|
||||
if(($proc_data_exists and $fields->{$field}{'source'} eq 'proc') or $fields->{$field}{'source'} eq 'both')
|
||||
{
|
||||
printf("%s.value %s\n", $field, $data->{$i}{$field});
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue