Skip to content

Commit

Permalink
add connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Retropex committed Oct 20, 2024
1 parent 5532f34 commit 1dc5714
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ else
endif
@start-sdk pack

install:
ifeq (,$(wildcard ~/.embassy/config.yaml))
@echo; echo "You must define \"host: http://server-name.local\" in ~/.embassy/config.yaml config file first"; echo
install: $(PKG_ID).s9pk
ifeq (,$(wildcard ./start9/config.yaml))
@echo; echo "You must define \"host: http://server-name.local\" in ./start9/config.yaml config file first"; echo
else
start-cli package install $(PKG_ID).s9pk
endif
Expand Down
32 changes: 32 additions & 0 deletions manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub struct ChainInfo {
softforks: LinearMap<String, SoftFork>,
}

#[derive(Clone, Debug, serde::Deserialize)]
pub struct NetworkInfo {
connections: usize,
connections_in: usize,
connections_out: usize,
}

#[derive(Clone, Debug, serde::Deserialize)]
#[serde(tag = "type")]
pub enum SoftFork {
Expand Down Expand Up @@ -372,6 +379,31 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box<dyn Error>> {
std::str::from_utf8(&info_res.stderr).unwrap_or("UNKNOWN ERROR")
);
}
let info_res = std::process::Command::new("bitcoin-cli")
.arg("-conf=/root/.bitcoin/bitcoin.conf")
.arg("getnetworkinfo")
.output()?;
if info_res.status.success() {
let info: NetworkInfo = serde_json::from_slice(&info_res.stdout)?;
stats.insert(
Cow::from("Connections"),
Stat {
value_type: "string",
value: format!("{} ({} in / {} out)", info.connections, info.connections_in, info.connections_out),
description: Some(Cow::from("The number of peers connected (inbound and outbound)")),
copyable: false,
qr: false,
masked: false,
},
);
} else if info_res.status.code() == Some(28) {
return Ok(());
} else {
eprintln!(
"Error updating network info: {}",
std::str::from_utf8(&info_res.stderr).unwrap_or("UNKNOWN ERROR")
);
}
serde_yaml::to_writer(
std::fs::File::create("/root/.bitcoin/start9/.stats.yaml.tmp")?,
&Stats {
Expand Down

0 comments on commit 1dc5714

Please sign in to comment.