Log mempool stats on new blocks
This commit is contained in:
parent
d921c3fdc2
commit
2c22200820
@ -6,6 +6,7 @@ import statisticsApi from './statistics-api';
|
|||||||
|
|
||||||
class Statistics {
|
class Statistics {
|
||||||
protected intervalTimer: NodeJS.Timer | undefined;
|
protected intervalTimer: NodeJS.Timer | undefined;
|
||||||
|
protected lastRun: number = 0;
|
||||||
protected newStatisticsEntryCallback: ((stats: OptimizedStatistic) => void) | undefined;
|
protected newStatisticsEntryCallback: ((stats: OptimizedStatistic) => void) | undefined;
|
||||||
|
|
||||||
public setNewStatisticsEntryCallback(fn: (stats: OptimizedStatistic) => void) {
|
public setNewStatisticsEntryCallback(fn: (stats: OptimizedStatistic) => void) {
|
||||||
@ -23,15 +24,21 @@ class Statistics {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.runStatistics();
|
this.runStatistics();
|
||||||
this.intervalTimer = setInterval(() => {
|
this.intervalTimer = setInterval(() => {
|
||||||
this.runStatistics();
|
this.runStatistics(true);
|
||||||
}, 1 * 60 * 1000);
|
}, 1 * 60 * 1000);
|
||||||
}, difference);
|
}, difference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async runStatistics(): Promise<void> {
|
public async runStatistics(skipIfRecent = false): Promise<void> {
|
||||||
if (!memPool.isInSync()) {
|
if (!memPool.isInSync()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skipIfRecent && new Date().getTime() / 1000 - this.lastRun < 30) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastRun = new Date().getTime() / 1000;
|
||||||
const currentMempool = memPool.getMempool();
|
const currentMempool = memPool.getMempool();
|
||||||
const txPerSecond = memPool.getTxPerSecond();
|
const txPerSecond = memPool.getTxPerSecond();
|
||||||
const vBytesPerSecond = memPool.getVBytesPerSecond();
|
const vBytesPerSecond = memPool.getVBytesPerSecond();
|
||||||
|
@ -23,6 +23,7 @@ import priceUpdater from '../tasks/price-updater';
|
|||||||
import { ApiPrice } from '../repositories/PricesRepository';
|
import { ApiPrice } from '../repositories/PricesRepository';
|
||||||
import accelerationApi from './services/acceleration';
|
import accelerationApi from './services/acceleration';
|
||||||
import mempool from './mempool';
|
import mempool from './mempool';
|
||||||
|
import statistics from './statistics/statistics';
|
||||||
|
|
||||||
interface AddressTransactions {
|
interface AddressTransactions {
|
||||||
mempool: MempoolTransactionExtended[],
|
mempool: MempoolTransactionExtended[],
|
||||||
@ -723,6 +724,7 @@ class WebsocketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.printLogs();
|
this.printLogs();
|
||||||
|
await statistics.runStatistics();
|
||||||
|
|
||||||
const _memPool = memPool.getMempool();
|
const _memPool = memPool.getMempool();
|
||||||
|
|
||||||
@ -1014,6 +1016,8 @@ class WebsocketHandler {
|
|||||||
client.send(this.serializeResponse(response));
|
client.send(this.serializeResponse(response));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await statistics.runStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// takes a dictionary of JSON serialized values
|
// takes a dictionary of JSON serialized values
|
||||||
|
Loading…
x
Reference in New Issue
Block a user