-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
35 lines (30 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Fills Prometheus with Smart Home Data
"""
from datetime import datetime
import time
import os
import configparser
import importlib
from apscheduler.schedulers.background import BackgroundScheduler
from prometheus_client import start_http_server
if __name__ == '__main__':
scheduler = BackgroundScheduler()
config = configparser.ConfigParser()
config.read("config/config.ini")
for moduleName in config.sections():
if config[moduleName]['enabled'] == 'yes':
print("Modul " + moduleName + " enabled!")
module = importlib.import_module("."+moduleName,"modules")
if "getdata" in dir(module) and "init" in dir(module):
module.init(config[moduleName])
scheduler.add_job(module.getdata, 'interval', seconds=int(config[moduleName]['interval']))
else:
print("Module " + moduleName + " has no function getdata or init!")
scheduler.start()
start_http_server(8000)
try:
while True:
time.sleep(2)
except (KeyboardInterrupt, SystemExit):
scheduler.shutdown()