Skip to content

Commit

Permalink
Update system metrics callbacks to accept CallbackOptions (open-telem…
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass authored May 10, 2022
1 parent fa56c6c commit 3e67893
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: 2c1cb20543fcc0bcfe5525d8a695e92babec06db
CORE_REPO_SHA: f367ec2045b2588be95dfa11913868c1d4fcbbc2

jobs:
build:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
path: |
.tox
~/.cache/pip
key: v4-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
key: v5-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
# - name: Find and merge ${{ matrix.package }} benchmarks
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
path: |
.tox
~/.cache/pip
key: v4-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
key: v5-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
- name: Ensure generated code is up to date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

import psutil

from opentelemetry._metrics import Observation, get_meter
from opentelemetry._metrics import CallbackOptions, Observation, get_meter

# FIXME Remove this pyling disabling line when Github issue is cleared
# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -320,7 +320,9 @@ def _instrument(self, **kwargs):
def _uninstrument(self, **__):
pass

def _get_system_cpu_time(self) -> Iterable[Observation]:
def _get_system_cpu_time(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for system CPU time"""
for cpu, times in enumerate(psutil.cpu_times(percpu=True)):
for metric in self._config["system.cpu.time"]:
Expand All @@ -331,7 +333,9 @@ def _get_system_cpu_time(self) -> Iterable[Observation]:
getattr(times, metric), self._system_cpu_time_labels
)

def _get_system_cpu_utilization(self) -> Iterable[Observation]:
def _get_system_cpu_utilization(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for system CPU utilization"""

for cpu, times_percent in enumerate(
Expand All @@ -346,7 +350,9 @@ def _get_system_cpu_utilization(self) -> Iterable[Observation]:
self._system_cpu_utilization_labels,
)

def _get_system_memory_usage(self) -> Iterable[Observation]:
def _get_system_memory_usage(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for memory usage"""
virtual_memory = psutil.virtual_memory()
for metric in self._config["system.memory.usage"]:
Expand All @@ -357,7 +363,9 @@ def _get_system_memory_usage(self) -> Iterable[Observation]:
self._system_memory_usage_labels,
)

def _get_system_memory_utilization(self) -> Iterable[Observation]:
def _get_system_memory_utilization(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for memory utilization"""
system_memory = psutil.virtual_memory()

Expand All @@ -369,7 +377,9 @@ def _get_system_memory_utilization(self) -> Iterable[Observation]:
self._system_memory_utilization_labels,
)

def _get_system_swap_usage(self) -> Iterable[Observation]:
def _get_system_swap_usage(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for swap usage"""
system_swap = psutil.swap_memory()

Expand All @@ -381,7 +391,9 @@ def _get_system_swap_usage(self) -> Iterable[Observation]:
self._system_swap_usage_labels,
)

def _get_system_swap_utilization(self) -> Iterable[Observation]:
def _get_system_swap_utilization(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for swap utilization"""
system_swap = psutil.swap_memory()

Expand All @@ -393,7 +405,9 @@ def _get_system_swap_utilization(self) -> Iterable[Observation]:
self._system_swap_utilization_labels,
)

def _get_system_disk_io(self) -> Iterable[Observation]:
def _get_system_disk_io(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for disk IO"""
for device, counters in psutil.disk_io_counters(perdisk=True).items():
for metric in self._config["system.disk.io"]:
Expand All @@ -405,7 +419,9 @@ def _get_system_disk_io(self) -> Iterable[Observation]:
self._system_disk_io_labels,
)

def _get_system_disk_operations(self) -> Iterable[Observation]:
def _get_system_disk_operations(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for disk operations"""
for device, counters in psutil.disk_io_counters(perdisk=True).items():
for metric in self._config["system.disk.operations"]:
Expand All @@ -417,7 +433,9 @@ def _get_system_disk_operations(self) -> Iterable[Observation]:
self._system_disk_operations_labels,
)

def _get_system_disk_time(self) -> Iterable[Observation]:
def _get_system_disk_time(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for disk time"""
for device, counters in psutil.disk_io_counters(perdisk=True).items():
for metric in self._config["system.disk.time"]:
Expand All @@ -429,7 +447,9 @@ def _get_system_disk_time(self) -> Iterable[Observation]:
self._system_disk_time_labels,
)

def _get_system_disk_merged(self) -> Iterable[Observation]:
def _get_system_disk_merged(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for disk merged operations"""

# FIXME The units in the spec is 1, it seems like it should be
Expand All @@ -445,7 +465,9 @@ def _get_system_disk_merged(self) -> Iterable[Observation]:
self._system_disk_merged_labels,
)

def _get_system_network_dropped_packets(self) -> Iterable[Observation]:
def _get_system_network_dropped_packets(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for network dropped packets"""

for device, counters in psutil.net_io_counters(pernic=True).items():
Expand All @@ -463,7 +485,9 @@ def _get_system_network_dropped_packets(self) -> Iterable[Observation]:
self._system_network_dropped_packets_labels,
)

def _get_system_network_packets(self) -> Iterable[Observation]:
def _get_system_network_packets(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for network packets"""

for device, counters in psutil.net_io_counters(pernic=True).items():
Expand All @@ -477,7 +501,9 @@ def _get_system_network_packets(self) -> Iterable[Observation]:
self._system_network_packets_labels,
)

def _get_system_network_errors(self) -> Iterable[Observation]:
def _get_system_network_errors(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for network errors"""
for device, counters in psutil.net_io_counters(pernic=True).items():
for metric in self._config["system.network.errors"]:
Expand All @@ -490,7 +516,9 @@ def _get_system_network_errors(self) -> Iterable[Observation]:
self._system_network_errors_labels,
)

def _get_system_network_io(self) -> Iterable[Observation]:
def _get_system_network_io(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for network IO"""

for device, counters in psutil.net_io_counters(pernic=True).items():
Expand All @@ -504,7 +532,9 @@ def _get_system_network_io(self) -> Iterable[Observation]:
self._system_network_io_labels,
)

def _get_system_network_connections(self) -> Iterable[Observation]:
def _get_system_network_connections(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for network connections"""
# TODO How to find the device identifier for a particular
# connection?
Expand Down Expand Up @@ -542,7 +572,9 @@ def _get_system_network_connections(self) -> Iterable[Observation]:
connection_counter["labels"],
)

def _get_runtime_memory(self) -> Iterable[Observation]:
def _get_runtime_memory(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for runtime memory"""
proc_memory = self._proc.memory_info()
for metric in self._config["runtime.memory"]:
Expand All @@ -553,7 +585,9 @@ def _get_runtime_memory(self) -> Iterable[Observation]:
self._runtime_memory_labels,
)

def _get_runtime_cpu_time(self) -> Iterable[Observation]:
def _get_runtime_cpu_time(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for runtime CPU time"""
proc_cpu = self._proc.cpu_times()
for metric in self._config["runtime.cpu.time"]:
Expand All @@ -564,7 +598,9 @@ def _get_runtime_cpu_time(self) -> Iterable[Observation]:
self._runtime_cpu_time_labels,
)

def _get_runtime_gc_count(self) -> Iterable[Observation]:
def _get_runtime_gc_count(
self, options: CallbackOptions
) -> Iterable[Observation]:
"""Observer callback for garbage collection"""
for index, count in enumerate(gc.get_count()):
self._runtime_gc_count_labels["count"] = str(index)
Expand Down

0 comments on commit 3e67893

Please sign in to comment.