Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / battery / acpi_batt_ @ 32264463

Historique | Voir | Annoter | Télécharger (5,27 ko)

1
#!/usr/bin/perl -w
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
acpi_batt_ - monitor the (note|net)book battery states through procfs
7

    
8
=head1 APPLICABLE SYSTEMS
9

    
10
Notebooks and netbooks with available /proc/acpi/battery
11

    
12
=head1 CONFIGURATION
13

    
14
The name of the plugin (or its symbolic link) determines the retrieved data.
15

    
16
=over
17

    
18
=item 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)
19

    
20
=item acpi_batt_X_percents: percentage chart of Current voltage, Current capacity, Full capacity (of design)
21

    
22
=item acpi_batt_X_voltage: chart of Design voltage, Present voltage
23

    
24
=back
25

    
26
Where X is the number of battery from /proc/acpi/battery/BATX
27

    
28
=head1 INTERPRETATION
29

    
30
The plugin shows:
31

    
32
=over
33

    
34
=item Design capacity
35

    
36
=item Last full capacity
37

    
38
=item Design capacity low
39

    
40
=item Design capacity warning
41

    
42
=item Capacity granularity 1
43

    
44
=item Capacity granularity 2
45

    
46
=item Remaining capacity
47

    
48
=item Present rate (mA)
49

    
50
=item Percentage Current/design voltage
51

    
52
=item Percentage Full/current capacity
53

    
54
=item Percentage Design/full capacity
55

    
56
=item Design voltage
57

    
58
=item Present voltage
59

    
60
=back
61

    
62

    
63
=head1 MAGIC MARKERS
64

    
65
 #%# family=power
66

    
67
=head1 BUGS
68

    
69
None known.
70

    
71
=head1 AUTHOR
72

    
73
Gorlow Maxim <sheridan@sheridan-home.ru>
74

    
75
=head1 LICENSE
76

    
77
GPLv2
78

    
79
=cut
80

    
81

    
82
use strict;
83
#use Data::Dumper;
84

    
85
my ($graph_type, $batt_num);
86
if ($0 =~ /^(?:|.*\/)acpi_batt_([^_]+)_(.+)$/)
87
{
88
    $graph_type = $2;
89
    $batt_num = $1;
90
}
91
elsif (!defined($batt_num) or !defined($graph_type)) {
92
    die "# Error: couldn't understand what I'm supposed to monitor."; }
