Skip to content

Commit ca68348

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

File tree

1 file changed

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

1 file changed

+24
-0
lines changed

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

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

181+
# Filter 'sin' and 'sout' from 'system.swap.usage'
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:
185+
vmstat = os.path.join(psutil.PROCFS_PATH, "vmstat")
186+
if not os.path.exists(vmstat):
187+
_logger.warning(
188+
"Could not find '%s'! The 'sin' and 'sout' "
189+
"states will not be included among metrics.",
190+
vmstat,
191+
)
192+
if usage := self._config.get("system.swap.usage"):
193+
self._config["system.swap.usage"] = [
194+
state
195+
for state in usage
196+
if state not in ("sin", "sout")
197+
]
198+
if utilization := self._config.get("system.swap.utilization"):
199+
self._config["system.swap.utilization"] = [
200+
state
201+
for state in utilization
202+
if state not in ("sin", "sout")
203+
]
204+
181205
self._proc = psutil.Process(os.getpid())
182206

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

0 commit comments

Comments
 (0)