Use parent-child relationship for gauge
This commit is contained in:
parent
46549c16fd
commit
453b5b56ea
10
app/main.py
10
app/main.py
@ -19,16 +19,16 @@ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
||||
|
||||
def setup_gauge():
|
||||
logging.info('Setting up Gauge')
|
||||
g = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature', ['node_name'])
|
||||
logging.info(f'Created Gauge: {g}')
|
||||
parent_gauge = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature', ['node_name'])
|
||||
logging.info(f'Created Gauge: {parent_gauge}')
|
||||
|
||||
node_name_label = _get_node_name()
|
||||
logging.info(f'Retrieved node_name label {node_name_label}')
|
||||
# Why call `.set()` here? Because, without it, I get "gauge metric is missing label values"
|
||||
g.labels(node_name=node_name_label).set(_get_temp())
|
||||
|
||||
gauge = parent_gauge.labels(node_name=node_name_label)
|
||||
|
||||
logging.info('Setting function for Gauge')
|
||||
g.set_function(_get_temp)
|
||||
gauge.set_function(_get_temp)
|
||||
|
||||
|
||||
def _get_temp():
|
||||
|
Loading…
x
Reference in New Issue
Block a user