mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 04:34:01 +08:00
opentelemetry-instrumentation-system-metrics: fix typo in metrics configs (#3025)
This commit is contained in:

committed by
GitHub

parent
116f98df72
commit
d9e14487b2
@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
|
- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
|
||||||
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))
|
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))
|
||||||
|
- `opentelemetry-instrumentation-system_metrics`: fix callbacks reading wrong config
|
||||||
|
([#3025](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3025))
|
||||||
- `opentelemetry-instrumentation-httpx`: Check if mount transport is none before wrap it
|
- `opentelemetry-instrumentation-httpx`: Check if mount transport is none before wrap it
|
||||||
([#3022](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3022))
|
([#3022](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3022))
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ following metrics are configured:
|
|||||||
"process.runtime.thread_count": None,
|
"process.runtime.thread_count": None,
|
||||||
"process.runtime.cpu.utilization": None,
|
"process.runtime.cpu.utilization": None,
|
||||||
"process.runtime.context_switches": ["involuntary", "voluntary"],
|
"process.runtime.context_switches": ["involuntary", "voluntary"],
|
||||||
|
"process.open_file_descriptor.count": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
@ -595,7 +596,7 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
|||||||
"""Observer callback for network packets"""
|
"""Observer callback for network packets"""
|
||||||
|
|
||||||
for device, counters in psutil.net_io_counters(pernic=True).items():
|
for device, counters in psutil.net_io_counters(pernic=True).items():
|
||||||
for metric in self._config["system.network.dropped.packets"]:
|
for metric in self._config["system.network.packets"]:
|
||||||
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
|
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
|
||||||
if hasattr(counters, f"packets_{recv_sent}"):
|
if hasattr(counters, f"packets_{recv_sent}"):
|
||||||
self._system_network_packets_labels["device"] = device
|
self._system_network_packets_labels["device"] = device
|
||||||
@ -626,7 +627,7 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
|||||||
"""Observer callback for network IO"""
|
"""Observer callback for network IO"""
|
||||||
|
|
||||||
for device, counters in psutil.net_io_counters(pernic=True).items():
|
for device, counters in psutil.net_io_counters(pernic=True).items():
|
||||||
for metric in self._config["system.network.dropped.packets"]:
|
for metric in self._config["system.network.io"]:
|
||||||
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
|
recv_sent = {"receive": "recv", "transmit": "sent"}[metric]
|
||||||
if hasattr(counters, f"bytes_{recv_sent}"):
|
if hasattr(counters, f"bytes_{recv_sent}"):
|
||||||
self._system_network_io_labels["device"] = device
|
self._system_network_io_labels["device"] = device
|
||||||
|
@ -20,6 +20,7 @@ from platform import python_implementation
|
|||||||
from unittest import mock, skipIf
|
from unittest import mock, skipIf
|
||||||
|
|
||||||
from opentelemetry.instrumentation.system_metrics import (
|
from opentelemetry.instrumentation.system_metrics import (
|
||||||
|
_DEFAULT_CONFIG,
|
||||||
SystemMetricsInstrumentor,
|
SystemMetricsInstrumentor,
|
||||||
)
|
)
|
||||||
from opentelemetry.sdk.metrics import MeterProvider
|
from opentelemetry.sdk.metrics import MeterProvider
|
||||||
@ -865,3 +866,14 @@ class TestSystemMetrics(TestBase):
|
|||||||
expected,
|
expected,
|
||||||
)
|
)
|
||||||
mock_process_num_fds.assert_called()
|
mock_process_num_fds.assert_called()
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfigSystemMetrics(TestBase):
|
||||||
|
# pylint:disable=no-self-use
|
||||||
|
def test_that_correct_config_is_read(self):
|
||||||
|
for key, value in _DEFAULT_CONFIG.items():
|
||||||
|
meter_provider = MeterProvider([InMemoryMetricReader()])
|
||||||
|
instrumentor = SystemMetricsInstrumentor(config={key: value})
|
||||||
|
instrumentor.instrument(meter_provider=meter_provider)
|
||||||
|
meter_provider.force_flush()
|
||||||
|
instrumentor.uninstrument()
|
||||||
|
Reference in New Issue
Block a user