Skip to content

Commit

Permalink
fix: Add help and type for prometheus metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjw committed Oct 14, 2020
1 parent 937688e commit dea4cd4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions glowprom/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
METRIC = "consumption{{type=\"{type}\",period=\"{period}\"}} {value}"
METER = "meter{{type=\"{type}\"}} {value}"

METRIC_HELP = "# HELP consumption The consumption over the given period."
METRIC_TYPE = "# TYPE consumption counter"

METER_HELP = "# HELP meter The meter reading."
METER_TYPE = "# TYPE meter counter"

def prometheus(msg):
# Code adapted from
Expand Down Expand Up @@ -103,6 +108,8 @@ def prometheus(msg):
gas_meter = gas_meter * gas_multiplier / gas_divisor

return "\n".join([
METRIC_HELP,
METRIC_TYPE,
METRIC.format(type="electricity",
period="daily",
value=elec_daily_consumption),
Expand All @@ -112,8 +119,6 @@ def prometheus(msg):
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),
Expand All @@ -123,6 +128,10 @@ def prometheus(msg):
METRIC.format(type="gas",
period="monthly",
value=elec_monthly_consumption),
METER_HELP,
METER_TYPE,
METER.format(type="electricity",
value=electricity_meter),
METER.format(type="gas",
value=gas_meter),
])

0 comments on commit dea4cd4

Please sign in to comment.