Skip to content

Commit

Permalink
updated monitoring for Orange Pi 3B and Raspberry Pi 4B
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkhamLee committed Feb 20, 2024
1 parent 91374db commit 8c90a7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 12 additions & 5 deletions hardware_telemetry/orangepi_3b/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@
import gc
import os
import logging
from sys import stdout
from orangepi3b_data import OrangePi3BData

# set up/configure logging with stdout so it can be picked up by K8s
logger = logging.getLogger('Orange_Pi_3B_Telemetry')
logger.setLevel(logging.DEBUG)

# create logger for logging errors, exceptions and the like
logging.basicConfig(filename='hardwareDataRockChip.log', level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s\
: %(message)s')
handler = logging.StreamHandler(stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(message)s') # noqa: E501
handler.setFormatter(formatter)
logger.addHandler(handler)


def monitor(client: object, getData: object, topic: str):

DEVICE_ID = os.environ['DEVICE_ID']

while True:

time.sleep(1)
Expand Down Expand Up @@ -52,7 +59,7 @@ def monitor(client: object, getData: object, topic: str):
if status != 0:

print(f'Failed to send {payload} to: {topic}')
logging.debug(f'MQTT publishing failure, return code: {status}')
logger.debug(f'MQTT publishing failure for hardware monitoring on: {DEVICE_ID}, return code: {status}') # noqa: E501

del payload, cpu_util, ram_use, cpu_freq, cpu_temp, gpu_temp, \
status, result
Expand Down
18 changes: 13 additions & 5 deletions hardware_telemetry/raspberrypi_4b/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@
import time
import gc
import logging
from sys import stdout
from rpi4b_data import Rpi4bData

# create logger for logging errors, exceptions and the like
logging.basicConfig(filename='hardware_data_rpi4b.log', level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s\
: %(message)s')
# set up/configure logging with stdout so it can be picked up by K8s
logger = logging.getLogger('Raspberry_Pi_4B_Telemetry')
logger.setLevel(logging.DEBUG)

handler = logging.StreamHandler(stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(message)s') # noqa: E501
handler.setFormatter(formatter)
logger.addHandler(handler)


def monitor(client: object, getData: object, topic: str):

DEVICE_ID = os.environ['DEVICE_ID']

while True:

time.sleep(1)
Expand Down Expand Up @@ -53,7 +61,7 @@ def monitor(client: object, getData: object, topic: str):
if status != 0:

print(f'Failed to send {payload} to: {topic}')
logging.debug(f'MQTT publishing failure, return code: {status}')
logger.debug(f'MQTT publishing failure for hardware monitoring on: {DEVICE_ID}, return code: {status}') # noqa: E501

del payload, cpuUtil, ramUse, cpuFreq, cpuTemp, status, result
gc.collect()
Expand Down

0 comments on commit 8c90a7a

Please sign in to comment.