User Tools

Site Tools


macbook_battery_monitoring

MacBook Battery Monitoring

Introduction

I bought a MacBook Pro in 2013 and wrote a script to routinely monitor the battery health. The script has run regularly since November 2013.

The Software

The script is very basic and I was new to Bash when I first wrote it in 2013; I haven't changed it at all since then.

#!/usr/bin/env bash

datetime=$(date)
batt=$(/usr/sbin/ioreg -l | grep -i "capacity")
echo "$datetime" >> /test.txt
echo "**" >> /test.txt
echo "$batt" >> /test.txt
echo "**" >> /test.txt

I have configured this script to run every 30 minutes with the following crontab config:

*/30 * * * * bash batt.sh

Example Output

Here is a snippet from the data I have gathered recently:

Thu Apr  1 13:00:01 BST 2021
**
    | |           "AppleRawCurrentCapacity" = 5639
    | |           "AppleRawMaxCapacity" = 8021
    | |           "MaxCapacity" = 8021
    | |           "CurrentCapacity" = 5639
    | |           "LegacyBatteryInfo" = {"Amperage"=18446744073709547542,"Flags"=4,"Capacity"=8021,"Current"=5639,"Voltage"=11612,"Cycle Count"=190}
    | |           "DesignCapacity" = 8440
    | |           "BatteryData" = {"StateOfCharge"=18688,"Voltage"=11918,"QmaxCell1"=15651,"QmaxCell2"=2082,"DesignCapacity"=8440,"QmaxCell0"=53282,"CycleCount"=190}
**
Fri Apr  2 10:30:01 BST 2021
**
    | |           "AppleRawCurrentCapacity" = 7805
    | |           "AppleRawMaxCapacity" = 8175
    | |           "MaxCapacity" = 8175
    | |           "CurrentCapacity" = 7805
    | |           "LegacyBatteryInfo" = {"Amperage"=18446744073709550612,"Flags"=4,"Capacity"=8175,"Current"=7805,"Voltage"=12453,"Cycle Count"=190}
    | |           "DesignCapacity" = 8440
    | |           "BatteryData" = {"StateOfCharge"=24832,"Voltage"=12754,"QmaxCell1"=6179,"QmaxCell2"=2594,"DesignCapacity"=8440,"QmaxCell0"=48674,"CycleCount"=190}
**
Fri Apr  2 11:00:00 BST 2021
**
    | |           "AppleRawCurrentCapacity" = 6992
    | |           "AppleRawMaxCapacity" = 8120
    | |           "MaxCapacity" = 8120
    | |           "CurrentCapacity" = 6992
    | |           "LegacyBatteryInfo" = {"Amperage"=18446744073709550047,"Flags"=4,"Capacity"=8120,"Current"=6992,"Voltage"=12199,"Cycle Count"=190}
    | |           "DesignCapacity" = 8440
    | |           "BatteryData" = {"StateOfCharge"=22528,"Voltage"=12045,"QmaxCell1"=6179,"QmaxCell2"=2594,"DesignCapacity"=8440,"QmaxCell0"=48674,"CycleCount"=190}
**
Fri Apr  2 11:30:00 BST 2021
**

Battery Replacement

In October 2018, I replaced the battery due to swelling.

Original Battery

I used the data collected from the original MacBook battery to create 2 graphs using a website I wrote. Here is a screenshot of those graphs:

Graph of battery cycles and health

There are 2 noteworthy points on this graph which I have annotated.

Point A (24th October 2013 – 8th November 2013) is the period of time where I owned the MacBook but hadn’t created the script.

Point B (27th January 2016 – 6th July 2016) is a period of time where the MacBook was out of my possession and not running the script; I’m not sure how much it was used during that period but it accumulated 2 cycles at some point within that timeframe.

The original Apple battery lasted almost exactly 5 years before failing due to swelling. It reached 305 charge cycles. Here is the final image of the original battery (partially removed from the MacBook):

MacBook with 2 of 6 battery cells removed

Second Battery

I bought my replacement battery from the official iFixit EU Store (product EU117046-4). System Information on MacOS reports the battery name as `bq20z451` made by SMP. This battery immediately reported zero charge cycles and a health of 104.57% when first installed.

This battery has been performing perfectly (comparable to the original battery). I have collected and graphed data between 16th October 2018 and 2nd April 2021 which can be seen below:

Graph of battery cycles and health

This battery currently has 190 charge cycles and reports a health of 95.39%. There are 2 small gaps in the data for the new battery: both were caused by the MacBook going unused for a while and not by an issue with the monitoring.

I am still using this replacement battery and the health of it continues to be monitored at 30-minute intervals.

Conclusion

The data collected with this script isn't particularly useful but it can be interesting to see how battery usage trends changed over time. The monitoring script is very lightweight and it becomes easy to forget it's even running. For that reason, I see no particular reason why you shouldn't run something like this on your own laptops.

macbook_battery_monitoring.txt · Last modified: 2021/05/30 20:45 by joseph

Page Tools