Prefix for Prometheus metrics (#151)

Added default prefix for Prometheus metrics.
This commit is contained in:
dasmfm
2019-10-09 12:35:02 +03:00
committed by Alexander Bersenev
parent 0a41479054
commit c010543889

View File

@@ -236,6 +236,9 @@ def init_config():
# export proxy link to prometheus # export proxy link to prometheus
conf_dict.setdefault("METRICS_EXPORT_LINKS", False) conf_dict.setdefault("METRICS_EXPORT_LINKS", False)
# default prefix for metrics
conf_dict.setdefault("METRICS_PREFIX", "mtprotoproxy_")
# allow access to config by attributes # allow access to config by attributes
config = type("config", (dict,), conf_dict)(conf_dict) config = type("config", (dict,), conf_dict)(conf_dict)
@@ -1586,6 +1589,7 @@ def make_metrics_pkt(metrics):
used_names = set() used_names = set()
for name, m_type, desc, val in metrics: for name, m_type, desc, val in metrics:
name = config.METRICS_PREFIX + name
if name not in used_names: if name not in used_names:
pkt_body_list.append("# HELP %s %s" % (name, desc)) pkt_body_list.append("# HELP %s %s" % (name, desc))
pkt_body_list.append("# TYPE %s %s" % (name, m_type)) pkt_body_list.append("# TYPE %s %s" % (name, m_type))