|
|
@ -19,24 +19,8 @@ defmodule Explorer.Chain.Statistics do |
|
|
|
) t |
|
|
|
) t |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
@lag_query """ |
|
|
|
|
|
|
|
SELECT coalesce(avg(lag), interval '0 seconds') |
|
|
|
|
|
|
|
FROM ( |
|
|
|
|
|
|
|
SELECT inserted_at - timestamp AS lag |
|
|
|
|
|
|
|
FROM blocks |
|
|
|
|
|
|
|
WHERE blocks.inserted_at > NOW() - interval '1 hour' |
|
|
|
|
|
|
|
AND blocks.timestamp > NOW() - interval '1 hour' |
|
|
|
|
|
|
|
) t |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@block_velocity_query """ |
|
|
|
|
|
|
|
SELECT count(blocks.hash) |
|
|
|
|
|
|
|
FROM blocks |
|
|
|
|
|
|
|
WHERE blocks.inserted_at > NOW() - interval '1 minute' |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@transaction_velocity_query """ |
|
|
|
@transaction_velocity_query """ |
|
|
|
SELECT count(transactions.hash) |
|
|
|
SELECT count(transactions.inserted_at) |
|
|
|
FROM transactions |
|
|
|
FROM transactions |
|
|
|
WHERE transactions.inserted_at > NOW() - interval '1 minute' |
|
|
|
WHERE transactions.inserted_at > NOW() - interval '1 minute' |
|
|
|
""" |
|
|
|
""" |
|
|
@ -53,9 +37,7 @@ defmodule Explorer.Chain.Statistics do |
|
|
|
|
|
|
|
|
|
|
|
@typedoc """ |
|
|
|
@typedoc """ |
|
|
|
* `average_time` - the average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` |
|
|
|
* `average_time` - the average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` |
|
|
|
* `block_velocity` - the number of `t:Explorer.Chain.Block.t/0` mined/validated in the last minute |
|
|
|
|
|
|
|
* `blocks` - the last <= 5 `t:Explorer.Chain.Block.t/0` |
|
|
|
* `blocks` - the last <= 5 `t:Explorer.Chain.Block.t/0` |
|
|
|
* `lag` - the average time over the last hour between when the block was mined/validated |
|
|
|
|
|
|
|
(`t:Explorer.Chain.Block.t/0` `timestamp`) and when it was inserted into the databasse |
|
|
|
(`t:Explorer.Chain.Block.t/0` `timestamp`) and when it was inserted into the databasse |
|
|
|
(`t:Explorer.Chain.Block.t/0` `inserted_at`) |
|
|
|
(`t:Explorer.Chain.Block.t/0` `inserted_at`) |
|
|
|
* `number` - the latest `t:Explorer.Chain.Block.t/0` `number` |
|
|
|
* `number` - the latest `t:Explorer.Chain.Block.t/0` `number` |
|
|
@ -66,9 +48,7 @@ defmodule Explorer.Chain.Statistics do |
|
|
|
""" |
|
|
|
""" |
|
|
|
@type t :: %__MODULE__{ |
|
|
|
@type t :: %__MODULE__{ |
|
|
|
average_time: Duration.t(), |
|
|
|
average_time: Duration.t(), |
|
|
|
block_velocity: blocks_per_minute(), |
|
|
|
|
|
|
|
blocks: [Block.t()], |
|
|
|
blocks: [Block.t()], |
|
|
|
lag: Duration.t(), |
|
|
|
|
|
|
|
number: Block.block_number(), |
|
|
|
number: Block.block_number(), |
|
|
|
timestamp: :calendar.datetime(), |
|
|
|
timestamp: :calendar.datetime(), |
|
|
|
transaction_velocity: transactions_per_minute(), |
|
|
|
transaction_velocity: transactions_per_minute(), |
|
|
@ -76,9 +56,7 @@ defmodule Explorer.Chain.Statistics do |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
defstruct average_time: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, |
|
|
|
defstruct average_time: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, |
|
|
|
block_velocity: 0, |
|
|
|
|
|
|
|
blocks: [], |
|
|
|
blocks: [], |
|
|
|
lag: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, |
|
|
|
|
|
|
|
number: -1, |
|
|
|
number: -1, |
|
|
|
timestamp: nil, |
|
|
|
timestamp: nil, |
|
|
|
transaction_velocity: 0, |
|
|
|
transaction_velocity: 0, |
|
|
@ -105,9 +83,7 @@ defmodule Explorer.Chain.Statistics do |
|
|
|
|
|
|
|
|
|
|
|
%__MODULE__{ |
|
|
|
%__MODULE__{ |
|
|
|
average_time: query_duration(@average_time_query), |
|
|
|
average_time: query_duration(@average_time_query), |
|
|
|
block_velocity: query_value(@block_velocity_query), |
|
|
|
|
|
|
|
blocks: Repo.all(blocks), |
|
|
|
blocks: Repo.all(blocks), |
|
|
|
lag: query_duration(@lag_query), |
|
|
|
|
|
|
|
transaction_velocity: query_value(@transaction_velocity_query), |
|
|
|
transaction_velocity: query_value(@transaction_velocity_query), |
|
|
|
transactions: transactions |
|
|
|
transactions: transactions |
|
|
|
} |
|
|
|
} |
|
|
|