Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect threads count in opentelemetry-instrumentation-system-metrics #1339

Merged
merged 19 commits into from
Sep 28, 2022
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"system.network.errors": ["transmit", "receive"],
"system.network.io": ["transmit", "receive"],
"system.network.connections": ["family", "type"],
"system.threading.active_count": None
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
}
Expand Down Expand Up @@ -71,6 +72,7 @@

import gc
import os
import threading
from platform import python_implementation
from typing import Collection, Dict, Iterable, List, Optional

Expand Down Expand Up @@ -99,6 +101,7 @@
"system.network.errors": ["transmit", "receive"],
"system.network.io": ["transmit", "receive"],
"system.network.connections": ["family", "type"],
"system.threading.active_count": None,
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"runtime.gc_count": None,
Expand Down Expand Up @@ -142,6 +145,8 @@ def __init__(
self._system_network_io_labels = self._labels.copy()
self._system_network_connections_labels = self._labels.copy()

self._system_threading_active_count_labels = self._labels.copy()

self._runtime_memory_labels = self._labels.copy()
self._runtime_cpu_time_labels = self._labels.copy()
self._runtime_gc_count_labels = self._labels.copy()
Expand Down Expand Up @@ -311,6 +316,13 @@ def _instrument(self, **kwargs):
unit="connections",
)

if "system.threading.active_count" in self._config:
self._meter.create_observable_gauge(
name=f"system.threading.active_count",
callbacks=[self._get_system_threading_active_count],
description=f"System active threads count",
)

if "runtime.memory" in self._config:
self._meter.create_observable_counter(
name=f"runtime.{self._python_implementation}.memory",
Expand Down Expand Up @@ -420,7 +432,7 @@ def _get_system_swap_utilization(
if hasattr(system_swap, metric):
self._system_swap_utilization_labels["state"] = metric
yield Observation(
getattr(system_swap, metric) / system_swap.total,
getattr(system_swap, metric) / system_swap.total if system_swap.total else 0,
self._system_swap_utilization_labels.copy(),
)

Expand Down Expand Up @@ -591,6 +603,14 @@ def _get_system_network_connections(
connection_counter["labels"],
)

def _get_system_threading_active_count(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for active threads count"""
yield Observation(
threading.active_count(), self._system_threading_active_count_labels
)

def _get_runtime_memory(
self, options: CallbackOptions
) -> Iterable[Observation]:
Expand Down