93

    
94
#print "$batt_num, $graph_type \n";
95

    
96
sub trim
97
{
98
	my($string)=@_;
99
	for ($string)
100
	{
101
		s/^\s+//;
102
		s/\s+$//;
103
	}
104
	return $string;
105
}
106

    
107

    
108
sub read_data
109
{
110
	my $file = $_[0];
111
	my ($fh, $var, $val);
112
	my @tmp;
113
	my $result = {};
114
	open($fh, '<', "/proc/acpi/battery/BAT${batt_num}/${file}") or die $!;
115
	foreach my $line (<$fh>)
116
	{
117
		chomp ($line);
118
		($var, $val) = split(':', $line);
119
		if ( $val =~ m/^\s*$/ )
120
		{
121
			$val = "unknown";
122
		}
123
		elsif ( $var ne "battery type" or $var ne "serial number" or $var ne "OEM info" )
124
		{
125
			@tmp = split(" " ,$val);
126
			$val = trim($tmp[0]);
127
		}
128
		$result->{$var} = $val;
129
		#print "$var, -$val- \n";
130
	}
131
	close($fh);
132
	return $result;
133
}
134

    
135
my $batt_data = {};
136
$batt_data->{'info'}  = read_data("info" );
137
$batt_data->{'state'} = read_data("state");
138

    
139
#print Dumper($batt_data);
140

    
141
if ($ARGV[0] and $ARGV[0] eq "config")
142
{
143
	my $batt_name = sprintf("%s %s %s", $batt_data->{'info'}{'OEM info'}, $batt_data->{'info'}{'battery type'}, $batt_data->{'info'}{'model number'});
144
	print  ("graph_args --base 1000\n");
145
	printf ("graph_title Battery %d (%s) %s\n" , $batt_num, $batt_name, $graph_type);
146
	printf ("graph_info This graph shows battery %d (%s) %s\n" , $batt_num, $batt_name, $graph_type);
147
	print  ("graph_category sensors\n");
148
	if ($graph_type eq "capacity")
149
	{
150
		print  ("graph_vlabel Capacity, mAh\n");
151
		print  ("dc.label Design capacity\ndc.type GAUGE\ndc.draw AREA\n");
152
		print  ("lfc.label Last full capacity\nlfc.type GAUGE\nlfc.draw AREA\n");
153
		print  ("dcl.label Design capacity low\ndcl.type GAUGE\ndcl.draw LINE2\n");
154
		print  ("dcw.label Design capacity warning\ndcw.type GAUGE\ndcw.draw LINE2\n");
155
		print  ("cg1.label Capacity granularity 1\ncg1.type GAUGE\ncg1.draw LINE2\n");
156
		print  ("cg2.label Capacity granularity 2\ncg2.type GAUGE\ncg2.draw LINE2\n");
157
		print  ("rc.label Remaining capacity\nrc.type GAUGE\nrc.draw LINE2\n");
158
		print  ("pr.label Present rate (mA)\npr.type GAUGE\npr.draw LINE2\n");
159
	}
160
	elsif ($graph_type eq "voltage")
161
	{
162
		print  ("graph_vlabel Voltage, mV\n");
163
		print  ("d.label Design voltage\nd.type GAUGE\nd.draw AREA\n");
164
		print  ("p.label Present voltage\np.type GAUGE\np.draw AREA\n");
165
	}
166
	elsif ($graph_type eq "percents")
167
	{
168
		print  ("graph_vlabel %\n");
169
		print  ("cv.label Current voltage\ncv.type GAUGE\ncv.draw LINE2\n");
170
		print  ("cc.label Current capacity\ncc.type GAUGE\ncc.draw LINE2\n");
171
		print  ("fc.label Full capacity (of design)\nfc.type GAUGE\nfc.draw LINE2\n");
172
	}
173
	exit 0;
174
}
175

    
176
#$batt_data->{'info'}{''}
177
sub percent
178
{
179
	my ($full, $current) = @_[0..1];
180
	return $current/($full/100);
181
}
182

    
183
if ($graph_type eq "capacity")
184
{
185
	printf ("dc.value %d\n", $batt_data->{'info'}{'design capacity'});
186
	printf ("lfc.value %d\n", $batt_data->{'info'}{'last full capacity'});
187
	printf ("dcl.value %d\n", $batt_data->{'info'}{'design capacity low'});
188
	printf ("dcw.value %d\n", $batt_data->{'info'}{'design capacity warning'});
189
	printf ("cg1.value %d\n", $batt_data->{'info'}{'capacity granularity 1'});
190
	printf ("cg2.value %d\n", $batt_data->{'info'}{'capacity granularity 2'});
191
	printf ("rc.value %d\n", $batt_data->{'state'}{'remaining capacity'});
192
	printf ("pr.value %d\n", $batt_data->{'state'}{'present rate'});
193
}
194
elsif ($graph_type eq "voltage")
195
{
196
	printf ("d.value %d\n", $batt_data->{'info'}{'design voltage'});
197
	printf ("p.value %d\n", $batt_data->{'state'}{'present voltage'});
198
}
199
elsif ($graph_type eq "percents")
200
{
201
	printf ("cv.value %d\n", percent($batt_data->{'info'}{'design voltage'},$batt_data->{'state'}{'present voltage'}));
202
	printf ("cc.value %d\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'state'}{'remaining capacity'}));
203
	printf ("fc.value %d\n", percent($batt_data->{'info'}{'design capacity'},$batt_data->{'info'}{'last full capacity'}));
204
}