rustfs_obs/system/
mod.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::GlobalError;
16
17pub(crate) mod attributes;
18mod collector;
19pub(crate) mod gpu;
20pub(crate) mod metrics;
21
22pub struct SystemObserver {}
23
24impl SystemObserver {
25    /// Initialize the indicator collector for the current process
26    /// This function will create a new `Collector` instance and start collecting metrics.
27    /// It will run indefinitely until the process is terminated.
28    pub async fn init_process_observer(meter: opentelemetry::metrics::Meter) -> Result<(), GlobalError> {
29        let pid = sysinfo::get_current_pid().map_err(|e| GlobalError::PidError(e.to_string()))?;
30        let mut collector = collector::Collector::new(pid, meter, 30000)?;
31        collector.run().await
32    }
33
34    /// Initialize the metric collector for the specified PID process
35    /// This function will create a new `Collector` instance and start collecting metrics.
36    /// It will run indefinitely until the process is terminated.
37    pub async fn init_process_observer_for_pid(meter: opentelemetry::metrics::Meter, pid: u32) -> Result<(), GlobalError> {
38        let pid = sysinfo::Pid::from_u32(pid);
39        let mut collector = collector::Collector::new(pid, meter, 30000)?;
40        collector.run().await
41    }
42}