feat: add automation last_run_start, next_run, enabled in the automation collector
This commit is contained in:
parent
3922082a56
commit
348a4b5cf0
1 changed files with 27 additions and 6 deletions
|
@ -121,19 +121,40 @@ class AutomationCollector(Collector):
|
||||||
"Status of a database collector (0: bad, 1: good)",
|
"Status of a database collector (0: bad, 1: good)",
|
||||||
labels=["collector"])
|
labels=["collector"])
|
||||||
try:
|
try:
|
||||||
c = GaugeMetricFamily("automation_state", "The automation state (0: idle, 1: running, 2: error)",
|
state = GaugeMetricFamily("automation_state", "The automation state (0: idle, 1: running, 2: error)",
|
||||||
labels=['automation_name'])
|
labels=['automation_name'])
|
||||||
|
enabled = GaugeMetricFamily("automation_enabled",
|
||||||
|
"Whether an automation is enabled (0: disabled, 1: enabled)",
|
||||||
|
labels=['automation_name'])
|
||||||
|
next_run = GaugeMetricFamily("automation_next_run", "The timestamp of the next run of the automation",
|
||||||
|
labels=['automation_name'])
|
||||||
|
last_run_start = GaugeMetricFamily("automation_last_run_start",
|
||||||
|
"The timestamp of the last run of the automation ",
|
||||||
|
labels=['automation_name'])
|
||||||
|
|
||||||
automations = Automation.query.all()
|
automations = Automation.query.all()
|
||||||
for automation in automations:
|
for automation in automations:
|
||||||
if automation.short_name in app.config['HIDDEN_AUTOMATIONS']:
|
if automation.short_name in app.config['HIDDEN_AUTOMATIONS']:
|
||||||
continue
|
continue
|
||||||
if automation.state == AutomationState.IDLE:
|
if automation.state == AutomationState.IDLE:
|
||||||
c.add_metric([automation.short_name], 0)
|
state.add_metric([automation.short_name], 0)
|
||||||
elif automation.state == AutomationState.RUNNING:
|
elif automation.state == AutomationState.RUNNING:
|
||||||
c.add_metric([automation.short_name], 1)
|
state.add_metric([automation.short_name], 1)
|
||||||
else:
|
else:
|
||||||
c.add_metric([automation.short_name], 2)
|
state.add_metric([automation.short_name], 2)
|
||||||
yield c
|
enabled.add_metric([automation.short_name], 1 if automation.enabled else 0)
|
||||||
|
if automation.next_run:
|
||||||
|
next_run.add_metric([automation.short_name], automation.next_run.timestamp())
|
||||||
|
else:
|
||||||
|
next_run.add_metric([automation.short_name], 0)
|
||||||
|
if automation.last_run:
|
||||||
|
last_run_start.add_metric([automation.short_name], automation.last_run.timestamp())
|
||||||
|
else:
|
||||||
|
last_run_start.add_metric([automation.short_name], 0)
|
||||||
|
yield state
|
||||||
|
yield enabled
|
||||||
|
yield next_run
|
||||||
|
yield last_run_start
|
||||||
ok.add_metric(["automation_state"], 1)
|
ok.add_metric(["automation_state"], 1)
|
||||||
except SQLAlchemyError:
|
except SQLAlchemyError:
|
||||||
ok.add_metric(["automation_state"], 0)
|
ok.add_metric(["automation_state"], 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue