Generate Prometheus metrics in an executor job (#121058)

This commit is contained in:
Anton Tolchanov 2024-07-03 14:41:01 +01:00 committed by Franck Nijhof
parent 16827ea09e
commit 36e74cd9a6
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3

View File

@ -26,7 +26,7 @@ from homeassistant.components.cover import (
ATTR_CURRENT_POSITION,
ATTR_CURRENT_TILT_POSITION,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.humidifier import ATTR_AVAILABLE_MODES, ATTR_HUMIDITY
from homeassistant.components.light import ATTR_BRIGHTNESS
from homeassistant.components.sensor import SensorDeviceClass
@ -729,7 +729,11 @@ class PrometheusView(HomeAssistantView):
"""Handle request for Prometheus metrics."""
_LOGGER.debug("Received Prometheus metrics request")
hass = request.app[KEY_HASS]
body = await hass.async_add_executor_job(
prometheus_client.generate_latest, prometheus_client.REGISTRY
)
return web.Response(
body=prometheus_client.generate_latest(prometheus_client.REGISTRY),
body=body,
content_type=CONTENT_TYPE_TEXT_PLAIN,
)