-
Notifications
You must be signed in to change notification settings - Fork 14
Add Telemetry #63
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
base: main
Are you sure you want to change the base?
Add Telemetry #63
Changes from 4 commits
ba5576e
9a2ac57
a00715a
ecb3dea
e2352a6
0acc529
c780bd6
5b2380c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::api::error::LdkServerError; | ||
use crate::service::Context; | ||
use ldk_server_protos::api::{GetMetricsRequest, GetMetricsResponse}; | ||
|
||
pub(crate) const GET_METRICS: &str = "metrics"; | ||
|
||
pub(crate) fn handle_metrics_request( | ||
context: Context, _request: GetMetricsRequest, | ||
) -> Result<GetMetricsResponse, LdkServerError> { | ||
let metrics = context.prometheus_handle.render(); | ||
Ok(GetMetricsResponse { metrics }) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use std::io; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::time::sleep; | ||
|
||
use ldk_node::{BalanceDetails, Node}; | ||
use metrics::{describe_counter, describe_gauge, gauge}; | ||
|
||
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle}; | ||
|
||
pub fn setup_prometheus() -> PrometheusHandle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove all the metric publishing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean all their descriptions, right? Just leaving the returning |
||
let prometheus_builder = PrometheusBuilder::new(); | ||
let handler = | ||
prometheus_builder.install_recorder().expect("failed to install Prometheus recorder"); | ||
|
||
describe_counter!( | ||
"channel_pending", | ||
"A channel has been created and is pending confirmation on-chain." | ||
); | ||
describe_counter!("channel_ready", "A channel is ready to be used."); | ||
describe_counter!("payment_received", "A payment has been received."); | ||
describe_counter!("payment_successful", "A sent payment was successful."); | ||
describe_counter!("payment_failed", "A sent payment has failed."); | ||
describe_counter!( | ||
"payment_claimable", | ||
"A payment for a previously-registered payment hash has been received." | ||
); | ||
describe_counter!("payment_forwarded", "A sent payment has failed."); | ||
|
||
describe_gauge!("node_total_onchain_balance_sats", "The total balance of our on-chain wallet."); | ||
describe_gauge!( | ||
"node_spendable_onchain_balance_sats", | ||
"The currently spendable balance of our on-chain wallet." | ||
); | ||
describe_gauge!( | ||
"node_total_anchor_channels_reserve_sats", | ||
"The total anchor channel reserve balance." | ||
); | ||
describe_gauge!( | ||
"node_total_lightning_balance_sats", | ||
"The total balance that we would be able to claim across all our Lightning channels." | ||
); | ||
describe_gauge!( | ||
"node_lightning_balances", | ||
"A detailed list of all known Lightning balances that would be claimable on channel closure." | ||
); | ||
describe_gauge!( | ||
"node_pending_balances_from_channel_closures", | ||
"A detailed list of balances currently being swept from the Lightning to the on-chain wallet." | ||
); | ||
|
||
// TODO (arturgontijo): Add all labels here. Fix descriptions. | ||
|
||
handler | ||
} | ||
|
||
pub async fn collect_node_metrics(node: Arc<Node>) -> io::Result<()> { | ||
println!("[DEBUG] Collecting Node Metrics..."); | ||
let BalanceDetails { | ||
total_onchain_balance_sats, | ||
spendable_onchain_balance_sats, | ||
total_anchor_channels_reserve_sats, | ||
total_lightning_balance_sats, | ||
// TODO (arturgontijo): | ||
// lightning_balances, | ||
// pending_balances_from_channel_closures, | ||
.. | ||
} = node.list_balances(); | ||
set_gauge("node_total_onchain_balance_sats".to_string(), total_onchain_balance_sats as f64); | ||
set_gauge( | ||
"node_spendable_onchain_balance_sats".to_string(), | ||
spendable_onchain_balance_sats as f64, | ||
); | ||
set_gauge( | ||
"node_total_anchor_channels_reserve_sats".to_string(), | ||
total_anchor_channels_reserve_sats as f64, | ||
); | ||
set_gauge("node_total_lightning_balance_sats".to_string(), total_lightning_balance_sats as f64); | ||
// TODO (arturgontijo): | ||
// set_gauge("node_lightning_balances".to_string(), lightning_balances as f64); | ||
// set_gauge("node_pending_balances_from_channel_closures".to_string(), pending_balances_from_channel_closures as f64); | ||
|
||
// TODO (arturgontijo): Get sleep delay from config file. | ||
sleep(Duration::from_millis(10_000)).await; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn set_gauge(label: String, value: f64) { | ||
let gauge = gauge!(label); | ||
gauge.set(value); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.