raoulg / energy-tracker

A simple script (meant to be run via cron) that tracks your Mac laptop's energy usage in watt hours.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

energy-tracker

A simple script (meant to be run via cron) that tracks your Mac laptop's energy usage in watt hours.

NOTE: This will only run on Mac.

Installation

To start, copy the energy tracking script into the correct folder:

sudo cp log-power-usage.sh /usr/local/bin/log-power-usage.sh

Cron

Next, install the cron script which will run the energy tracker once per minute:

crontab -l > cron-new
cat cron >> cron-new
crontab cron-new
rm cron-new

plist

Alternatively, you can install the plist file which will run the energy tracker every 10 seconds. Copy the plist file to the LaunchAgents folder:

cp com.raoulg.log-power-usage.plist ~/Library/LaunchAgents/

Then load the plist file:

launchctl load ~/Library/LaunchAgents/com.raoulg.log-power-usage.plist

In settings > general > Login Items you should see the log-power-usage.sh script under 'allow in background'. This means the script is running.

Viewing Usage Data

Once installed, the energy tracker will log all energy consumption to the file ~/.cache/energy-tracker/energy-log.txt.

This file will look something like this:

timestamp,wattage,wattHours,uuid
2024-04-13T12:02:35Z,8.46427726,.14107128766666666666,8D154220-45E6-5C0D-9753-3DAF9F757909
2024-04-13T12:18:01Z,10.1954079,.16992346500000000000,8D154220-45E6-5C0D-9753-3DAF9F757909
2024-04-13T12:19:01Z,9.24522876,.15408714600000000000,8D154220-45E6-5C0D-9753-3DAF9F757909
2024-04-13T12:20:00Z,9.16311264,.15271854400000000000,8D154220-45E6-5C0D-9753-3DAF9F757909

Each line contains a timestamp, the amount of wattage being used at the time of sampling, the amount of watt-hours being used, and the uuid of the Mac.

About

A simple script (meant to be run via cron) that tracks your Mac laptop's energy usage in watt hours.

License:The Unlicense


Languages

Language:Shell 100.0%