diff --git a/.docker/openobserve-otel/docker-compose.yml b/.docker/openobserve-otel/docker-compose.yml index 68788aba..a4083bca 100644 --- a/.docker/openobserve-otel/docker-compose.yml +++ b/.docker/openobserve-otel/docker-compose.yml @@ -6,11 +6,12 @@ services: ZO_ROOT_USER_EMAIL: "root@rustfs.com" ZO_ROOT_USER_PASSWORD: "rustfs123" ZO_TRACING_HEADER_KEY: "Authorization" - ZO_TRACING_HEADER_VALUE: "Bearer cm9vdEBydXN0ZnMuY29tOmxIV0RqQmZMWXJ6MnZOajU=" + ZO_TRACING_HEADER_VALUE: "Basic cm9vdEBydXN0ZnMuY29tOmQ4SXlCSEJTUkk3RGVlcEQ=" ZO_DATA_DIR: "/data" ZO_MEMORY_CACHE_ENABLED: "true" ZO_MEMORY_CACHE_MAX_SIZE: "256" RUST_LOG: "info" + TZ: Asia/Shanghai ports: - "5080:5080" - "5081:5081" @@ -44,9 +45,11 @@ services: - "13133:13133" # Health check - "1777:1777" # pprof - "55679:55679" # zpages + - "1888:1888" # Metrics + - "8888:8888" # Prometheus metrics + - "8889:8889" # Additional metrics endpoint depends_on: - openobserve: - condition: service_healthy + - openobserve networks: - otel-network deploy: diff --git a/.docker/openobserve-otel/otel-collector-config.yaml b/.docker/openobserve-otel/otel-collector-config.yaml index 288ac9a2..561692ad 100644 --- a/.docker/openobserve-otel/otel-collector-config.yaml +++ b/.docker/openobserve-otel/otel-collector-config.yaml @@ -20,9 +20,9 @@ processors: exporters: otlphttp/openobserve: - endpoint: http://openobserve:5080/api/default + endpoint: http://openobserve:5080/api/default # http://127.0.0.1:5080/api/default headers: - Authorization: "Bearer cm9vdEBydXN0ZnMuY29tOmxIV0RqQmZMWXJ6MnZOajU=" + Authorization: "Basic cm9vdEBydXN0ZnMuY29tOmQ4SXlCSEJTUkk3RGVlcEQ=" stream-name: default organization: default compression: gzip @@ -32,6 +32,21 @@ exporters: max_interval: 30s max_elapsed_time: 300s timeout: 10s + otlp/openobserve: + endpoint: openobserve:5081 # http://127.0.0.1:5080/api/default + headers: + Authorization: "Basic cm9vdEBydXN0ZnMuY29tOmQ4SXlCSEJTUkk3RGVlcEQ=" + stream-name: default + organization: default + compression: gzip + retry_on_failure: + enabled: true + initial_interval: 5s + max_interval: 30s + max_elapsed_time: 300s + timeout: 10s + tls: + insecure: true extensions: health_check: @@ -47,15 +62,15 @@ service: traces: receivers: [ otlp ] processors: [ memory_limiter, batch ] - exporters: [ otlphttp/openobserve ] + exporters: [ otlp/openobserve ] metrics: receivers: [ otlp ] processors: [ memory_limiter, batch ] - exporters: [ otlphttp/openobserve ] + exporters: [ otlp/openobserve ] logs: receivers: [ otlp, filelog ] processors: [ memory_limiter, batch ] - exporters: [ otlphttp/openobserve ] + exporters: [ otlp/openobserve ] telemetry: logs: level: "info" # Collector 日志级别 diff --git a/crates/obs/src/config.rs b/crates/obs/src/config.rs index 770203de..9d6b0617 100644 --- a/crates/obs/src/config.rs +++ b/crates/obs/src/config.rs @@ -26,12 +26,18 @@ pub struct OtelConfig { /// Helper function: Extract observable configuration from environment variables fn extract_otel_config_from_env() -> OtelConfig { + let endpoint = env::var("RUSTFS_OBSERVABILITY_ENDPOINT").unwrap_or_else(|_| "".to_string()); + let mut use_stdout = env::var("RUSTFS_OBSERVABILITY_USE_STDOUT") + .ok() + .and_then(|v| v.parse().ok()) + .or(Some(USE_STDOUT)); + if endpoint.is_empty() { + use_stdout = Some(true); + } + OtelConfig { - endpoint: env::var("RUSTFS_OBSERVABILITY_ENDPOINT").unwrap_or_else(|_| "".to_string()), - use_stdout: env::var("RUSTFS_OBSERVABILITY_USE_STDOUT") - .ok() - .and_then(|v| v.parse().ok()) - .or(Some(USE_STDOUT)), + endpoint, + use_stdout, sample_ratio: env::var("RUSTFS_OBSERVABILITY_SAMPLE_RATIO") .ok() .and_then(|v| v.parse().ok()) @@ -308,7 +314,10 @@ pub fn load_config(config_dir: Option) -> AppConfig { } else { // If no path provided, use current directory + default config file match env::current_dir() { - Ok(dir) => dir.join(DEFAULT_CONFIG_FILE).to_string_lossy().into_owned(), + Ok(dir) => { + println!("Current directory: {:?}", dir); + dir.join(DEFAULT_CONFIG_FILE).to_string_lossy().into_owned() + } Err(_) => { eprintln!("Warning: Failed to get current directory, using default config file"); DEFAULT_CONFIG_FILE.to_string() diff --git a/crates/obs/src/system/collector.rs b/crates/obs/src/system/collector.rs index c4184051..ea9bae3b 100644 --- a/crates/obs/src/system/collector.rs +++ b/crates/obs/src/system/collector.rs @@ -23,7 +23,7 @@ pub struct Collector { impl Collector { pub fn new(pid: Pid, meter: opentelemetry::metrics::Meter, interval_ms: u64) -> Result { - let mut system = System::new_all(); + let mut system = System::new(); let attributes = ProcessAttributes::new(pid, &mut system)?; let core_count = System::physical_core_count().ok_or(GlobalError::CoreCountError)?; let metrics = Metrics::new(&meter); @@ -52,7 +52,7 @@ impl Collector { fn collect(&mut self) -> Result<(), GlobalError> { self.system - .refresh_processes(sysinfo::ProcessesToUpdate::Some(&[self.pid]), true); + .refresh_processes(sysinfo::ProcessesToUpdate::Some(&[self.pid]), false); // refresh the network interface list and statistics self.networks.refresh(false); diff --git a/scripts/run.sh b/scripts/run.sh index 29605648..6d528ca2 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -37,18 +37,19 @@ export RUSTFS_CONSOLE_ADDRESS=":9002" # export RUSTFS_TLS_PATH="./deploy/certs" # 具体路径修改为配置文件真实路径,obs.example.toml 仅供参考 其中 `RUSTFS_OBS_CONFIG` 和下面变量二选一 -# export RUSTFS_OBS_CONFIG="./deploy/config/obs.example.toml" +# export RUSTFS_OBS_CONFIG="./deploy/config/obs.toml" # 如下变量需要必须参数都有值才可以,以及会覆盖配置文件中的值 -#export RUSTFS__OBSERVABILITY__ENDPOINT=http://localhost:4317 -#export RUSTFS__OBSERVABILITY__USE_STDOUT=false -#export RUSTFS__OBSERVABILITY__SAMPLE_RATIO=2.0 -#export RUSTFS__OBSERVABILITY__METER_INTERVAL=31 -#export RUSTFS__OBSERVABILITY__SERVICE_NAME=rustfs -#export RUSTFS__OBSERVABILITY__SERVICE_VERSION=0.1.0 -#export RUSTFS__OBSERVABILITY__ENVIRONMENT=develop -#export RUSTFS__OBSERVABILITY__LOGGER_LEVEL=debug -#export RUSTFS__OBSERVABILITY__LOCAL_LOGGING_ENABLED=true +export RUSTFS_OBSERVABILITY_ENDPOINT=http://localhost:4317 +#export RUSTFS_OBSERVABILITY_ENDPOINT=http://localhost:4317 +#export RUSTFS_OBSERVABILITY_USE_STDOUT=false +#export RUSTFS_OBSERVABILITY_SAMPLE_RATIO=2.0 +#export RUSTFS_OBSERVABILITY_METER_INTERVAL=31 +#export RUSTFS_OBSERVABILITY_SERVICE_NAME=rustfs +#export RUSTFS_OBSERVABILITY_SERVICE_VERSION=0.1.0 +#export RUSTFS_OBSERVABILITY_ENVIRONMENT=develop +#export RUSTFS_OBSERVABILITY_LOGGER_LEVEL=debug +#export RUSTFS_OBSERVABILITY_LOCAL_LOGGING_ENABLED=true # #export RUSTFS__SINKS_0__type=File #export RUSTFS__SINKS_0__path=./deploy/logs/rustfs.log