5 for my $psu_path (glob '/sys/class/power_supply/*')
7 my ($psu_name) = $psu_path =~ /([^\/]+)$/;
8 my $percent = file_get_line
("$psu_path/capacity");
9 my $status = file_get_line
("$psu_path/status");
10 my $online = file_get_line
("$psu_path/online");
12 if(not defined $percent and $charge_full)
14 my $charge_full = file_get_line
("$psu_path/charge_full");
15 my $charge_now = file_get_line
("$psu_path/charge_now");
16 $percent = $charge_now*100/$charge_full;
22 print sprintf "%s.percent %d", $psu_name, $percent if defined $percent;
23 print sprintf "%s.status.%s 1", $psu_name, $status if $status;
24 print sprintf "%s.online 1", $psu_name if $online;