Skip to content

Commit 3b07729

Browse files
committed
feat(relay): Add more prometheus metrics
1 parent d5d59a3 commit 3b07729

File tree

5 files changed

+109
-3
lines changed

5 files changed

+109
-3
lines changed

beacon-light-client/solidity/tasks/start-publishing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
isSupportedFollowNetwork,
1212
} from '@dendreth/relay/utils/get_current_network_config';
1313
import { getGenericLogger } from '@dendreth/utils/ts-utils/logger';
14-
import { initPrometheusSetup } from '@dendreth/utils/ts-utils/prometheus-utils';
14+
import {
15+
initPrometheusSetup,
16+
registerGaugesForStartPublishing,
17+
} from '@dendreth/utils/ts-utils/prometheus-utils';
1518

1619
const logger = getGenericLogger();
1720

@@ -73,6 +76,7 @@ task('start-publishing', 'Run relayer')
7376
}
7477

7578
initPrometheusSetup(args.prometheusPort, networkName);
79+
registerGaugesForStartPublishing();
7680
}
7781

7882
const currentConfig = await getNetworkConfig(args.followNetwork);

libs/typescript/ts-utils/prometheus-utils.ts

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let followNetwork: string;
1111

1212
export function initPrometheusSetup(port?: number, curFollowNetwork?: string) {
1313
const app = express();
14-
14+
prometheusInitProving();
1515
if (!port) {
1616
// Only for pollUpdates
1717
port = 2999;
@@ -20,12 +20,14 @@ export function initPrometheusSetup(port?: number, curFollowNetwork?: string) {
2020
followNetwork = curFollowNetwork;
2121
}
2222

23+
// Only expose the metrics endpoint if not already initialized
2324
app.get('/metrics', async (req, res) => {
25+
res.set('Content-Type', register.contentType);
2426
res.end(await register.metrics());
2527
});
2628

2729
app.listen(port, () => {
28-
console.log(`Express listening on port ${port}`);
30+
console.log(`Prometheus metrics exposed on port ${port}`);
2931
});
3032

3133
return client;
@@ -69,3 +71,89 @@ export async function prometheusTiming<T>(func: () => T, funcName: string) {
6971
}
7072
}
7173
}
74+
75+
export function registerGaugesForProver() {
76+
register.registerMetric(timesGettingInputsForProofGeneration);
77+
register.registerMetric(numberOfProofGenerated);
78+
}
79+
80+
export function registerGaugesForStartPublishing() {
81+
register.registerMetric(accountBalanceGauge);
82+
register.registerMetric(previousSlot);
83+
register.registerMetric(transactionForSlot);
84+
register.registerMetric(currentNetworkSlot);
85+
register.registerMetric(minutesDelayPrevSlot);
86+
register.registerMetric(minutesDelayTransaction);
87+
register.registerMetric(numberOfProofPublished);
88+
}
89+
90+
export const accountBalanceGauge = new client.Gauge({
91+
name: 'account_balance',
92+
help: 'Current balance of the account',
93+
labelNames: ['network'],
94+
});
95+
96+
export const previousSlot = new client.Gauge({
97+
name: 'previous_slot',
98+
help: 'Previous slot on the chain',
99+
labelNames: ['network'],
100+
});
101+
102+
export const transactionForSlot = new client.Gauge({
103+
name: 'transaction_slot',
104+
help: 'Transaction publishing for slot',
105+
labelNames: ['network'],
106+
});
107+
108+
export const currentNetworkSlot = new client.Gauge({
109+
name: 'current_network_slot',
110+
help: 'Current slot on chian',
111+
labelNames: ['network'],
112+
});
113+
114+
export const minutesDelayPrevSlot = new client.Gauge({
115+
name: 'minutes_delay_prev_slot',
116+
help: 'How behind is the last slot',
117+
labelNames: ['network'],
118+
});
119+
120+
export const minutesDelayTransaction = new client.Gauge({
121+
name: 'minutes_delay_transaction',
122+
help: 'How behind is the transaction',
123+
labelNames: ['network'],
124+
});
125+
126+
export async function prometheusInitProving() {
127+
timesGettingInputsForProofGeneration.reset();
128+
numberOfProofGenerated.reset();
129+
numberOfProofPublished.reset();
130+
}
131+
132+
export function incrementInputsForProofGeneration() {
133+
timesGettingInputsForProofGeneration.inc();
134+
}
135+
136+
export function incrementProofGenerated() {
137+
numberOfProofGenerated.inc();
138+
}
139+
140+
export function incrementProofPublished(network) {
141+
numberOfProofPublished.labels(network).inc();
142+
}
143+
export const timesGettingInputsForProofGeneration = new client.Counter({
144+
name: 'times_getting_inputs_for_proof_generation',
145+
help: 'The number of times inputs for proof generation were requested(since last restart)',
146+
labelNames: ['network'],
147+
});
148+
149+
export const numberOfProofGenerated = new client.Counter({
150+
name: 'number_of_proof_generated',
151+
help: 'The number of proofs generated(since last restart)',
152+
labelNames: ['network'],
153+
});
154+
155+
export const numberOfProofPublished = new client.Counter({
156+
name: 'number_of_proof_published',
157+
help: 'The number of proofs published(since last restart)',
158+
labelNames: ['network'],
159+
});

