GithubHelp home page GithubHelp logo

petterreinholdtsen / battery-stats Goto Github PK

View Code? Open in Web Editor NEW
27.0 27.0 13.0 201 KB

Log battery charge (battery-stats-collector), show gnuplot graphs (battery-graph)

License: GNU General Public License v2.0

CMake 5.31% Shell 41.74% Python 23.69% Roff 29.26%

battery-stats's People

Contributors

anarcat avatar b3 avatar gillesmocellin avatar illes avatar jcromero avatar marsoft avatar nachtgeist avatar petterreinholdtsen avatar richih avatar rx14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

battery-stats's Issues

cron mail clutter when no batteries connected

/usr/share/battery-stats/collect-csv prints errors when no batteries are connected, resulting in cron mail clutter like

-----8<------
Subject: Cron root@localhost if [ -x /usr/share/battery-stats/collect-csv ]; then /usr/share/battery-stats/collect-csv ; fi (failed)

/usr/share/battery-stats/collect-csv: line 86: cd: BAT*: No such file or directory
-----8<------

Graph is not continuous

Hello,
When removing the AC adapter and plugging it back (or the other way) the graph gets cut. I haven't dug into the code much, but I suspect that those are separate graphs and on plug/unplug action there should be two entries for both datasets.
scrot_20200704_181027

Thanks.

`battery-graph` does not show any graph if AC status was not determined

I have recently installed the package in Arch Linux to my HP Envy laptop. Data collection daemon works fine, and the data is available in /var/log/battery-stats.
But when I try to view graph using battery-graph, it shows an empty graph.

After some investigating, it turned out that on my system AC power adapter was not recognized by battery-stats-collector (due to incorrect packaging, but it is not related to this issue).

After reading plot command in /usr/bin/battery-graph, it turns out that it shows blue line when charging, red line when discharging, and shows nothing when charging status is unknown.
I think we should instead show black or gray line for such data.

battery-stats-graph-flow fails to do anything

i get the following when running the flow program on my logfile:

[1239]anarcat@angela:battery-stats$ /usr/share/battery-stats/battery-stats-graph-flow
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 4.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 4.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 5.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 5.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 6.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 7.
Argument "" isn't numeric in subtraction (-) at - line 17, <$fh> line 8.
Warning: empty y range [0:0], adjusting to [-1:1]

now, maybe it's because i have a screwed up CSV logfile, because I have used the procedure in #3 to convert my previous CSV files... you can reproduce the issue with the following .csv file:

timestamp,when,manufacturer,,technology,serial_number,status,cycle_count,energy_now,energy_full,energy_full_design,charge_now,charge_full,charge_full_design
1443139045,2015-09-24T19:57:25-0400,SANYO,,Li-ion,3016,Charging,0,,,,974000,6602000,6600000
1443139201,2015-09-24T20:00:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,1078000,6602000,6600000
1443139621,2015-09-24T20:07:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,1360000,6602000,6600000
1443139801,2015-09-24T20:10:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,1480000,6602000,6600000
1443140401,2015-09-24T20:20:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,1882000,6602000,6600000
1443141001,2015-09-24T20:30:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,2283000,6602000,6600000
1443141601,2015-09-24T20:40:01-0400,SANYO,,Li-ion,3016,Charging,0,,,,2685000,6602000,6600000

not quite sure what is going on here...

keep more than 5 weeks of logs

this is a rare case of when i think it is relevant to keep a larger amount of logs. the current configuration of the debian package only ships with 5 weeks of logs. that is not a long time to do proper analysis! for example, here's a graph i generated with the data I have so far, which is about 6 months:

6 months of stats

it is barely usable, more samples would be great! this log file takes less than 1MB:

868K    /var/log/battery-stats.csv

and will take 10 times less that when compressed:

$ gzip -c /var/log/battery-stats.csv  | wc
    226    1280   71159

so i would suggest bumping log rotation to "monthly" at least, and make that at least a year. I have set it to 4 years here, but that may be a little extreme:

/var/log/battery-stats {
    rotate 208
    delaycompress
    missingok
    notifempty
    nocopytruncate
    nomail
    weekly
    postrotate
        if which invoke-rc.d >/dev/null 2>&1; then
          invoke-rc.d battery-stats restart > /dev/null
        else
          /etc/init.d/battery-stats restart > /dev/null
        fi
    endscript
}

thanks!

gnuplot >=6.x no longer has '-title' argument

As per title.

unrecognized option -title
line 0: Cannot load input from 'Battery Graph'

Or with bash -x

+ gnuplot -persist -title 'Battery Graph'
+ echo 'zero_time_err = sqrt((A/B**2*B_err)**2+(1.0/B*A_err)**2) }'
+ echo 'full_time = (100-A)/B'
+ echo 'g(x) = x<zero_time?(x>full_time?f(x):1/0):1/0'
+ echo 'set xrange [ 758684676 : 758713476 ] noreverse'
+ echo plot '"/tmp/tmp.tk7Rtpedcl" using ($1 - 946733400):($3==2?$2:1/0) smooth unique axis x1y1 title "Plugged in" with lines linecolor rgb "blue" linewidth 3, 	"" using ($1 - 946733400):($3==1?$2:1/0) smooth unique axis x1y1 title "Discharging" with lines linecolor rgb "red" linewidth 3, 	"" using ($1 - 946733400):($3==0?$2:1/0) smooth unique axis x1y1 title "Unknown" with lines linecolor rgb "gray" linewidth 3 \'
+ true
+ echo ', g(x -(1705388544-946733400) ) title (B<0?sprintf("slope= (%.2f +/- %.2f) %/h", B*3600, B_err*3600):"") lc rgb "black" lt 2 '
unrecognized option -title
line 0: Cannot load input from 'Battery Graph'

