mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 08:56:04 -04:00
Use _ instead of . as a metric namespacing separator, for Prometheus
This commit is contained in:
parent
0b96bb793e
commit
b0cf867319
8 changed files with 34 additions and 18 deletions
|
@ -41,7 +41,12 @@ class Metrics(object):
|
|||
self.name_prefix = name
|
||||
|
||||
def _register(self, metric_class, name, *args, **kwargs):
|
||||
full_name = "%s.%s" % (self.name_prefix, name)
|
||||
if "_" in name:
|
||||
raise ValueError("Metric names %s is invalid as it cannot contain an underscore"
|
||||
% (name)
|
||||
)
|
||||
|
||||
full_name = "%s_%s" % (self.name_prefix, name)
|
||||
|
||||
metric = metric_class(full_name, *args, **kwargs)
|
||||
|
||||
|
@ -78,10 +83,13 @@ class Metrics(object):
|
|||
return wrapped
|
||||
|
||||
|
||||
def get_metrics_for(name):
|
||||
def get_metrics_for(pkg_name):
|
||||
""" Returns a Metrics instance for conveniently creating metrics
|
||||
namespaced with the given name prefix. """
|
||||
return Metrics(name)
|
||||
|
||||
# Convert a "package.name" to "package_name" because Prometheus doesn't
|
||||
# let us use . in metric names
|
||||
return Metrics(pkg_name.replace(".", "_"))
|
||||
|
||||
|
||||
def render_all():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue