Skip to content

Commit 4004bcf

Browse files
committed
Add freebsd sysinfo for telemetry
1 parent 25552a0 commit 4004bcf

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

prdoc/pr_7985.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: Collect system infomation on FreeBSD OS
2+
author: firegrass
3+
doc:
4+
- audience: Node Operator
5+
description: |
6+
Adds support for collecting system information on FreeBSD. This allows Decentralized Nodes operators to be compliant with the Telemetry rule without maintaining patches.
7+
crates:
8+
- name: sc-sysinfo
9+
bump: minor

substrate/client/sysinfo/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use futures::prelude::*;
2323
use std::time::Duration;
2424

2525
mod sysinfo;
26+
#[cfg(target_os = "freebsd")]
27+
mod sysinfo_freebsd;
2628
#[cfg(target_os = "linux")]
2729
mod sysinfo_linux;
2830

substrate/client/sysinfo/src/sysinfo.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ pub fn gather_sysinfo() -> SysInfo {
317317
#[cfg(target_os = "linux")]
318318
crate::sysinfo_linux::gather_linux_sysinfo(&mut sysinfo);
319319

320+
#[cfg(target_os = "freebsd")]
321+
crate::sysinfo_freebsd::gather_freebsd_sysinfo(&mut sysinfo);
322+
320323
sysinfo
321324
}
322325

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5+
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
use sc_telemetry::SysInfo;
20+
use std::process::Command;
21+
use std::str;
22+
23+
fn sysctl_output(name: &str) -> Option<String> {
24+
let output = Command::new("sysctl").arg("-n").arg(name).output().ok()?;
25+
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
26+
Some(stdout)
27+
}
28+
29+
pub fn gather_freebsd_sysinfo(sysinfo: &mut SysInfo) {
30+
if let Some(cpu_model) = sysctl_output("hw.model") {
31+
sysinfo.cpu = Some(cpu_model);
32+
}
33+
34+
if let Some(cores) = sysctl_output("kern.smp.cores") {
35+
sysinfo.core_count = cores.parse().ok();
36+
}
37+
38+
if let Some(memory) = sysctl_output("hw.physmem") {
39+
sysinfo.memory = memory.parse().ok();
40+
}
41+
42+
if let Some(virtualization) = sysctl_output("kern.vm_guest") {
43+
sysinfo.is_virtual_machine = Some(virtualization != "none");
44+
}
45+
46+
if let Some(freebsd_version) = sysctl_output("kern.osrelease") {
47+
sysinfo.linux_distro = Some(freebsd_version);
48+
}
49+
}

0 commit comments

Comments
 (0)