Unfortunately I can't interpret what is needed from gnuplots changelog or I'd do an MR.

exit gnuplot after close dialog

--persist option keep graph window live.
however, because you remove the temp file,
window often crash when zoom or panning.

i suggest that use pause mouse close which make gnuplot wait til window close.
then you can remove temperary file safely after gnuplot exit.

this would be a easy patch like this. do you want me to send pull request?

--- /usr/bin/battery-graph	2016-11-17 18:51:44.000000000 +0800
+++ ./battery-graph	2019-01-02 22:10:36.559350289 +0800
@@ -217,10 +217,8 @@
     if $SWITCH_RATE ; then 
 		echo ", g(x -($TIME_LAST_DISCHARGE_BEGIN-$adjustment) ) title (B<0?sprintf(\"slope= (%.2f +/- %.2f) %/h\", B*3600, B_err*3600):\"\") lc rgb \"black\" lt 2 "
     fi
+    echo pause mouse close
     
-)  | gnuplot -persist ${geometry:+-geometry} $geometry ${title:+-title} "${title}" ; rm -f $TMPFILENAME
+)  | gnuplot ${geometry:+-geometry} $geometry ${title:+-title} "${title}"
 
-
-# TODO Have to decide if we want to clean up or leave the file for us to zoom in/out in the graph
-# For now we will just go the clean way and delete everything again.
 rm -f $TMPFILENAME

cannot read old CSV files

for some reason, this software cannot read the files created from the older "battery-status" version. i get this error:

$ /usr/share/battery-stats/battery-stats-graph /var/log/hjemmenett-battery-status.log
loading CSV file <open file '/var/log/hjemmenett-battery-status.log', mode 'r' at 0x7fba9dc6e420> with builtin CSV module
Traceback (most recent call last):
  File "/usr/share/battery-stats/battery-stats-graph", line 171, in <module>
    data = parse_csv()
  File "/usr/share/battery-stats/battery-stats-graph", line 74, in parse_csv_builtin
    if '' == row[f]:
KeyError: 'charge_now'

is there a way to convert the files over? my original python version still works:

$ ~/src/battery-status/battery-status-graph.py /var/log/hjemmenett-battery-status.log
loading CSV file <open file '/var/log/hjemmenett-battery-status.log', mode 'r' at 0x7fe9238b6420> with builtin CSV module
building data array
guessing expiry
this battery will reach end of life (5%) in 904 days, 23:22:16.832222, on 2018-09-15 16:08:27.770046
building graph
drawing on tty

... and crap, it looks like my battery is already at 80% effective capacity!

`battery-stats-collector` should just issue usable lines on stdout and no warning.

In battery-stats-collector when get_logline is unable to determine a value for ac_online it echoes a message warning that "No power supply found". This line then goes to the log file before the status line is echoed.

That way the generated file becomes unusable since every two lines it contains non-data. On my host it looks likes something like :

No power supply found
1474886747 56.11 1 2016/09/26 12:45:47 -
No power supply found
1474886807 56.45 1 2016/09/26 12:46:47 -
No power supply found
1474886867 56.82 1 2016/09/26 12:47:47 -

The warning line should not be echoed, or at least not on stdout.

Init script

I just installed from git and it appears that no init script gets installed by default. I will share the systemd script I created for my system:

# cat /etc/systemd/system/battery-stats-collector.service 
[Unit]
Description = battery-stats-collector daemon

[Service]
Type = simple
PIDFile = /run/battery-stats-collector.pid
ExecStart = /usr/local/sbin/battery-stats-collector
Restart = on-abort
StartLimitInterval = 60
StartLimitBurst = 10

[Install]
WantedBy = multi-user.target

The config file /etc/battery-stats.conf, refers to a certain /etc/init.d/battery-stats script for INIT based systems:

# Default configuration for battery-stats-collector
#
# This file is sourced from /etc/init.d/battery-stats ; it should follow normal
# /bin/sh syntax.
.....

But no such init script is installed during make install, or indeed appears to be present in the git repo.

suspend/resume hooks don't run in jessie

for some reason, suspend/resume hooks don't run here and the data doesn't get collected then.

i have /etc/pm stuff installed here:

$ dpkg -S /etc/pm
unattended-upgrades, toshset, pm-utils: /etc/pm

i am not sure they get fired when my laptop gets suspended/resumed, but then again, i am not sure how that happens in the first place. it may be systemd doing the suspend, but it could also be the laptop's BIOS as well: it's unclear. i know that suspend happens when i close the lid, but that's about it.

later:

http://askubuntu.com/questions/609695/does-systemd-read-etc-pm explain
that /etc/pm/ is ignored by systemd, and suggest to provide units in
/lib/systemd/system-sleep/ instead.

copy from petterreinholdtsen/battery-status#8, see there for more comments

old python graphing script broken

the python script i wrote is still in the package, but not the default and worse, it's actually broken now:

$ battery-log | ./src/battery-stats-graph
loading CSV file <open file '<stdin>', mode 'r' at 0x7f11f0fe10c0> with builtin CSV module
building data array
guessing expiry
Traceback (most recent call last):
  File "./src/battery-stats-graph", line 190, in <module>
    death = guess_expiry(data[full], data['timestamp'], zero)
  File "./src/battery-stats-graph", line 162, in guess_expiry
    fit = np.polyfit(data[full], data['timestamp'], 1)
  File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 581, in polyfit
    c, resids, rank, s = lstsq(lhs, rhs, rcond)
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 1867, in lstsq
    0, work, lwork, iwork, 0)
ValueError: On entry to DLASCL parameter number 4 had an illegal value

my guess is that it wasn't adapted to the new CSV structure, or not correctly. it fails at guessing the death of the battery, above...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.