MMCT TEAM
Server IP : 192.185.129.71  /  Your IP : 3.144.40.78
Web Server : Apache
System : Linux bh-ht-3.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : svymadmin ( 4072)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/dstat/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/dstat/dstat_battery_remain.py
### Author: Dag Wieers <dag$wieers,com>

class dstat_plugin(dstat):
    """
    Remaining battery time.

    Calculated from power drain and remaining battery power. Information is
    retrieved from ACPI.
    """

    def __init__(self):
        self.name = 'remain'
        self.type = 't'
        self.width = 5
        self.scale = 0

    def vars(self):
        ret = []
        for battery in os.listdir('/proc/acpi/battery/'):
            for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
                l = line.split()
                if len(l) < 2: continue
                if l[0] == 'present:' and l[1] == 'yes':
                    ret.append(battery)
        ret.sort()
        return ret

    def nick(self):
        return [name.lower() for name in self.vars]

    def extract(self):
        for battery in self.vars:
            for line in dopen('/proc/acpi/battery/'+battery+'/state').readlines():
                l = line.split()
                if len(l) < 3: continue
                if l[0:2] == ['remaining', 'capacity:']:
                    remaining = int(l[2])
                    continue
                elif l[0:2] == ['present', 'rate:']:
                    rate = int(l[2])
                    continue

            if rate and remaining:
                self.val[battery] = remaining * 60 / rate
            else:
                self.val[battery] = -1

# vim:ts=4:sw=4:et

MMCT - 2023