Skip to content

Commit

Permalink
Generate Prometheus metrics in an executor job (#121058)
Browse files Browse the repository at this point in the history
  • Loading branch information
knyar authored and frenck committed Jul 3, 2024
1 parent 16827ea commit 36e74cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions homeassistant/components/prometheus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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
Expand Down Expand Up @@ -729,7 +729,11 @@ async def get(self, request: web.Request) -> web.Response:
"""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,
)

0 comments on commit 36e74cd

Please sign in to comment.