Add libretranslate namespace to prometheus metrics

This commit is contained in:
Piero Toffanin 2022-12-26 16:49:04 -05:00
parent b6111b95f8
commit 9d2a2cd55f
3 changed files with 10 additions and 10 deletions

View file

@ -276,13 +276,13 @@ LibreTranslate has Prometheus [exporter](https://prometheus.io/docs/instrumentin
http://localhost:5000/metrics http://localhost:5000/metrics
``` ```
# HELP request_inprogress Multiprocess metric # HELP libretranslate_http_requests_in_flight Multiprocess metric
# TYPE request_inprogress gauge # TYPE libretranslate_http_requests_in_flight gauge
request_inprogress{api_key="",endpoint="/translate",request_ip="127.0.0.1"} 0.0 libretranslate_http_requests_in_flight{api_key="",endpoint="/translate",request_ip="127.0.0.1"} 0.0
# HELP request_seconds Multiprocess metric # HELP libretranslate_http_request_duration_seconds Multiprocess metric
# TYPE request_seconds summary # TYPE libretranslate_http_request_duration_seconds summary
request_seconds_count{api_key="",endpoint="/translate",request_ip="127.0.0.1",status="200"} 0.0 libretranslate_http_request_duration_seconds_count{api_key="",endpoint="/translate",request_ip="127.0.0.1",status="200"} 0.0
request_seconds_sum{api_key="",endpoint="/translate",request_ip="127.0.0.1",status="200"} 0.0 libretranslate_http_request_duration_seconds_sum{api_key="",endpoint="/translate",request_ip="127.0.0.1",status="200"} 0.0
``` ```
You can then configure `prometheus.yml` to read the metrics: You can then configure `prometheus.yml` to read the metrics:

View file

@ -1 +1 @@
1.3.5 1.3.6

View file

@ -192,10 +192,10 @@ def create_app(args):
multiprocess.MultiProcessCollector(registry) multiprocess.MultiProcessCollector(registry)
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST) return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)
measure_request = Summary('request_seconds', 'Time spent on request', ['endpoint', 'status', 'request_ip', 'api_key']) measure_request = Summary('libretranslate_http_request_duration_seconds', 'Time spent on request', ['endpoint', 'status', 'request_ip', 'api_key'])
measure_request.labels('/translate', 200, '127.0.0.1', '') measure_request.labels('/translate', 200, '127.0.0.1', '')
gauge_request = Gauge('request_inprogress', 'Active requests', ['endpoint', 'request_ip', 'api_key'], multiprocess_mode='livesum') gauge_request = Gauge('libretranslate_http_requests_in_flight', 'Active requests', ['endpoint', 'request_ip', 'api_key'], multiprocess_mode='livesum')
gauge_request.labels('/translate', '127.0.0.1', '') gauge_request.labels('/translate', '127.0.0.1', '')
def access_check(f): def access_check(f):