root / plugins / sensors / power / acpi_batt_ @ e5ce7492
Historique | Voir | Annoter | Télécharger (5,2 ko)
| 1 | 346b8c3a | Gorlow Maxim aka Sheridan | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # -*- perl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | acpi_batt_ Munin plugin to monitor the (note|net)book battery states through procfs |
||
| 7 | |||
| 8 | =head1 APPLICABLE SYSTEMS |
||
| 9 | |||
| 10 | Notebooks and netbooks with avialable /proc/acpi/battery |
||
| 11 | |||
| 12 | =head1 CONFIGURATION |
||
| 13 | |||
| 14 | Configured change the name of symbolic link |
||
| 15 | |||
| 16 | acpi_batt_X_capacity - chart of Design capacity, Last full capacity, Design capacity low, |
||
| 17 | Design capacity warning, Capacity granularity 1, Capacity granularity 2, |
||
| 18 | Remaining capacity, Present rate (mA) |
||
| 19 | acpi_batt_X_percents - percentage chart of Current voltage, Current capacity, Full capacity (of design) |
||
| 20 | acpi_batt_X_voltage - chart of Design voltage, Present voltage |
||
| 21 | Where X is the number of battery from /proc/acpi/battery/BATX |
||
| 22 | |||
| 23 | =head1 INTERPRETATION |
||
| 24 | |||
| 25 | The plugin shows: |
||
| 26 | Design capacity |
||
| 27 | Last full capacity |
||
| 28 | Design capacity low |
||
| 29 | Design capacity warning |
||
| 30 | Capacity granularity 1 |
||
| 31 | Capacity granularity 2 |
||
| 32 | Remaining capacity |
||
| 33 | Present rate (mA) |
||
| 34 | Percentage Current/design voltage |
||
| 35 | Percentage Full/current capacity |
||
| 36 | Percentage Design/full capacity |
||
| 37 | Design voltage |
||
| 38 | Present voltage |
||
| 39 | |||
| 40 | =head1 MAGIC MARKERS |
||
| 41 | |||
| 42 | #%# family=power |
||
| 43 | |||
| 44 | =head1 VERSION |
||
| 45 | =head1 BUGS |
||
| 46 | |||
| 47 | None known. |
||
| 48 | |||
| 49 | =head1 AUTHOR |
||
| 50 | |||
| 51 | Gorlow Maxim <sheridan@sheridan-home.ru> |
||
| 52 | |||
| 53 | =head1 LICENSE |
||
| 54 | |||
| 55 | GPLv2 |
||
| 56 | |||
| 57 | =cut |
||
| 58 | |||
| 59 | |||
| 60 | use strict; |
||
| 61 | #use Data::Dumper; |
||
| 62 | |||
| 63 | my ($graph_type, $batt_num); |
||
| 64 | if ($0 =~ /^(?:|.*\/)acpi_batt_([^_]+)_(.+)$/) |
||
| 65 | {
|
||
| 66 | $graph_type = $2; |
||
| 67 | $batt_num = $1; |
||
| 68 | } |
||
| 69 | elsif (!defined($batt_num) or !defined($graph_type)) {
|
||
| 70 | die "# Error: couldn't understand what I'm supposed to monitor."; } |
||
| 71 | |||
| 72 | #print "$batt_num, $graph_type \n"; |
||
| 73 | |||
| 74 | sub trim |
||
| 75 | {
|
||
| 76 | my($string)=@_; |
||
| 77 | for ($string) |
||
| 78 | {
|
||
| 79 | s/^\s+//; |
||
| 80 | s/\s+$//; |
||
| 81 | } |
||
| 82 | return $string; |
||
| 83 | } |
||
| 84 | |||
| 85 | |||
| 86 | sub read_data |
||
| 87 | {
|
||
| 88 | my $file = $_[0]; |
||
| 89 | my ($fh, $var, $val); |
||
| 90 | my @tmp; |
||
| 91 | my $result = {};
|
||
| 92 | open($fh, '<', "/proc/acpi/battery/BAT${batt_num}/${file}") or die $!;
|
||
| 93 | foreach my $line (<$fh>) |
||
| 94 | {
|
||
| 95 | chomp ($line); |
||
| 96 | ($var, $val) = split(':', $line);
|
||
| 97 | if ( $val =~ m/^\s*$/ ) |
||
| 98 | {
|
||
| 99 | $val = "unknown"; |
||
| 100 | } |
||
| 101 | elsif ( $var ne "batery type" or $var ne "serial number" or $var ne "OEM info" ) |
||
| 102 | {
|
||
| 103 | @tmp = split(" " ,$val);
|
||
| 104 | $val = trim($tmp[0]); |
||
| 105 | } |
||
| 106 | $result->{$var} = $val;
|
||
| 107 | #print "$var, -$val- \n"; |
||
| 108 | } |
||
| 109 | close($fh); |
||
| 110 | return $result; |
||
| 111 | } |
||
| 112 | |||
| 113 | my $batt_data = {};
|
||
| 114 | $batt_data->{'info'} = read_data("info" );
|
||
| 115 | $batt_data->{'state'} = read_data("state");
|
||
| 116 | |||
| 117 | #print Dumper($batt_data); |
||
| 118 | |||
| 119 | if ($ARGV[0] and $ARGV[0] eq "config") |
||
| 120 | {
|
||
| 121 | my $batt_name = sprintf("%s %s %s", $batt_data->{'info'}{'OEM info'}, $batt_data->{'info'}{'battery type'}, $batt_data->{'info'}{'model number'});
|
||
| 122 | print ("graph_args --base 1000\n");
|
||
| 123 | printf ("graph_title Battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||
| 124 | printf ("graph_info This graph shows battery %s (%s) %s\n" , $batt_num, $batt_name, $graph_type);
|
||
| 125 | print ("graph_category power\n");
|
||
| 126 | if ($graph_type eq "capacity") |
||
| 127 | {
|
||
| 128 | print ("graph_vlabel Capacity, mAh\n");
|
||
| 129 | print ("dc.label Design capacity\ndc.type GAUGE\ndc.draw AREA\n");
|
||
| 130 | print ("lfc.label Last full capacity\nlfc.type GAUGE\nlfc.draw AREA\n");
|
||
| 131 | print ("dcl.label Design capacity low\ndcl.type GAUGE\ndcl.draw LINE2\n");
|
||
| 132 | print ("dcw.label Design capacity warning\ndcw.type GAUGE\ndcw.draw LINE2\n");
|
||
| 133 | print ("cg1.label Capacity granularity 1\ncg1.type GAUGE\ncg1.draw LINE2\n");
|
||
| 134 | print ("cg2.label Capacity granularity 2\ncg2.type GAUGE\ncg2.draw LINE2\n");
|
||
| 135 | print ("rc.label Remaining capacity\nrc.type GAUGE\nrc.draw LINE2\n");
|
||
| 136 | print ("pr.label Present rate (mA)\npr.type GAUGE\npr.draw LINE2\n");
|
||
| 137 | } |
||
| 138 | elsif ($graph_type eq "voltage") |
||
| 139 | {
|
||
| 140 | print ("graph_vlabel Voltage, mV\n");
|
||
| 141 | print ("d.label Design voltage\nd.type GAUGE\nd.draw AREA\n");
|
||
| 142 | print ("p.label Present voltage\np.type GAUGE\np.draw AREA\n");
|
||
| 143 | } |
||
| 144 | elsif ($graph_type eq "percents") |
||
| 145 | {
|
||
| 146 | print ("graph_vlabel %\n");
|
||
| 147 | print ("cv.label Current voltage\ncv.type GAUGE\ncv.draw LINE2\n");
|
||
| 148 | print ("cc.label Current capacity\ncc.type GAUGE\ncc.draw LINE2\n");
|
||
| 149 | print ("fc.label Full capacity (of design)\nfc.type GAUGE\nfc.draw LINE2\n");
|
||
| 150 | } |
||
| 151 | exit 0; |
||
| 152 | } |
||
| 153 | |||
| 154 | #$batt_data->{'info'}{''}
|
||
| 155 | sub percent |
||
| 156 | {
|
||
| 157 | my ($full, $current) = @_[0..1]; |
||
| 158 | return $current/($full/100); |
||
| 159 | } |
||
| 160 | |||
| 161 | if ($graph_type eq "capacity") |
||
| 162 | {
|
||
| 163 | printf ("dc.value %s\n", $batt_data->{'info'}{'design capacity'});
|
||
| 164 | printf ("lfc.value %s\n", $batt_data->{'info'}{'last full capacity'});
|
||
| 165 | printf ("dcl.value %s\n", $batt_data->{'info'}{'design capacity low'});
|
||
| 166 | printf ("dcw.value %s\n", $batt_data->{'info'}{'design capacity warning'});
|
||
| 167 | printf ("cg1.value %s\n", $batt_data->{'info'}{'capacity granularity 1'});
|
||
| 168 | printf ("cg2.value %s\n", $batt_data->{'info'}{'capacity granularity 2'});
|
||
| 169 | printf ("rc.value %s\n", $batt_data->{'state'}{'remaining capacity'});
|
||
| 170 | printf ("pr.value %s\n", $batt_data->{'state'}{'present rate'});
|
||
| 171 | } |
||
| 172 | elsif ($graph_type eq "voltage") |
||
| 173 | {
|
||
| 174 | printf ("d.value %s\n", $batt_data->{'info'}{'design voltage'});
|
||
| 175 | printf ("p.value %s\n", $batt_data->{'state'}{'present voltage'});
|
||
| 176 | } |
||
| 177 | elsif ($graph_type eq "percents") |
||
| 178 | {
|
||
| 179 | printf ("cv.value %s\n", percent($batt_data->{'info'}{'design voltage'},$batt_data->{'state'}{'present voltage'}));
|
||
| 180 | printf ("cc.value %s\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'state'}{'remaining capacity'}));
|
||
| 181 | printf ("fc.value %s\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'info'}{'last full capacity'}));
|
||
| 182 | } |
||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | |||
| 188 | |||
| 189 |
