This repository was archived by the owner on Jun 29, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
100 lines (82 loc) · 3.04 KB
/
Copy pathmain.rs
File metadata and controls
100 lines (82 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
mod error;
mod system_information;
use clap::Parser;
use stackable_telemetry::{Tracing, tracing::TelemetryOptions};
use std::path::PathBuf;
use crate::system_information::SystemInformation;
use std::time::Instant;
const APP_NAME: &str = "containerdebug";
/// Collects and prints helpful debugging information about the environment that it is running in.
#[derive(clap::Parser)]
struct Opts {
/// Loop every DURATION, instead of shutting down once completed (default DURATION: 30m)
#[clap(
long = "loop",
value_name = "INTERVAL",
default_missing_value = "30m",
num_args = 0..=1,
require_equals = true,
)]
loop_interval: Option<stackable_shared::time::Duration>,
/// Write collected information to OUTPUT as JSON
#[clap(long, short = 'o')]
output: Option<PathBuf>,
#[clap(flatten)]
pub telemetry_arguments: TelemetryOptions,
}
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
#[tokio::main]
async fn main() {
let opts = Opts::parse();
let _trace_guard = Tracing::pre_configured(APP_NAME, opts.telemetry_arguments)
.init()
.unwrap();
let init_span = tracing::error_span!("containerdebug init").entered();
tracing::info!(
built_info.pkg_version = built_info::PKG_VERSION,
built_info.git_version = built_info::GIT_VERSION,
built_info.target = built_info::TARGET,
built_info.built_time_utc = built_info::BUILT_TIME_UTC,
built_info.rustc_version = built_info::RUSTC_VERSION,
"Starting {name}",
name = built_info::PKG_NAME
);
let mut collect_ctx = SystemInformation::init();
let mut next_run = Instant::now();
drop(init_span);
loop {
// Wrap *all* output in a span, to separate it from main app output.
let _span = tracing::error_span!("containerdebug run").entered();
let next_run_sleep = next_run.saturating_duration_since(Instant::now());
if !next_run_sleep.is_zero() {
tracing::info!(?next_run, "scheduling next run...");
}
tokio::time::sleep(next_run_sleep).await;
let system_information = SystemInformation::collect(&mut collect_ctx).await;
match serde_json::to_string_pretty(&system_information) {
Ok(serialized) => {
if let Some(output_path) = &opts.output
&& let Err(err) = std::fs::write(output_path, &serialized)
{
tracing::error!(
path = %output_path.display(),
error = &err as &dyn std::error::Error,
"failed to write JSON output file"
);
}
}
Err(err) => {
tracing::error!(
error = &err as &dyn std::error::Error,
"failed to serialize system information"
);
}
}
match opts.loop_interval {
Some(interval) => next_run += interval,
None => break,
}
}
}