Created
May 21, 2021 11:11
-
-
Save stuartbain/2529b504981a20a214d1ec694278b91f to your computer and use it in GitHub Desktop.
Radix Metrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
from flatten_json import flatten | |
content = [] | |
# System Info | |
system_info = requests.get('http://localhost:3333/system/info') | |
flat_system_info = flatten(system_info.json()) | |
system_info_keys_to_remove =["info_system_version_system_version_agent_version", "info_system_version_system_version_protocol_version", "agent_protocol", "agent_version", "info_configuration_pacemakerRate", "info_configuration_pacemakerTimeout", "info_configuration_pacemakerMaxExponent"] | |
for key in system_info_keys_to_remove: | |
flat_system_info.pop(key) | |
for item in flat_system_info.items(): | |
if type(item[1]) is int: | |
content.append("radix_" + str(item[0]).lower() + ' ' + str(item[1])) | |
# Node Staking | |
node_validator = requests.post('http://localhost:3333/node/validator').json() | |
validator_stake_total = node_validator['validator']['totalStake'] | |
content.append("radix_validator_stake_total" + ' ' + str(validator_stake_total)) | |
validator_delegators_count = len(node_validator['validator']['stakes']) | |
content.append("radix_validator_delegators_count" + ' ' + str(validator_delegators_count)) | |
# Peers | |
node_peers = requests.get('http://localhost:3333/system/peers').json() | |
content.append("radix_validator_peers_count" + ' ' + str(len(node_peers))) | |
# Next Validators | |
epoch_proof = requests.get('http://localhost:3333/system/epochproof').json() | |
if 'header' in epoch_proof: | |
next_validators = epoch_proof['header']['nextValidators'] | |
next_validators_count = len(next_validators) | |
min_staked_validator = min(next_validators, key=lambda x:int(x['stake']))['stake'] | |
max_staked_validator = max(next_validators, key=lambda x:int(x['stake']))['stake'] | |
content.append("radix_validator_next_validators_count" + ' ' + str(next_validators_count)) | |
content.append("radix_validator_next_validators_stake_min" + ' ' + str(int(min_staked_validator)/1000000000000000000)) | |
content.append("radix_validator_next_validators_stake_max" + ' ' + str(int(max_staked_validator)/1000000000000000000)) | |
# Add line breaks | |
content=map(lambda x:x+'\n', content) | |
sys.stdout.writelines(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment