Fix prometheus metrics

Use a singleton to prevent attempt to rebind socket on page reload.
This commit is contained in:
Jakob Lechner 2025-08-02 00:01:29 +02:00
parent fcfec4b6a9
commit 82263557af
3 changed files with 30 additions and 15 deletions

View file

@ -1,9 +1,10 @@
class Counter:
def __init__(self, line_orientation):
def __init__(self, line_orientation, metrics):
self.in_count = 0
self.out_count = 0
self.track_memory = {}
self.line_orientation = line_orientation
self.metrics = metrics
def update(self, tracks, line_position):
for track in tracks:
@ -27,5 +28,7 @@ class Counter:
if prev < line_position <= center:
self.in_count += 1
self.metrics["people_in"].inc()
elif prev > line_position >= center:
self.out_count += 1
self.metrics["people_out"].inc()