Skip to content

Commit

Permalink
Add a 'Connections' property (#110)
Browse files Browse the repository at this point in the history
* Add 'Connections' property

* Update Makefile

* Update Makefile

---------

Co-authored-by: kn0wmad <[email protected]>
  • Loading branch information
biotic21 and kn0wmad authored Feb 27, 2024
1 parent 95722a3 commit d545f0a
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 d545f0a

Please sign in to comment.