relay/implementations/prover.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { IProver } from '@/abstraction/prover-interface';
22
import { ProofInputType, Proof, WitnessGeneratorInput } from '@/types/types';
33
import { getGenericLogger } from '@dendreth/utils/ts-utils/logger';
4+
import {
5+
incrementInputsForProofGeneration,
6+
incrementProofGenerated,
7+
} from '@dendreth/utils/ts-utils/prometheus-utils';
48

59
const logger = getGenericLogger();
610
export class Prover implements IProver {
@@ -24,6 +28,7 @@ export class Prover implements IProver {
2428
await this.callInput(proofInput.proofInput);
2529

2630
logger.info('Input send waiting for proof generation');
31+
incrementInputsForProofGeneration();
2732

2833
st = await this.getStatus();
2934

@@ -35,6 +40,7 @@ export class Prover implements IProver {
3540
}
3641

3742
logger.info('Proof successfully generated');
43+
incrementProofGenerated();
3844

3945
const proof = JSON.parse(st.proof);
4046

relay/implementations/publish_evm_transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Web3 from 'web3';
33
import { FeeHistoryResult } from 'web3-eth';
44
import { groth16 } from 'snarkjs';
55
import { getGenericLogger } from '@dendreth/utils/ts-utils/logger';
6+
import { incrementProofPublished } from '@dendreth/utils/ts-utils/prometheus-utils';
67
import { explorerUrls } from '@dendreth/utils/ts-utils/common-utils';
78

89
const logger = getGenericLogger();
@@ -73,6 +74,7 @@ export async function publishTransaction(
7374
});
7475
}
7576
if (chainName) {
77+
incrementProofPublished(chainName);
7678
logger.info(
7779
'Transaction uploaded at: ',
7880
explorerUrls[chainName].tx(transaction.hash),

relay/workers/prover/prover-worker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import { Prover } from '@/implementations/prover';
77
import { PROOF_GENERATOR_QUEUE } from '@/constants/constants';
88
import { checkConfig } from '@dendreth/utils/ts-utils/common-utils';
99
import yargs from 'yargs';
10+
import {
11+
initPrometheusSetup,
12+
registerGaugesForProver,
13+
} from '@dendreth/utils/ts-utils/prometheus-utils';
1014

1115
(async () => {
1216
const proverConfig = {
1317
REDIS_HOST: process.env.REDIS_HOST || 'localhost',
1418
REDIS_PORT: Number(process.env.REDIS_PORT) || 6379,
1519
};
20+
initPrometheusSetup(3000);
21+
registerGaugesForProver();
1622

1723
checkConfig(proverConfig);
1824

0 commit comments

Comments
 (0)