Skip to content

Commit

Permalink
fix: Fix prometheus style, removing initial blank line and simplifyin…
Browse files Browse the repository at this point in the history
…g formatting.
  • Loading branch information
andrewjw committed Oct 13, 2020
1 parent 695e58c commit 616c73f
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions glowprom/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
# - 01: ProviderName (string)


METRIC = "consumption{{type='{type}',period='{period}'}} {value}"
METER = "meter{{type='{type}'}} {value}"


def prometheus(msg):
# Code adapted from
# https://gist.github.com/ndfred/b373eeafc4f5b0870c1b8857041289a9
Expand Down Expand Up @@ -98,13 +102,27 @@ def prometheus(msg):
gas_multiplier / gas_divisor
gas_meter = gas_meter * gas_multiplier / gas_divisor

return f"""
consumption{{type='electricity',period='daily'}} {elec_daily_consumption}
consumption{{type='electricity',period='weekly'}} {elec_weekly_consumption}
consumption{{type='electricity',period='monthly'}} {elec_monthly_consumption}
meter{{type='electricity'}} {electricity_meter}
consumption{{type='gas',period='daily'}} {gas_daily_consumption}
consumption{{type='gas',period='weekly'}} {gas_weekly_consumption}
consumption{{type='gas',period='monthly'}} {gas_monthly_consumption}
meter{{type='gas'}} {gas_meter}
"""
return "\n".join([
METRIC.format(type="electricity",
period="daily",
value=elec_daily_consumption),
METRIC.format(type="electricity",
period="weekly",
value=elec_weekly_consumption),
METRIC.format(type="electricity",
period="monthly",
value=elec_monthly_consumption),
METER.format(type="electricity",
value=electricity_meter),
METRIC.format(type="gas",
period="daily",
value=gas_daily_consumption),
METRIC.format(type="gas",
period="weekly",
value=gas_weekly_consumption),
METRIC.format(type="gas",
period="monthly",
value=elec_monthly_consumption),
METER.format(type="gas",
value=gas_meter),
])

0 comments on commit 616c73f

Please sign in to comment.