Merge pull request #273 from doccodyblue/feature/266-normalize-prometheus-metric-names
Feature/266 normalize prometheus metric names
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
				
			|||||||
from . import Controller
 | 
					from . import Controller
 | 
				
			||||||
from owrx.metrics import CounterMetric, DirectMetric, Metrics
 | 
					from owrx.metrics import CounterMetric, DirectMetric, Metrics
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MetricsController(Controller):
 | 
					class MetricsController(Controller):
 | 
				
			||||||
@@ -21,7 +23,7 @@ class MetricsController(Controller):
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                raise ValueError("Unexpected metric type for metric {}".format(repr(metric)))
 | 
					                raise ValueError("Unexpected metric type for metric {}".format(repr(metric)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return "{key} {value}".format(key=key.replace(".", "_"), value=value)
 | 
					            return "{key} {value}".format(key=re.sub('[^a-zA-Z0-9:_]', '_', key), value=value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        data = ["# https://prometheus.io/docs/instrumenting/exposition_formats/"] + [
 | 
					        data = ["# https://prometheus.io/docs/instrumenting/exposition_formats/"] + [
 | 
				
			||||||
            prometheusFormat(k, v) for k, v in metrics.items()
 | 
					            prometheusFormat(k, v) for k, v in metrics.items()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user