diff --git a/.env.example b/.env.example index 01dc3d9..7334843 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,13 @@ EXPORTER_PORT=8000 -SCRAPE_INTERVAL=30 +UPDATE_INTERVAL=30 # twitch TWITCH_CLIENT_ID= TWITCH_CLIENT_SECRET= -TWITCH_CHANNELS=ikiznear \ No newline at end of file +TWITCH_CHANNELS=ikiznear + +# mail +MAIL_SERVER= +MAIL_PORT=993 +MAIL_USER= +MAIL_PASS= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 05d15f5..176ac32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim +FROM python:latest WORKDIR /app COPY . /app diff --git a/main.py b/main.py index 6b5e21e..04dd62d 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ import time from prometheus_client import start_http_server from dotenv import load_dotenv -load_dotenv() +load_dotenv('.env', verbose=True) def load_stat_modules(path='stats'): modules = [] @@ -23,10 +23,10 @@ def load_stat_modules(path='stats'): if __name__ == '__main__': port = int(os.getenv("EXPORTER_PORT", "8000")) + modules = load_stat_modules() print(f"Starting exporter on port {port}...") start_http_server(port) - modules = load_stat_modules() while True: for mod in modules: @@ -34,4 +34,4 @@ if __name__ == '__main__': mod.update() except Exception as e: print(f"Error in {mod.__name__}: {e}") - time.sleep(int(os.getenv("SCRAPE_INTERVAL", "30"))) + time.sleep(int(os.getenv("UPDATE_INTERVAL", "30"))) diff --git a/stats/mail.py b/stats/mail.py new file mode 100644 index 0000000..9a859af --- /dev/null +++ b/stats/mail.py @@ -0,0 +1,42 @@ +from prometheus_client import Gauge +import os +import imaplib + +unread_mails = Gauge('unread_mails', 'Number of unread mails', ['mailbox']) + +MAIL_SERVER = os.getenv("MAIL_SERVER") +MAIL_USER = os.getenv("MAIL_USER") +MAIL_PASS = os.getenv("MAIL_PASS") +MAIL_PORT = int(os.getenv("MAIL_PORT", 993)) + +print("[mail] Mail server:", MAIL_SERVER) +print("[mail] Mail user:", MAIL_USER) +print("[mail] Mail port:", MAIL_PORT) + +def update(): + try: + # handle secure differently, detect with port + if MAIL_PORT == 993: + mail = imaplib.IMAP4_SSL(MAIL_SERVER, MAIL_PORT) + else: + mail = imaplib.IMAP4(MAIL_SERVER, MAIL_PORT) + mail.login(MAIL_USER, MAIL_PASS) + mail.select("inbox") + result, data = mail.search(None, 'UNSEEN') + if result == 'OK': + unread_count = len(data[0].split()) + unread_mails.labels(mailbox="inbox").set(unread_count) + else: + print(f"[mail] Error searching inbox: {data}") + unread_mails.labels(mailbox="inbox").set(0) + mail.close() + mail.logout() + except imaplib.IMAP4.error as e: + print(f"[mail] IMAP error: {e}") + unread_mails.labels(mailbox="inbox").set(0) + except ConnectionRefusedError: + print("[mail] Connection refused. Check your IMAP server settings.") + unread_mails.labels(mailbox="inbox").set(0) + except Exception as e: + print(f"[mail] Error checking unread mails: {e}") + unread_mails.labels(mailbox="inbox").set(0) \ No newline at end of file diff --git a/stats/twitch_stats.py b/stats/twitch_stats.py index cff12c8..c509ece 100644 --- a/stats/twitch_stats.py +++ b/stats/twitch_stats.py @@ -17,7 +17,6 @@ _token_cache = { } print("[twitch] Client ID:", TWITCH_CLIENT_ID) -print("[twitch] Client Secret:", TWITCH_CLIENT_SECRET) print("[twitch] Channels:", CHANNELS) def get_token():