Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove connections counter
Browse files Browse the repository at this point in the history
libretto committed Dec 20, 2023
1 parent 569d5ef commit 0386ca9
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions karapace/metrics.py
Original file line number Diff line number Diff line change
@@ -15,12 +15,7 @@
from karapace.prometheus import PrometheusClient
from karapace.statsd import StatsdClient

import os
import psutil
import schedule
import threading
import time


class MetricsException(Exception):
pass
@@ -43,8 +38,6 @@ def __init__(
self,
) -> None:
self.is_ready = False
self.stop_event = threading.Event()
self.worker_thread = threading.Thread(target=self.worker)
self.lock = threading.Lock()

def setup(self, config: Config) -> None:
@@ -62,8 +55,6 @@ def setup(self, config: Config) -> None:
else:
raise MetricsException('Config variable "stats_service" is not defined')
self.is_ready = True
schedule.every(10).seconds.do(self.connections)
self.worker_thread.start()

def request(self, size: int) -> None:
if not self.is_ready or self.stats_client is None:
@@ -100,31 +91,8 @@ def error(self) -> None:
raise RuntimeError("no StatsClient available")
self.stats_client.increase("error_total", 1)

def connections(self) -> None:
if not self.is_ready or self.stats_client is None:
return
if not isinstance(self.stats_client, StatsClient):
raise RuntimeError("no StatsClient available")
connections = 0
karapace_proc = psutil.Process(os.getpid())

for conn in karapace_proc.connections(kind="tcp"):
if conn.laddr and conn.status == "ESTABLISHED":
connections += 1
self.stats_client.gauge("connections-active", connections)

def worker(self) -> None:
while True:
if self.stop_event.is_set():
break
schedule.run_pending()
time.sleep(1)

def cleanup(self) -> None:
if self.stats_client:
self.stats_client.close()
if not self.is_ready:
return
self.stop_event.set()
if self.worker_thread.is_alive():
self.worker_thread.join()

0 comments on commit 0386ca9

Please sign in to comment.