Projet

Général

Profil

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

root / plugins / battery / acpi_sys_batt_ @ 32264463

Historique | Voir | Annoter | Télécharger (4,12 ko)

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

    
4
=head1 NAME
5

    
6
acpi_sys_batt_ Munin plugin to monitor the (note|net)book battery states through sysfs
7

    
8
=head1 APPLICABLE SYSTEMS
9

    
10
Notebooks and netbooks with available /sys/class/power_supply
11

    
12
=head1 CONFIGURATION
13

    
14
Configured change the name of symbolic link
15

    
16
acpi_sys_batt_X_capacity - chart of Charge full by design, Charge full and Charge now
17
acpi_sys_batt_X_current  - chart of battery current
18
acpi_sys_batt_X_percents - percentage chart of Current/design voltage, Full/current capacity, Design/full capacity
19
acpi_sys_batt_X_voltage  - chart of Design min voltage and Current voltage
20
Where X is the number of batteries from /sys/class/power_supply/BATX
21

    
22
=head1 INTERPRETATION
23

    
24
The plugin shows:
25
 Charge full by design
26
 Charge full
27
 Charge now
28
 Battery current
29
 Percentage Current/design voltage
30
 Percentage Full/current capacity
31
 Percentage Design/full capacity
32
 Design min voltage
33
 Current voltage
34

    
35
=head1 MAGIC MARKERS
36

    
37
#%# family=power
38

    
39
=head1 VERSION
40
=head1 BUGS
41

    
42
None known.
43

    
44
=head1 AUTHOR
45

    
46
Gorlow Maxim <sheridan@sheridan-home.ru>
47

    
48
=head1 LICENSE
49

    
50
GPLv2
51

    
52
=cut
53

    
54
use strict;
55
#use Data::Dumper;
56

    
57
my ($graph_type, $batt_num);
58
if ($0 =~ /^(?:|.*\/)acpi_sys_batt_([^_]+)_(.+)$/)
59
{
60
    $graph_type = $2;
61
    $batt_num = $1;
62
}
63
elsif (!defined($batt_num) or !defined($graph_type)) {
64
    die "# Error: couldn't understand what I'm supposed to monitor."; }
65

    
66
my $sys_path=sprintf("/sys/class/power_supply/BAT%d", $batt_num);
67

    
68
#print "$batt_num, $graph_type \n";
69

    
70
sub cat_file
71
{
72
	my $file = $_[0];
73
	my $fh;
74
	my $file_content = "--";
75
	open($fh, '<', "${sys_path}/${file}") or die $!;
76
	foreach my $line (<$fh>)
77
	{
78
		chomp ($line);
79
		$file_content = $line;
80
	}
81
	close($fh);
82
	return $file_content;
83
}
84

    
85
#print Dumper($batt_data);
86

    
87
if ($ARGV[0] and $ARGV[0] eq "config")
88
{
89

    
90
#manufacturer
91
#model_name
92
#serial_number
93
# ----------- status
94
#technology
95
#type
96

    
97

    
98
	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'));
99
	print  ("graph_args --base 1000\n");
100
	printf ("graph_title Battery %d (%s) %s\n" , $batt_num, $batt_name, $graph_type);
101
	printf ("graph_info This graph shows battery %d (%s) %s\n" , $batt_num, $batt_name, $graph_type);
102
	print  ("graph_category sensors\n");
103
	if ($graph_type eq "capacity")
104
	{
105
		print  ("graph_vlabel Charge\n");
106
		print  ("cfd.label Charge full design\ncfd.type GAUGE\ncfd.draw AREA\n");
107
		print  ("cf.label Charge full\ncf.type GAUGE\ncf.draw AREA\n");
108
		print  ("cn.label Charge now\ncn.type GAUGE\ncn.draw AREA\n");
109
	}
110
	elsif ($graph_type eq "current")
111
	{
112
		print  ("graph_vlabel Current, mAh\n");
113
		print  ("currn.label Current\ncurrn.type GAUGE\ncurrn.draw AREA\n");
114
	}
115
	elsif ($graph_type eq "voltage")
116
	{
117
		print  ("graph_vlabel Voltage, mV\n");
118
		print  ("vmd.label Design min voltage\nvmd.type GAUGE\nvmd.draw AREA\n");
119
		print  ("vn.label Voltage now\nvn.type GAUGE\nvn.draw AREA\n");
120
	}
121
	elsif ($graph_type eq "percents")
122
	{
123
		print  ("graph_vlabel %\n");
124
		print  ("cv.label Current/design voltage\ncv.type GAUGE\ncv.draw LINE2\n");
125
		print  ("cc.label Full/current capacity\ncc.type GAUGE\ncc.draw LINE2\n");
126
		print  ("fc.label Design/full capacity\nfc.type GAUGE\nfc.draw LINE2\n");
127
	}
128
	exit 0;
129
}
130

    
131
#$batt_data->{'info'}{''}
132
sub percent
133
{
134
	my ($full, $current) = @_[0..1];
135
	return $current/($full/100);
136
}
137

    
138
#charge_full
139
#charge_full_design
140
#charge_now
141
#current_now
142
#voltage_min_design
143
#voltage_now
144

    
145
if ($graph_type eq "capacity")
146
{
147
	printf ("cfd.value %d\n", cat_file('charge_full_design'));
148
	printf ("cf.value %d\n", cat_file('charge_full'));
149
	printf ("cn.value %d\n", cat_file('charge_now'));
150
}
151
elsif ($graph_type eq "voltage")
152
{
153
	printf ("vmd.value %d\n", cat_file('voltage_min_design'));
154
	printf ("vn.value %d\n", cat_file('voltage_now'));
155
}
156
elsif ($graph_type eq "current")
157
{
158
	printf ("currn.value %d\n", cat_file('current_now'));
159
}
160
elsif ($graph_type eq "percents")
161
{
162
	printf ("cv.value %d\n", percent(cat_file('voltage_min_design'),cat_file('voltage_now')));
163
	printf ("cc.value %d\n", percent(cat_file('charge_full'),cat_file('charge_now')));
164
	printf ("fc.value %d\n", percent(cat_file('charge_full_design'),cat_file('charge_full')));
165
}