fix: public metrics enabling (#10365)

* fix: Fix public metrics enabling

* Simplified query for active accounts metric
pull/10369/head
Victor Baranov 5 months ago committed by GitHub
parent b74cd94ba7
commit 69a819abba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      apps/explorer/lib/explorer/chain/metrics.ex
  2. 23
      apps/explorer/lib/explorer/chain/metrics/queries.ex
  3. 20
      apps/explorer/lib/explorer/prometheus/instrumenter.ex

@ -18,10 +18,8 @@ defmodule Explorer.Chain.Metrics do
:weekly_verified_smart_contracts_number,
:weekly_new_addresses_number,
:weekly_new_tokens_number,
:weekly_new_token_transfers_number
# todo; this metric causes increasing of AccessShareLocks
# which increases DB loading. Disabling this metric for now.
# :weekly_active_addresses_number
:weekly_new_token_transfers_number,
:weekly_simplified_active_addresses_number
]
@spec start_link(term()) :: GenServer.on_start()
@ -30,7 +28,7 @@ defmodule Explorer.Chain.Metrics do
end
def init(_) do
if Application.get_env(:explorer, __MODULE__, :disabled?) do
if Application.get_env(:explorer, __MODULE__)[:disabled?] do
:ignore
else
send(self(), :set_metrics)

@ -19,6 +19,7 @@ defmodule Explorer.Chain.Metrics.Queries do
alias Explorer.Chain.{
Address,
Block,
DenormalizationHelper,
InternalTransaction,
SmartContract,
@ -135,7 +136,27 @@ defmodule Explorer.Chain.Metrics.Queries do
end
@doc """
Retrieves the query for the number of active EOA and smart-contract addresses in the current week.
Retrieves the query for the number of addresses initiated transactions in the current week.
"""
@spec weekly_simplified_active_addresses_number_query() :: Ecto.Query.t()
def weekly_simplified_active_addresses_number_query do
if DenormalizationHelper.transactions_denormalization_finished?() do
Transaction
|> where([tx], tx.block_timestamp >= ago(7, "day"))
|> where([tx], tx.block_consensus == true)
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash))
else
Transaction
|> join(:inner, [tx], block in assoc(tx, :block))
|> where([tx, block], block.timestamp >= ago(7, "day"))
|> where([tx, block], block.consensus == true)
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash))
end
end
@doc """
Retrieves the query for the number of active EOA and smart-contract addresses (from/to/contract participated in transactions, internal transactions, token transfers) in the current week.
This query is currently unused since the very low performance: it doesn't return results in 1 hour.
"""
@spec weekly_active_addresses_number_query() :: Ecto.Query.t()
def weekly_active_addresses_number_query do

@ -49,13 +49,11 @@ defmodule Explorer.Prometheus.Instrumenter do
registry: :public
]
# todo; this metric causes increasing of AccessShareLocks
# which increases DB loading. Disabling this metric for now.
# @gauge [
# name: :weekly_active_addresses_number,
# help: "Number of active EOA addresses (participated in transactions in to/from) in the last 7 days",
# registry: :public
# ]
@gauge [
name: :weekly_active_addresses_number,
help: "Number of active EOA addresses (participated in transactions in to/from) in the last 7 days",
registry: :public
]
def block_import_stage_runner(function, stage, runner, step) do
{time, result} = :timer.tc(function)
@ -89,9 +87,7 @@ defmodule Explorer.Prometheus.Instrumenter do
Gauge.set([name: :weekly_new_token_transfers_number, registry: :public], number)
end
# todo; this metric causes increasing of AccessShareLocks
# which increases DB loading. Disabling this metric for now.
# def weekly_active_addresses_number(number) do
# Gauge.set([name: :weekly_active_addresses_number, registry: :public], number)
# end
def weekly_simplified_active_addresses_number(number) do
Gauge.set([name: :weekly_active_addresses_number, registry: :public], number)
end
end

Loading…
Cancel
Save