Skip to content

Commit

Permalink
Client: Add LOG_CPU_AND_MEMORY option
Browse files Browse the repository at this point in the history
  • Loading branch information
goldarte committed Nov 19, 2019
1 parent dcfdfe2 commit 90b0a97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Drone/client_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ port = 123
[TELEMETRY]
frequency = 1
transmit = True
log_cpu_and_memory = True

[ANIMATION]
takeoff_animation_check = True
Expand Down
14 changes: 14 additions & 0 deletions Drone/copter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datetime
import logging
import threading
import psutil
import subprocess
import ConfigParser
from collections import namedtuple
Expand Down Expand Up @@ -75,6 +76,7 @@ def load_config(self):
super(CopterClient, self).load_config()
self.TELEM_FREQ = self.config.getfloat('TELEMETRY', 'frequency')
self.TELEM_TRANSMIT = self.config.getboolean('TELEMETRY', 'transmit')
self.LOG_CPU_AND_MEMORY = self.config.getboolean('TELEMETRY', 'log_cpu_and_memory')
self.FRAME_ID = self.config.get('COPTERS', 'frame_id')
self.FRAME_FLIPPED_HEIGHT = 0.
self.TAKEOFF_HEIGHT = self.config.getfloat('COPTERS', 'takeoff_height')
Expand Down Expand Up @@ -736,6 +738,18 @@ def telemetry_loop():
tasks_cleared = True
else:
tasks_cleared = False
if client.active_client.LOG_CPU_AND_MEMORY:
cpu_usage = psutil.cpu_percent(interval=None, percpu=True)
mem_usage = psutil.virtual_memory().percent
cpu_temp_info = psutil.sensors_temperatures()['cpu-thermal'][0]
cpu_temp = cpu_temp_info.current
if cpu_temp_info.critical:
cpu_temp_state = 'critical'
elif cpu_temp_info.high:
cpu_temp_state = 'high'
else:
cpu_temp_state = 'normal'
logger.info("CPU usage: {} | Memory: {} % | T: {} ({})".format(cpu_usage, mem_usage, cpu_temp, cpu_temp_state))

rate.sleep()

Expand Down

0 comments on commit 90b0a97

Please sign in to comment.