Skip to content

Commit 9431692

Browse files
committed
Log warning on Linux if /proc/vmstat is not available and remove metric states
1 parent fc878a6 commit 9431692

File tree

1 file changed

+27
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics

1 file changed

+27
-0
lines changed

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,33 @@ def __init__(
178178
)
179179
self._config.pop("system.network.connections")
180180

181+
# Filter 'sin' and 'sout' from 'system.swap' metrics
182+
# if '/proc/vmstat' is not available and issue a warning.
183+
# See: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3740.
184+
if psutil.LINUX and (
185+
"system.swap.usage" in self._config
186+
or "system.swap.utilization" in self._config
187+
):
188+
vmstat = os.path.join(psutil.PROCFS_PATH, "vmstat")
189+
if not os.path.exists(vmstat):
190+
_logger.warning(
191+
"Could not find '%s'! The 'sin' and 'sout' states"
192+
"will not be included in 'system.swap' metrics.",
193+
vmstat,
194+
)
195+
if usage := self._config.get("system.swap.usage"):
196+
self._config["system.swap.usage"] = [
197+
state
198+
for state in usage
199+
if state not in ("sin", "sout")
200+
]
201+
if utilization := self._config.get("system.swap.utilization"):
202+
self._config["system.swap.utilization"] = [
203+
state
204+
for state in utilization
205+
if state not in ("sin", "sout")
206+
]
207+
181208
self._proc = psutil.Process(os.getpid())
182209

183210
self._system_cpu_time_labels = self._labels.copy()

0 commit comments

Comments
 (0)