|
| 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