Skip to content

Commit

Permalink
add account_balance metric
Browse files Browse the repository at this point in the history
  • Loading branch information
pops-one committed Nov 11, 2023
1 parent c52aa9b commit a737928
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ sudo systemctl start wallet-exporter

```
curl -s localhost:9877/metric
account_balance{address="cosmos1gswfh88s88s2evtsutwt8heh59jttjglhdlwtwj",name="validator",network="cosmos"} 54.451031
account_balance{address="cosmos1r59ugu6w72s88s2evtsutwt8heh59jpqp9mm3ew",name="delegator",network="cosmos"} 25600.995009
```
# TODO

Expand Down
30 changes: 1 addition & 29 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,4 @@ networks:
- name: validator
address: cosmos1gswfh88s88s2evtsutwt8heh59jttjglhdlwtwj
- name: delegator
address: cosmos1r59ugu6w72s88s2evtsutwt8heh59jpqp9mm3ew
- name: axelar
rpc: http://127.0.0.1:26657
api: http://127.0.0.1:1317
decimals: 6
denom: uaxl
symbol: AXL
type: cosmos
wallets:
- name: vald-operator
address: axelar1gswfh88s88s2evtsutwt8heh59jttjglhdlwtw3
- name: validator
address: axelar1gswfh88s88s2evtsu34t8heh59jttjglhdlwtwj
- name: delegator
address: axelar1gswfh88s88s2evtsutwt8he4559jttjglhdlwtl
- name: umee
rpc: http://127.0.0.1:26657
api: http://127.0.0.1:1317
decimals: 6
denom: uumee
symbol: UMEE
type: cosmos
wallets:
- name: vald-operator
address: axelar1gswfh88s88s2evtsutwt8heh59jttjglhdlwtwj
- name: validator
address: axelar1gswfh8s823s2evtsutwt8heh59jttjglhdlwtwk
- name: delegator
address: axelar112wfh88s88s2evtsutwt8heh59jttjglhdlwtwl
address: cosmos1r59ugu6w72s88s2evtsutwt8heh59jpqp9mm3ew
17 changes: 6 additions & 11 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ def __init__(self, polling_interval_seconds=15, walletconfig=False, logging=Fals

self.logging = logging
self.logging.info("Init the Appmetrics class")
# all metrics are defined below
self.metrics = {}
self.walletconfig=walletconfig

# all metrics are defined below
self.account_balance = Gauge("account_balance", "account balance", ["address", "name", "network"])

logging.debug(walletconfig)
for network in walletconfig["networks"]:
logging.debug(network)
networkname=network["name"]
self.metrics[networkname]={}
for wallet in network["wallets"]:
metric = Gauge(f"{wallet['address']}",
f"{wallet['name']}")
self.metrics[networkname][wallet['address']]=metric

def run_metrics_loop(self):
"""Metrics fetching loop"""
Expand All @@ -59,7 +53,8 @@ def fetch(self):
wallet['address'],
network['denom'])) / (10 ** network['decimals'])
self.logging.info(f"{wallet['address']} has {balance} {network['symbol']}")
self.metrics[networkname][wallet['address']].set(balance)

self.account_balance.labels(network=networkname, address=wallet['address'],name=wallet['name']).set(balance)
except Exception as e:
self.logging.error(str(e))

Expand Down

0 comments on commit a737928

Please sign in to comment.