Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ijonas committed Feb 3, 2024
1 parent b81f117 commit b83142c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ promdata
grafdata
feedsmon.yml
.vscode
feedsmon-config.yaml
15 changes: 10 additions & 5 deletions contract_metrics.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from web3 import Web3
from cfg import network, flux_monitor_abi

import logging
from metrics import metrics

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')


def analyse_fluxmon_contracts(cfg, contracts):
print(f"Analysing {len(contracts)} contracts...")
logging.info(f"Analysing {len(contracts)} contracts...")
for contract in contracts:
print(
logging.info(
f"Analysing contract {contract['code']} on {contract['network']}")
chain = network(cfg['general']['networks'], contract['network'])
if network is not None:
logging.info(f"Connecting to {contract['rpc']}...")
w3 = Web3(Web3.HTTPProvider(chain["rpc"]))

if w3.is_connected():
logging.info(f"Connected to {contract['network']}")
contract_instance = w3.eth.contract(
contract["address"], abi=flux_monitor_abi)
decimals = contract_instance.functions.decimals().call()
Expand Down Expand Up @@ -46,6 +51,6 @@ def analyse_fluxmon_contracts(cfg, contracts):
).set(withdrawable_payment)

else:
print(f"Failed to connect to {contract['network']}")
logging.info(f"Failed to connect to {contract['network']}")
else:
print(f"Network {contract['network']} not found in config")
logging.info(f"Network {contract['network']} not found in config")
11 changes: 9 additions & 2 deletions metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from prometheus_client import Counter, Gauge, Info
import logging

metrics = {
"data_feed": Gauge("data_feed", "Numeric data feed", ["project", "code"]),
Expand Down Expand Up @@ -63,11 +64,17 @@ def init_metrics(cfg):
metrics["data_feed_last_error"].labels(
data_feed_source["project"], data_feed_source["code"]
).info({"status": "", "timestamp": "", "error": ""})
logging.info(
f"Initialised metrics for DATAFEED {data_feed_source['project']}" +
f" {data_feed_source['code']}",
)

for fluxmon_contract in cfg["fluxmon_contracts"]:
for metric in ["fluxmon_decimals", "fluxmon_allocated_funds", "fluxmon_available_funds", "fluxmon_latest_answer", "fluxmon_latest_round", "fluxmon_withdrawable_payment"]:
metrics[metric].labels(
fluxmon_contract["project"], fluxmon_contract["code"]
).set(0)
print(
f"Initialised metrics for {data_feed_source['project']}-{data_feed_source['code']}",
logging.info(
f"Initialised metrics for CONTRACT {fluxmon_contract['project']}" +
f" {fluxmon_contract['code']}",
)

0 comments on commit b83142c

Please sign in to comment.