-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add metrics * chore: move metrics from the wrong folder * chore: disable powered by express header * chore: add custom metrics
- Loading branch information
Showing
5 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import init, { client } from '@snapshot-labs/snapshot-metrics'; | ||
import { Express } from 'express'; | ||
import db from './mysql'; | ||
|
||
export default function initMetrics(app: Express) { | ||
init(app, { | ||
normalizedPath: [['^/api/messages/.+', '/api/messages/#hash']], | ||
whitelistedPath: [/^\/$/, /^\/api$/, /^\/api\/msg$/, /^\/api\/messages\/.+$/] | ||
}); | ||
} | ||
|
||
new client.Gauge({ | ||
name: 'messages_per_network_count', | ||
help: 'Total number of messages per network', | ||
labelNames: ['network'], | ||
async collect() { | ||
const results = await db.queryAsync( | ||
'SELECT COUNT(*) as count, network FROM messages GROUP BY network' | ||
); | ||
|
||
results.forEach(result => { | ||
this.set({ network: result.network }, result.count); | ||
}); | ||
} | ||
}); | ||
|
||
export const timeMessageProcess = new client.Histogram({ | ||
name: 'message_process_duration_seconds', | ||
help: 'Duration in seconds of each batch messages process', | ||
labelNames: ['network'] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters