Skip to content

Commit

Permalink
Add feature: export last & avg number of batched messages
Browse files Browse the repository at this point in the history
  • Loading branch information
clemensgg committed Jan 28, 2024
1 parent a4a92a5 commit 4dd0e3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions metrics-exporter/metrics-relayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ export default {
help: 'Counts of top 3 message types for each grantee in the last 24 hours',
labelNames: ['grantee_address', 'msg_type', 'memo']
}),
granteeLastNumMsgsGauge: new prometheus.Gauge({
name: 'grantee_last_num_msgs',
help: 'Last number of messages used (batched) for each grantee',
labelNames: ['grantee_address', 'memo']
}),
granteeAvgNumMsgs24hGauge: new prometheus.Gauge({
name: 'grantee_avg_num_msgs_24h',
help: 'Average number of messages used (batched) for each grantee in the last 24 hours',
labelNames: ['grantee_address', 'memo']
}),
avgGasWantedGauge: new prometheus.Gauge({
name: 'avg_gas_wanted',
help: 'Average gas wanted across all transactions',
Expand Down
53 changes: 53 additions & 0 deletions metrics-exporter/relayer-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,59 @@ export async function updateAllMetrics() {
});
});

// Update granteeLastNumMsgsGauge
db.each(`
SELECT t.relayer_address, t.memo, t.msg_array
FROM relayer_transactions t
INNER JOIN (
SELECT relayer_address, memo, MAX(block_time) as latest_time
FROM relayer_transactions
GROUP BY relayer_address, memo
) latest ON t.relayer_address = latest.relayer_address AND t.memo = latest.memo AND t.block_time = latest.latest_time
`, [], (err, row) => {
if (err) {
console.error('[ERR] Error running query for last number of messages', err.message);
return;
}
try {
const msgCount = JSON.parse(row.msg_array).length;
metrics.granteeLastNumMsgsGauge.labels(row.relayer_address, row.memo).set(msgCount);
} catch (parseError) {
console.error('[ERR] Error parsing msg_array:', parseError);
}
});

// Update granteeAvgNumMsgs24hGauge
db.all(`
SELECT relayer_address, memo, msg_array
FROM relayer_transactions
WHERE block_time > ?
`, [yesterday], (err, rows) => {
if (err) {
console.error('[ERR] Error running query for average number of messages in 24h', err.message);
return;
}

const granteeMsgCounts = {};
rows.forEach(row => {
try {
const msgCount = JSON.parse(row.msg_array).length;
if (!granteeMsgCounts[row.relayer_address]) {
granteeMsgCounts[row.relayer_address] = { totalMsgs: 0, txCount: 0, memo: row.memo };
}
granteeMsgCounts[row.relayer_address].totalMsgs += msgCount;
granteeMsgCounts[row.relayer_address].txCount += 1;
} catch (parseError) {
console.error('[ERR] Error parsing msg_array:', parseError);
}
});

for (const [relayer_address, data] of Object.entries(granteeMsgCounts)) {
const avgMsgs = data.totalMsgs / data.txCount;
metrics.granteeAvgNumMsgs24hGauge.labels(relayer_address, data.memo).set(avgMsgs);
}
});

// Update total top3 message types for each grantee
processMessageTypesForGauge(metrics.granteeTopMsgTypesTotalGauge);

Expand Down

0 comments on commit 4dd0e3c

Please sign in to comment.