diff --git a/src/charm.py b/src/charm.py index 69445e28..76c3b281 100755 --- a/src/charm.py +++ b/src/charm.py @@ -123,8 +123,11 @@ def __init__(self, *args): self.metrics_endpoint = MetricsEndpointProvider( charm=self, - jobs=[{"static_configs": [{"targets": ["*:3000"]}]}], - refresh_event=self.on.grafana_pebble_ready, # pyright: ignore + jobs=self._scrape_jobs, + refresh_event=[ + self.on.grafana_pebble_ready, # pyright: ignore + self.on.update_status, + ], ) # -- standard events @@ -1175,6 +1178,18 @@ def generate_auth_env_vars(self, conf: Dict[str, Dict[str, Any]]) -> Dict[str, s env_vars[auth_var_prefix + str(var).upper()] = str(conf[auth_mode][var]) return env_vars + @property + def _hostname(self) -> str: + return socket.getfqdn() + + @property + def _scrape_jobs(self) -> list: + return [ + { + "static_configs": [{"targets": [f"{self._hostname}:{PORT}"]}], + } + ] + if __name__ == "__main__": main(GrafanaCharm, use_juju_for_storage=True) diff --git a/tox.ini b/tox.ini index 7472b992..15cec3f3 100644 --- a/tox.ini +++ b/tox.ini @@ -86,7 +86,8 @@ description = Run integration tests deps = aiohttp asyncstdlib - juju + # Libjuju needs to track the juju version + juju ~= 3.1.0 pytest pytest-operator commands =