-
Notifications
You must be signed in to change notification settings - Fork 2
P2poolv2 status view #13
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
Open
R27-pixel
wants to merge
10
commits into
p2poolv2:main
Choose a base branch
from
R27-pixel:p2poolv2-status-view
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e367057
p2poolv2_config parser
R27-pixel 866d1cb
added test cases for wrong network address , minimal config , address
R27-pixel 26bee74
add test parsed_to_raw_preserves_all_fields
R27-pixel 369dbf0
chore: trigger CI
R27-pixel 225755a
Tui for p2poolv2 config
R27-pixel 4da5429
added test cases
R27-pixel b7210ac
initial commit of status view
R27-pixel 194765f
changed order of list item
R27-pixel a10628e
add test cases
R27-pixel e573c61
fix linting
R27-pixel 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| // SPDX-FileCopyrightText: 2024 PDM Authors | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| #[derive(Debug, Default, Clone, PartialEq)] | ||
| pub struct P2PoolMetrics { | ||
| pub shares_accepted: u64, | ||
| pub shares_rejected: u64, | ||
| pub pool_difficulty: u64, | ||
| pub start_time: u64, | ||
| pub coinbase_total: u64, | ||
| } | ||
|
|
||
| impl P2PoolMetrics { | ||
| /// Parses a raw Prometheus text response into our P2PoolMetrics struct | ||
| pub fn parse_prometheus(raw_text: &str) -> Self { | ||
| let mut metrics = P2PoolMetrics::default(); | ||
|
|
||
| for line in raw_text.lines() { | ||
| let trimmed = line.trim(); | ||
|
|
||
| // Skip comments and empty lines | ||
| if trimmed.starts_with('#') || trimmed.is_empty() { | ||
| continue; | ||
| } | ||
|
|
||
| // Split by whitespace | ||
| let mut parts = trimmed.split_whitespace(); | ||
| if let (Some(key), Some(value_str)) = (parts.next(), parts.next()) { | ||
| // Try to parse the value as a u64 | ||
| let value = value_str.parse::<u64>().unwrap_or(0); | ||
|
|
||
| // Map the Prometheus keys to our struct fields | ||
| match key { | ||
| "shares_accepted_total" => metrics.shares_accepted = value, | ||
| "shares_rejected_total" => metrics.shares_rejected = value, | ||
| "pool_difficulty" => metrics.pool_difficulty = value, | ||
| "start_time_seconds" => metrics.start_time = value, | ||
| "coinbase_total" => metrics.coinbase_total = value, | ||
| _ => {} // Ignore metrics we don't care about | ||
| } | ||
| } | ||
| } | ||
|
|
||
| metrics | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_parse_prometheus_output() { | ||
| let raw_data = "\ | ||
| # HELP shares_accepted_total Total number of accepted shares | ||
| # TYPE shares_accepted_total counter | ||
| shares_accepted_total 0 | ||
|
|
||
| # HELP start_time_seconds Pool start time in Unix timestamp | ||
| # TYPE start_time_seconds gauge | ||
| start_time_seconds 1771149691 | ||
|
|
||
| coinbase_output{index=\"0\",address=\"tb1qyazxde6558qj6z3d9np5e6msmrspwpf6k0qggk\"} 2500000000 | ||
| coinbase_total 2500000000 | ||
| "; | ||
|
|
||
| let metrics = P2PoolMetrics::parse_prometheus(raw_data); | ||
|
|
||
| assert_eq!(metrics.shares_accepted, 0); | ||
| assert_eq!(metrics.start_time, 1771149691); | ||
| assert_eq!(metrics.coinbase_total, 2500000000); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| pub mod file_explorer; | ||
| pub mod metrics; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ | |
| pub mod app; | ||
| pub mod components; | ||
| pub mod config; | ||
| pub mod p2poolv2_config_parser; | ||
| pub mod ui; | ||
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.
The reqwest dependency is configured with the "blocking" feature, but the code uses the async API (client.get().send().await). The "blocking" feature is for synchronous HTTP requests. For async usage, you should remove "blocking" and keep only the default async features, or use no explicit features at all as the async API is the default.