A slightly neater way to manage metric collector functions
This commit is contained in:
parent
5663137e03
commit
4cedd53224
|
@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
all_metrics = []
|
all_metrics = []
|
||||||
|
all_collectors = []
|
||||||
|
|
||||||
|
|
||||||
class Metrics(object):
|
class Metrics(object):
|
||||||
|
@ -46,6 +47,9 @@ class Metrics(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name_prefix = name
|
self.name_prefix = name
|
||||||
|
|
||||||
|
def register_collector(self, func):
|
||||||
|
all_collectors.append(func)
|
||||||
|
|
||||||
def _register(self, metric_class, name, *args, **kwargs):
|
def _register(self, metric_class, name, *args, **kwargs):
|
||||||
full_name = "%s_%s" % (self.name_prefix, name)
|
full_name = "%s_%s" % (self.name_prefix, name)
|
||||||
|
|
||||||
|
@ -94,8 +98,8 @@ def get_metrics_for(pkg_name):
|
||||||
def render_all():
|
def render_all():
|
||||||
strs = []
|
strs = []
|
||||||
|
|
||||||
# TODO(paul): Internal hack
|
for collector in all_collectors:
|
||||||
update_resource_metrics()
|
collector()
|
||||||
|
|
||||||
for metric in all_metrics:
|
for metric in all_metrics:
|
||||||
try:
|
try:
|
||||||
|
@ -188,6 +192,8 @@ def _process_fds():
|
||||||
|
|
||||||
resource_metrics = get_metrics_for("process.resource")
|
resource_metrics = get_metrics_for("process.resource")
|
||||||
|
|
||||||
|
resource_metrics.register_collector(update_resource_metrics)
|
||||||
|
|
||||||
# msecs
|
# msecs
|
||||||
resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
|
resource_metrics.register_callback("utime", lambda: rusage.ru_utime * 1000)
|
||||||
resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)
|
resource_metrics.register_callback("stime", lambda: rusage.ru_stime * 1000)
|
||||||
|
|
Loading…
Reference in New Issue