diff --git a/README.md b/README.md index 0143c61..5895d6c 100644 --- a/README.md +++ b/README.md @@ -39,5 +39,6 @@ Your metrics will be available at All configuration is done with environment variables. +- `SMARTCTL_REFRESH_INTERVAL`: (Optional) The refresh interval of the metrics. A larger value reduces CPU usage. The default is `60` seconds. - `SMARTCTL_EXPORTER_PORT`: (Optional) The address the exporter should listen on. The default is `9902`. - `SMARTCTL_EXPORTER_ADDRESS`: (Optional) The address the exporter should listen on. The default is to listen on all addresses. diff --git a/smartprom.py b/smartprom.py index 706616b..89cb56e 100755 --- a/smartprom.py +++ b/smartprom.py @@ -157,19 +157,14 @@ def main(): """ exporter_address = os.environ.get("SMARTCTL_EXPORTER_ADDRESS", "0.0.0.0") exporter_port = int(os.environ.get("SMARTCTL_EXPORTER_PORT", 9902)) + refresh_interval = int(os.environ.get("SMARTCTL_REFRESH_INTERVAL", 60)) start_http_server(exporter_port, exporter_address) print(f"Server listening in http://{exporter_address}:{exporter_port}/metrics") - collect() - - start_time = time.time() while True: - elapsed_time = time.time() - start_time - if elapsed_time > 20.0: - start_time = time.time() - collect() - time.sleep(0.1) + collect() + time.sleep(refresh_interval) if __name__ == '__main__':