-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement dump metrics #200
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6b4e57
feat: implement dump metrics
Igorgro 5cf2abd
fixes: fixed per review
Igorgro 44ce082
fix: refactor per review
Igorgro 785a35b
fix: improve block range
Igorgro af892c3
feat: add metrics for rpc requests
Igorgro 65f0caf
fixes per review
Igorgro 74a6bfb
Improvements per review
Igorgro 41fc80f
fix: change kind label
Igorgro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@subsquid/substrate-dump/feat-dump-metrics_2023-09-25-10-56.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@subsquid/substrate-dump", | ||
"comment": "feat: implement prometheus metrics", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@subsquid/substrate-dump" | ||
} |
10 changes: 10 additions & 0 deletions
10
...on/changes/@subsquid/util-internal-archive-layout/feat-dump-metrics_2023-09-25-10-56.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@subsquid/util-internal-archive-layout", | ||
"comment": "feat: implement onSuccessWrite callback", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@subsquid/util-internal-archive-layout" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
import { RpcClient } from '@subsquid/rpc-client'; | ||
import {createPrometheusServer, ListeningServer} from '@subsquid/util-internal-prometheus-server' | ||
import promClient, { collectDefaultMetrics, Gauge, Registry } from 'prom-client'; | ||
|
||
|
||
export class PrometheusServer { | ||
private registry = new Registry() | ||
private port?: number | string | ||
private chainHeightGauge: Gauge; | ||
private lastWrittenBlockGauge: Gauge; | ||
private rpcRequestsGauge: Gauge; | ||
|
||
constructor(port: number, rpc: RpcClient) { | ||
this.port = port; | ||
this.chainHeightGauge = new Gauge({ | ||
name: 'sqd_dump_chain_height', | ||
help: 'Last block available in the chain', | ||
registers: [this.registry] | ||
}); | ||
|
||
this.lastWrittenBlockGauge = new Gauge({ | ||
name: 'sqd_dump_last_written_block', | ||
help: 'Last saved block', | ||
registers: [this.registry] | ||
}); | ||
|
||
this.rpcRequestsGauge = new Gauge({ | ||
name: 'sqd_dump_rpc_requests_count', | ||
help: 'Number of rpc requests of different kinds', | ||
labelNames: ['kind', 'url'], | ||
registers: [this.registry], | ||
collect() { | ||
const metrics = rpc.getMetrics(); | ||
this.set({ | ||
kind: 'successful', | ||
url: rpc.url | ||
}, metrics.requestsServed); | ||
this.set({ | ||
kind: 'failed', | ||
url: rpc.url | ||
}, metrics.connectionErrors); | ||
} | ||
}); | ||
|
||
collectDefaultMetrics({register: this.registry}) | ||
} | ||
|
||
setChainHeight(height: number) { | ||
this.chainHeightGauge.set(height); | ||
} | ||
|
||
setLastWrittenBlock(block: number) { | ||
this.lastWrittenBlockGauge.set(block); | ||
} | ||
|
||
serve(): Promise<ListeningServer> { | ||
return createPrometheusServer(this.registry, this.port) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be
success | failure
instead ofsuccessful | failed
? Sounds better to me.