metrics fixes
This commit is contained in:
@@ -14,7 +14,7 @@ from dexorder.contract import get_contract_event
|
||||
from dexorder.contract.dexorder import get_dexorder_contract
|
||||
from dexorder.event_handler import (init, dump_log, handle_vault_created, handle_order_placed,
|
||||
handle_transfer, handle_swap_filled, handle_order_canceled, handle_order_cancel_all,
|
||||
handle_uniswap_swaps, handle_vault_impl_changed, initialize_metrics)
|
||||
handle_uniswap_swaps, handle_vault_impl_changed, update_metrics)
|
||||
from dexorder.memcache import memcache
|
||||
from dexorder.memcache.memcache_state import RedisState, publish_all
|
||||
from dexorder.order.executionhandler import handle_dexorderexecutions, execute_tranches
|
||||
@@ -81,6 +81,8 @@ def setup_logevent_triggers(runner):
|
||||
# runner.add_event_trigger(handle_fees_changed, get_contract_event('IFeeManager', 'FeesChanged'))
|
||||
# runner.add_callback(adjust_gas)
|
||||
|
||||
runner.add_callback(update_metrics)
|
||||
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
async def main():
|
||||
@@ -114,7 +116,6 @@ async def main():
|
||||
await redis_state.save(state.root_fork, state.diffs_by_branch[state.root_branch.id])
|
||||
|
||||
await initialize_accounting()
|
||||
initialize_metrics()
|
||||
|
||||
runner = BlockStateRunner(state, publish_all=publish_all if redis_state else None)
|
||||
setup_logevent_triggers(runner)
|
||||
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
|
||||
from web3.types import EventData
|
||||
|
||||
from dexorder import db, metric, current_w3
|
||||
from dexorder import db, metric, current_w3, timestamp
|
||||
from dexorder.accounting import accounting_fill, accounting_placement, accounting_transfer, is_tracked_address, \
|
||||
accounting_lock
|
||||
from dexorder.base.chain import current_chain
|
||||
@@ -214,13 +214,21 @@ async def handle_vault_impl_changed(upgrade: EventData):
|
||||
log.debug(f'Vault {addr} upgraded to impl version {version}')
|
||||
|
||||
|
||||
async def get_gas_price():
|
||||
return await current_w3.get().eth.gas_price
|
||||
slow_metric_update = 0
|
||||
async def update_metrics():
|
||||
|
||||
# called at the end of the runloop in the worker context
|
||||
metric.vaults.set(vault_owners.upper_len())
|
||||
metric.open_orders.set(Order.open_orders.upper_len())
|
||||
metric.triggers_time.set(len(TimeTrigger.all))
|
||||
metric.triggers_line.set(len(PriceLineTrigger.triggers_set))
|
||||
|
||||
def initialize_metrics():
|
||||
metric.vaults.set_function(vault_owners.upper_len)
|
||||
metric.open_orders.set_function(Order.open_orders.upper_len)
|
||||
metric.triggers_time.set_function(lambda: len(TimeTrigger.all))
|
||||
metric.triggers_line.set_function(lambda: len(PriceLineTrigger.triggers_set))
|
||||
metric.gas_price.set_function(get_gas_price)
|
||||
# slow updates
|
||||
global slow_metric_update
|
||||
now = timestamp()
|
||||
if now - slow_metric_update >= 60:
|
||||
slow_metric_update = now
|
||||
|
||||
# put slow updates here
|
||||
price = await current_w3.get().eth.gas_price
|
||||
metric.gas_price.observe(price)
|
||||
|
||||
@@ -22,4 +22,4 @@ volume = Counter("volume", "Total volume of successful executions in USD")
|
||||
account_total = Gauge('account_total', 'Total number of accounts configured')
|
||||
account_available = Gauge('account_available', 'Number of accounts that do not have any pending transactions')
|
||||
|
||||
gas_price = Gauge('gas_price', 'Gas price in wei')
|
||||
gas_price = Summary('gas_price', 'Gas price in wei')
|
||||
|
||||
Reference in New Issue
Block a user