diff --git a/homeassistant/components/prometheus/__init__.py b/homeassistant/components/prometheus/__init__.py index 2159656f129..a0f0d69ce46 100644 --- a/homeassistant/components/prometheus/__init__.py +++ b/homeassistant/components/prometheus/__init__.py @@ -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, )