Skip to content

Commit

Permalink
Option to gather penalties from all validators
Browse files Browse the repository at this point in the history
Add an envvar (defaults to off) that will gather penalties for
all validators from the ledger. In an effort to reduce the size
of the collection, this "all" mode will filter out validators
with a total penalty of 0.0.

Regardless of this new envvar, last_heartbeat will still only
be gathered for "this" validator.
  • Loading branch information
kellybyrd authored and tedder committed Jul 9, 2021
1 parent ef55ff6 commit 21b8d99
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions miner_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
# for testnet, https://testnet-api.helium.wtf/v1
API_BASE_URL = os.environ.get('API_BASE_URL', 'https://api.helium.io/v1')

# Gather the ledger penalities for all, instead of just "this" validator. When in this
# mode all validators from `miner validator ledger` with a penalty >0.0 will be included.
# The >0 constraint is just to keep data and traffic smaller.
ALL_PENALTIES = os.environ.get('ALL_PENALTIES', 0)

# use the RPC calls where available. This means you have your RPC port open.
# Once all of the exec calls are replaced we can enable this by default.
ENABLE_RPC = os.environ.get('ENABLE_RPC', 0)
Expand Down Expand Up @@ -412,20 +417,25 @@ def collect_ledger_validators(docker_container, miner_name):
continue

(val_name,address,last_heartbeat,stake,status,version,tenure_penalty,dkg_penalty,performance_penalty,total_penalty) = c
if miner_name == val_name:
if ALL_PENALTIES or miner_name == val_name:
log.debug(f"have pen line: {c}")
tenure_penalty_val = try_float(tenure_penalty)
dkg_penalty_val = try_float(dkg_penalty)
performance_penalty_val = try_float(performance_penalty)
total_penalty_val = try_float(total_penalty)
last_heartbeat = try_float(last_heartbeat)

log.info(f"L penalty: {total_penalty_val}")
LEDGER_PENALTY.labels('ledger_penalties', 'tenure', miner_name).set(tenure_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'dkg', miner_name).set(dkg_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'performance', miner_name).set(performance_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'total', miner_name).set(total_penalty_val)
BLOCKAGE.labels('last_heartbeat', miner_name).set(last_heartbeat)
log.debug(f"L penalty: {total_penalty_val}")
if not ALL_PENALTIES or total_penalty_val > 0.0:
LEDGER_PENALTY.labels('ledger_penalties', 'tenure', val_name).set(tenure_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'dkg', val_name).set(dkg_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'performance', val_name).set(performance_penalty_val)
LEDGER_PENALTY.labels('ledger_penalties', 'total', val_name).set(total_penalty_val)

# In an effort to reduce the number of metrics to track, only gather
# last_heartbear for this miner_name. Will this surprise users?
if miner_name == val_name:
BLOCKAGE.labels('last_heartbeat', val_name).set(last_heartbeat)

elif len(line) == 0:
# empty lines are fine
Expand Down

0 comments on commit 21b8d99

Please sign in to comment.