-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgaugeBtcUtxos.ts
34 lines (28 loc) · 1.24 KB
/
gaugeBtcUtxos.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import promClient, { Gauge } from 'prom-client';
import { Context } from '../../lib/interfaces';
import { ProtocolData } from '../../utils/utils';
const metricNameUtxosCount: string = 'cf_btc_utxos';
const metricUtxosCount: Gauge = new promClient.Gauge({
name: metricNameUtxosCount,
help: 'The total number of btc utxos we currently have',
registers: [],
});
const metricNameUtxosBalance: string = 'cf_btc_utxo_balance';
const metricUtxosBalance = new promClient.Gauge({
name: metricNameUtxosBalance,
help: 'Aggregated amounts from Bitcoin utxos',
registers: [],
});
export const gaugeBtcUtxos = async (context: Context, data: ProtocolData): Promise<void> => {
if (context.config.skipMetrics.includes('cf_btc_utxos')) {
return;
}
const { logger, registry } = context;
logger.debug(`Scraping ${metricNameUtxosCount}, ${metricNameUtxosBalance}`);
if (registry.getSingleMetric(metricNameUtxosCount) === undefined)
registry.registerMetric(metricUtxosCount);
if (registry.getSingleMetric(metricNameUtxosBalance) === undefined)
registry.registerMetric(metricUtxosBalance);
metricUtxosCount.set(data.data.btc_utxos.count);
metricUtxosBalance.set(Number(data.data.btc_utxos.total_balance));
};