Skip to content

Commit

Permalink
emit metric on number of active vaults (dydxprotocol#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Apr 23, 2024
1 parent fb2e7f9 commit 30b926d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions protocol/lib/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const (
TreasuryBalanceAfterDistribution = "treasury_balance_after_distribution"

// Vault.
NumActiveVaults = "num_active_vaults"
VaultCancelOrder = "vault_cancel_order"
VaultPlaceOrder = "vault_place_order"
VaultType = "vault_type"
Expand Down
10 changes: 10 additions & 0 deletions protocol/x/vault/keeper/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) {
// Iterate through all vaults.
params := k.GetParams(ctx)
numActiveVaults := 0
totalSharesIterator := k.getTotalSharesIterator(ctx)
defer totalSharesIterator.Close()
for ; totalSharesIterator.Valid(); totalSharesIterator.Next() {
Expand All @@ -43,6 +44,9 @@ func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) {
}
}

// Count current vault as active.
numActiveVaults++

// Refresh orders depending on vault type.
// Currently only supported vault type is CLOB.
switch vaultId.Type {
Expand All @@ -55,6 +59,12 @@ func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) {
log.ErrorLog(ctx, "Failed to refresh vault orders: unknown vault type", "vaultId", *vaultId)
}
}

// Emit metric on number of active vaults.
metrics.SetGauge(
metrics.NumActiveVaults,
float32(numActiveVaults),
)
}

// RefreshVaultClobOrders refreshes orders of a CLOB vault.
Expand Down

0 comments on commit 30b926d

Please sign in to comment.