init: initial commit

This commit is contained in:
Strix 2025-04-09 23:59:52 +02:00
commit d4496a2eda
8 changed files with 120 additions and 0 deletions

37
main.py Normal file
View file

@ -0,0 +1,37 @@
import os
import importlib.util
import time
from prometheus_client import start_http_server
from dotenv import load_dotenv
load_dotenv()
def load_stat_modules(path='stats'):
modules = []
for filename in os.listdir(path):
if filename.endswith(".py") and filename != "__init__.py":
module_name = filename[:-3]
filepath = os.path.join(path, filename)
spec = importlib.util.spec_from_file_location(module_name, filepath)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if hasattr(module, 'update'):
modules.append(module)
return modules
if __name__ == '__main__':
port = int(os.getenv("EXPORTER_PORT", "8000"))
print(f"Starting exporter on port {port}...")
start_http_server(port)
modules = load_stat_modules()
while True:
for mod in modules:
try:
mod.update()
except Exception as e:
print(f"Error in {mod.__name__}: {e}")
time.sleep(int(os.getenv("SCRAPE_INTERVAL", "30")))