Mercurial > prosody-hg
comparison util/openmetrics.lua @ 12535:7ef7abb72cdd
util.openmetrics: Set __name field on metatables to improve error messages
Don't think we cause any such errors right now, but you never know!
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 30 May 2022 17:37:25 +0200 |
| parents | 3caff1f93520 |
| children | 39ae08180c81 |
comparison
equal
deleted
inserted
replaced
| 12534:3caff1f93520 | 12535:7ef7abb72cdd |
|---|---|
| 33 -- `with_labels` and `with_partial_label` methods. This allows to pre-set one | 33 -- `with_labels` and `with_partial_label` methods. This allows to pre-set one |
| 34 -- or more labels on a metric family. This is used in particular via | 34 -- or more labels on a metric family. This is used in particular via |
| 35 -- `with_partial_label` by the moduleapi in order to pre-set the `host` label | 35 -- `with_partial_label` by the moduleapi in order to pre-set the `host` label |
| 36 -- on metrics created in non-global modules. | 36 -- on metrics created in non-global modules. |
| 37 local metric_proxy_mt = {} | 37 local metric_proxy_mt = {} |
| 38 metric_proxy_mt.__name = "metric_proxy" | |
| 38 metric_proxy_mt.__index = metric_proxy_mt | 39 metric_proxy_mt.__index = metric_proxy_mt |
| 39 | 40 |
| 40 local function new_metric_proxy(metric_family, with_labels_proxy_fun) | 41 local function new_metric_proxy(metric_family, with_labels_proxy_fun) |
| 41 return setmetatable({ | 42 return setmetatable({ |
| 42 _family = metric_family, | 43 _family = metric_family, |
| 126 end | 127 end |
| 127 | 128 |
| 128 -- BEGIN of generic MetricFamily implementation | 129 -- BEGIN of generic MetricFamily implementation |
| 129 | 130 |
| 130 local metric_family_mt = {} | 131 local metric_family_mt = {} |
| 132 metric_family_mt.__name = "metric_family" | |
| 131 metric_family_mt.__index = metric_family_mt | 133 metric_family_mt.__index = metric_family_mt |
| 132 | 134 |
| 133 local function histogram_metric_ctor(orig_ctor, buckets) | 135 local function histogram_metric_ctor(orig_ctor, buckets) |
| 134 return function(family_name, labels, extra) | 136 return function(family_name, labels, extra) |
| 135 return orig_ctor(buckets, family_name, labels, extra) | 137 return orig_ctor(buckets, family_name, labels, extra) |
| 276 -- conflicts | 278 -- conflicts |
| 277 return full_name | 279 return full_name |
| 278 end | 280 end |
| 279 | 281 |
| 280 local metric_registry_mt = {} | 282 local metric_registry_mt = {} |
| 283 metric_registry_mt.__name = "metric_registry" | |
| 281 metric_registry_mt.__index = metric_registry_mt | 284 metric_registry_mt.__index = metric_registry_mt |
| 282 | 285 |
| 283 local function new_metric_registry(backend) | 286 local function new_metric_registry(backend) |
| 284 local reg = { | 287 local reg = { |
| 285 families = {}, | 288 families = {}, |
