fix: using /proc/uptime to correctly calculate uptime in seconds (fixes #264)

This commit is contained in:
Simone Margaritelli
2019-10-13 12:18:35 +02:00
parent 99d7017785
commit 77c16c38f4
2 changed files with 10 additions and 7 deletions

View File

@ -17,6 +17,11 @@ def name():
return _name return _name
def uptime():
with open('/proc/uptime') as fp:
return int(fp.read().split('.')[0])
def mem_usage(): def mem_usage():
out = subprocess.getoutput("free -m") out = subprocess.getoutput("free -m")
for line in out.split("\n"): for line in out.split("\n"):

View File

@ -7,6 +7,7 @@ from datetime import datetime
import logging import logging
import _thread import _thread
import pwnagotchi
import pwnagotchi.utils as utils import pwnagotchi.utils as utils
import pwnagotchi.plugins as plugins import pwnagotchi.plugins as plugins
from pwnagotchi.log import LastSession from pwnagotchi.log import LastSession
@ -241,9 +242,9 @@ class Agent(Client, AsyncAdvertiser, AsyncTrainer):
return None return None
def _update_uptime(self, s): def _update_uptime(self, s):
secs = time.time() - self._started_at secs = pwnagotchi.uptime()
self._view.set('uptime', utils.secs_to_hhmmss(secs)) self._view.set('uptime', utils.secs_to_hhmmss(secs))
self._view.set('epoch', '%04d' % self._epoch.epoch) # self._view.set('epoch', '%04d' % self._epoch.epoch)
def _update_counters(self): def _update_counters(self):
tot_aps = len(self._access_points) tot_aps = len(self._access_points)
@ -276,13 +277,10 @@ class Agent(Client, AsyncAdvertiser, AsyncTrainer):
def _update_advertisement(self, s): def _update_advertisement(self, s):
run_handshakes = len(self._handshakes) run_handshakes = len(self._handshakes)
tot_handshakes = utils.total_unique_handshakes(self._config['bettercap']['handshakes']) tot_handshakes = utils.total_unique_handshakes(self._config['bettercap']['handshakes'])
started = s['started_at'].split('.')[0] self._advertiser.update({
started = datetime.strptime(started, '%Y-%m-%dT%H:%M:%S')
started = time.mktime(started.timetuple())
self._advertiser.update({ \
'pwnd_run': run_handshakes, 'pwnd_run': run_handshakes,
'pwnd_tot': tot_handshakes, 'pwnd_tot': tot_handshakes,
'uptime': time.time() - started, 'uptime': pwnagotchi.uptime(),
'epoch': self._epoch.epoch}) 'epoch': self._epoch.epoch})
def _update_peers(self): def _update_peers(self):