diff --git a/dockstat.py b/dockstat.py index 562bd38..166739b 100644 --- a/dockstat.py +++ b/dockstat.py @@ -11,18 +11,17 @@ import sys from http.server import HTTPServer from typing import Any -import docker # type: ignore[import] -import docker.errors # type: ignore[import] +import docker +import docker.errors import numpy -from docker.models.containers import Container # type: ignore[import] -from prometheus_client import CollectorRegistry # type: ignore[import] -from prometheus_client import Gauge, MetricsHandler, generate_latest +from docker.models.containers import Container +from prometheus_client import CollectorRegistry, Gauge, MetricsHandler, generate_latest LISTEN_PORT = int(os.environ.get("DOCKSTAT_LISTEN_PORT", 8080)) HEALTHY_STR = "healthy" -class HTTPHandler(MetricsHandler): # type: ignore[misc] +class HTTPHandler(MetricsHandler): """ Class to encompass the requirements of a Prometheus Exporter for Docker containers with a healthcheck configured @@ -62,6 +61,7 @@ class HTTPHandler(MetricsHandler): # type: ignore[misc] message (str): String to output """ self.send_response(int(status) or 500) + self.send_header("content-type", "text/plain") self.end_headers() try: self.wfile.write(bytes(str(message).encode())) @@ -111,9 +111,9 @@ class HTTPHandler(MetricsHandler): # type: ignore[misc] ) container: Container - for container in self.docker_client.containers.list(all=True): # type: ignore + for container in self.docker_client.containers.list(all=True): try: - data = self.docker_api.inspect_container(container.id) + data = self.docker_api.inspect_container(getattr(container, "id")) except docker.errors.NotFound: print(f"WARNING: Container {container.id} does not exist. Skipping.") continue