mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 03:53:52 +01:00
A slightly neater way to manage metric collector functions
This commit is contained in:
parent
5663137e03
commit
4cedd53224
1 changed files with 8 additions and 2 deletions
|
@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
all_metrics = []
|
||||
all_collectors = []
|
||||
|
||||
|
||||
class Metrics(object):
|
||||
|
@ -46,6 +47,9 @@ class Metrics(object):
|
|||
def __init__(self, name):
|
||||
self.name_prefix = name
|
||||
|
||||
def register_collector(self, func):
|
||||
all_collectors.append(func)
|
||||
|
||||
def _register(self, metric_class, name, *args, **kwargs):
|
||||
full_name = "%s_%s" % (self.name_prefix, name)
|
||||
|
||||
|
@ -94,8 +98,8 @@ def get_metrics_for(pkg_name):
|
|||
def render_all():
|
||||
strs = []
|
||||
|
||||
# TODO(paul): Internal hack
|
||||
update_resource_metrics()
|
||||
for collector in all_collectors:
|
||||
collector()
|
||||
|
||||
for metric in all_metrics:
|
||||
try:
|
||||
|
@ -188,6 +192,8 @@ def _process_fds():
|
|||
|
||||
resource_metrics = get_metrics_for("process.resource")
|
||||
|
||||
resource_metrics.register_collector(update_resource_metrics)
|
||||
|
||||
# msecs
|
||||
resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
|
||||
resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)
|
||||
|
|
Loading…
Reference in a new issue