Add logging messgaes
This commit is contained in:
parent
92f5af943d
commit
2cf072256f
17
app/main.py
17
app/main.py
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
# https://pimylifeup.com/raspberry-pi-temperature/
|
# https://pimylifeup.com/raspberry-pi-temperature/
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from prometheus_client import start_http_server, Gauge, REGISTRY, GC_COLLECTOR, PLATFORM_COLLECTOR, PROCESS_COLLECTOR
|
from prometheus_client import start_http_server, Gauge, REGISTRY, GC_COLLECTOR, PLATFORM_COLLECTOR, PROCESS_COLLECTOR
|
||||||
|
|
||||||
@ -12,16 +14,27 @@ REGISTRY.unregister(GC_COLLECTOR)
|
|||||||
REGISTRY.unregister(PLATFORM_COLLECTOR)
|
REGISTRY.unregister(PLATFORM_COLLECTOR)
|
||||||
REGISTRY.unregister(PROCESS_COLLECTOR)
|
REGISTRY.unregister(PROCESS_COLLECTOR)
|
||||||
|
|
||||||
|
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def setup_gauge():
|
def setup_gauge():
|
||||||
|
logging.info('Setting up Gauge')
|
||||||
g = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature', ['node_name'])
|
g = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature', ['node_name'])
|
||||||
g.labels(_get_node_name())
|
logging.info(f'Created Gauge: {g}')
|
||||||
|
|
||||||
|
labels = [_get_node_name()]
|
||||||
|
logging.info(f'Retrieved labels {labels}')
|
||||||
|
g.labels(labels)
|
||||||
|
|
||||||
|
logging.info('Setting function for Gauge')
|
||||||
g.set_function(_get_temp)
|
g.set_function(_get_temp)
|
||||||
|
|
||||||
|
|
||||||
def _get_temp():
|
def _get_temp():
|
||||||
return float(subprocess.run(['/usr/bin/vcgencmd', 'measure_temp'], capture_output=True).stdout.decode('utf-8')
|
temp = float(subprocess.run(['/usr/bin/vcgencmd', 'measure_temp'], capture_output=True).stdout.decode('utf-8')
|
||||||
.replace('temp=', '').replace("'C\n", ''))
|
.replace('temp=', '').replace("'C\n", ''))
|
||||||
|
logging.info(f'Got temp: {temp}')
|
||||||
|
return temp
|
||||||
|
|
||||||
|
|
||||||
def _get_node_name():
|
def _get_node_name():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user