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

Small metrics tweaks #81

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.2
hash=6a3f7b1658909aed705809485a62426b
hash=c18860c7914c78fabefbae5f111993f1
=====================================
-->

# runtimepy ([1.7.0](https://pypi.org/project/runtimepy/))
# runtimepy ([1.7.1](https://pypi.org/project/runtimepy/))

[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "runtimepy"
version = "1.7.0"
version = "1.7.1"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
4 changes: 2 additions & 2 deletions runtimepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.2
# hash=428163e0258b1d93839c3226a9246203
# hash=5d1b6856bd3cb27cb017bd1036a96932
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "1.7.0"
VERSION = "1.7.1"
2 changes: 1 addition & 1 deletion runtimepy/net/arbiter/housekeeping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def dispatch(self) -> bool:


def metrics_poller(
manager: _ConnectionManager, period_s: float = 0.1
manager: _ConnectionManager, period_s: float = 0.5
) -> ConnectionMetricsPoller:
"""Create a metrics-polling task."""

Expand Down
21 changes: 16 additions & 5 deletions runtimepy/net/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"""

# third-party
from vcorelib.math import RateTracker
from vcorelib.math import RateTracker as _RateTracker

# internal
from runtimepy.primitives import Float as _Float
from runtimepy.primitives import Uint32 as _Uint32
from runtimepy.primitives import Uint64 as _Uint64

METRICS_DEPTH = 50


class ChannelMetrics:
"""Metrics for a network channel."""
Expand All @@ -18,23 +20,33 @@ def __init__(self) -> None:
"""Initialize this instance."""

self.messages = _Uint32()
self.message_rate = _Float()
self._message_rate_tracker = _RateTracker(depth=METRICS_DEPTH)

self.bytes = _Uint64()
self.kbps = _Float()
self._kbps_tracker = RateTracker()
self.stale = True
self._kbps_tracker = _RateTracker(depth=METRICS_DEPTH)

def poll(self, time_ns: int = None) -> None:
"""Poll kbps tracking."""

self.kbps.raw.value = self._kbps_tracker.poll(time_ns=time_ns)
self.message_rate.raw.value = self._message_rate_tracker.poll(
time_ns=time_ns
)

def increment(self, count: int, time_ns: int = None) -> None:
"""Update tracking."""

self.messages.raw.value += 1
self.message_rate.raw.value = self._message_rate_tracker(
time_ns=time_ns
)

self.bytes.raw.value += count
self.kbps.raw.value = self._kbps_tracker(
time_ns=time_ns, value=float(count) / 1000.0
)
self.stale = False

def reset(self) -> None:
"""Reset metrics."""
Expand All @@ -43,7 +55,6 @@ def reset(self) -> None:
self.bytes.raw.value = 0
self.kbps.raw.value = 0.0
self._kbps_tracker()
self.stale = True


class ConnectionMetrics:
Expand Down