Merge pull request #111 from ArtemKolodko/add_total_fee_metrics

Add total fee metrics
pull/112/head
Diego Nava 1 year ago committed by GitHub
commit d72816143d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      doc/ManualMigrations.md
  2. 17
      src/indexer/indexer/metrics/stats.ts
  3. 23
      src/store/postgres/Metrics.ts
  4. 3
      src/store/postgres/sql/scheme.sql
  5. 1
      src/types/api.ts

@ -5,9 +5,21 @@
### Manual migrations list
### Date: 25.07.23
#### Description
New `metrics_type` enum value: 'total_fee'
```sql
ALTER TYPE metrics_type ADD VALUE 'total_fee';
```
#### Date: 21.03.23
#### Description: add `block_number` column to tables `erc721_asset` and `erc1155_assets`
#### Description
Add `block_number` column to tables `erc721_asset` and `erc1155_assets`
```sql
ALTER TABLE erc721_asset

@ -11,16 +11,19 @@ export const statsIndexer = () => {
}
const runLoop = async () => {
l.info('Daily metrics update started...')
try {
const dateStart = Date.now()
const limit = 14
await Promise.all([
stores[0].metrics.updateWalletsCount(limit),
stores[0].metrics.updateTransactionsCount(limit),
stores[0].metrics.updateAverageFee(limit),
stores[0].metrics.updateBlockSize(limit),
])
const daysCount = 14
const metricsStore = stores[0].metrics
await metricsStore.updateWalletsCount(daysCount)
await metricsStore.updateTransactionsCount(daysCount)
await metricsStore.updateAverageFee(daysCount)
await metricsStore.updateBlockSize(daysCount)
await metricsStore.updateTotalFee(daysCount)
await updateTopDailyMetrics()
l.info(`Daily metrics updated in ${Math.round((Date.now() - dateStart) / 1000)}s`)
} catch (e) {
l.error('Error on metrics update:', e.message)

@ -135,6 +135,29 @@ export class PostgresStorageMetrics implements IStorageMetrics {
return rows
}
updateTotalFee = async (offsetFrom = 14, offsetTo = 0) => {
const rows = await this.query(
`select to_date("timestamp"::varchar, 'YYYY-MM-DD')::varchar as date,
round(sum(gas * gas_price / power(10, 18))::numeric, 0) as value
from (
select timestamp, gas, gas_price from "transactions"
union all
select timestamp, gas, gas_price from "staking_transactions"
) t1
where "timestamp" >= date_trunc('day', now() - interval '${offsetFrom} day')
and "timestamp" < date_trunc('day', now() - interval '${offsetTo} day')
group by 1
order by 1 desc
limit 1000`,
[]
)
if (rows.length > 0) {
await this.insertStats(MetricsDailyType.totalFee, rows)
}
return rows
}
updateBlockSize = async (offsetFrom = 14, offsetTo = 0) => {
const rows = await this.query(
`select to_date("timestamp"::varchar, 'YYYY-MM-DD')::varchar as date,

@ -464,7 +464,8 @@ $$
'wallets_count',
'transactions_count',
'average_fee',
'block_size'
'block_size',
'total_fee'
);
exception
when duplicate_object then null;

@ -73,6 +73,7 @@ export enum MetricsDailyType {
transactionsCount = 'transactions_count',
averageFee = 'average_fee',
blockSize = 'block_size',
totalFee = 'total_fee',
}
export enum MetricsTopType {

Loading…
Cancel
Save