Get system uptime on battery

batterypower-managementuptime

How to know system uptime under battery ?
so that i can get exact time of battery backup
the uptime shows complete uptime (AC/Battery)

NOTE : I am using linux Mint 17.

Best Answer

You can use UDEV to get the particulars about your system's battery.

connected to power
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:0a/PNP0C09:00/PNP0C0A:00/power_supply/BAT0
  vendor:               Panasonic
  model:                42T4801
  serial:               624
  power supply:         yes
  updated:              Sat Oct 18 13:17:16 2014 (2 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    energy:              80.5788 Wh
    energy-empty:        0 Wh
    energy-full:         80.9892 Wh
    energy-full-design:  84.24 Wh
    energy-rate:         0.00372912 W
    voltage:             12.224 V
    percentage:          99.4933%
    capacity:            96.141%
    technology:          lithium-ion
on battery
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:0a/PNP0C09:00/PNP0C0A:00/power_supply/BAT0
  vendor:               Panasonic
  model:                42T4801
  serial:               624
  power supply:         yes
  updated:              Sat Oct 18 13:37:36 2014 (22 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    energy:              79.9524 Wh
    energy-empty:        0 Wh
    energy-full:         80.9892 Wh
    energy-full-design:  84.24 Wh
    energy-rate:         17.172 W
    voltage:             11.94 V
    time to empty:       4.7 hours
    percentage:          98.7198%
    capacity:            96.141%
    technology:          lithium-ion
  History (charge):
    1413653856  98.720  discharging
    1413653826  98.893  discharging
    1413653796  99.080  discharging
    1413653766  99.293  discharging
  History (rate):
    1413653856  17.172  discharging
    1413653826  17.399  discharging
    1413653796  17.453  discharging
    1413653766  17.345  discharging

I've never seen anything that shows the time that's elapsed on battery, so you'll have to calculate it from the above output. Also this output will typically show a "time to charge" which is a rough indicator of how long it was on power.

Related Question