2020-04-14 22:49:22 +00:00
|
|
|
import config
|
|
|
|
import database
|
|
|
|
import signal
|
2020-04-17 16:16:58 +00:00
|
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
2020-04-14 22:49:22 +00:00
|
|
|
from threading import Event
|
2020-04-14 22:52:07 +00:00
|
|
|
from plugins.system.cpu_plugin import CpuPlugin
|
|
|
|
from plugins.system.memory_plugin import MemoryPlugin
|
2020-04-17 16:16:58 +00:00
|
|
|
from plugins.system.disk_plugin import DiskIOPlugin, DiskUsagePlugin
|
2020-04-14 22:52:07 +00:00
|
|
|
from plugins.system.network_plugin import NetworkPlugin
|
|
|
|
from plugins.system.temperatures_plugin import TemperaturesPlugin
|
|
|
|
from plugins.system.ping_plugin import PingPlugin
|
2020-04-17 16:16:58 +00:00
|
|
|
from plugins.finance.stocks_plugin import StocksPlugin
|
2020-04-15 20:29:29 +00:00
|
|
|
from plugins.finance.robor_plugin import RoborPlugin
|
2020-04-17 16:16:58 +00:00
|
|
|
import logging
|
|
|
|
|
2020-04-14 22:49:22 +00:00
|
|
|
|
|
|
|
class Collector(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.plugins = [
|
2020-04-17 16:16:58 +00:00
|
|
|
# system
|
2020-04-14 22:49:22 +00:00
|
|
|
CpuPlugin(),
|
|
|
|
MemoryPlugin(),
|
2020-04-17 16:16:58 +00:00
|
|
|
DiskUsagePlugin(),
|
|
|
|
DiskIOPlugin(),
|
2020-04-14 22:49:22 +00:00
|
|
|
NetworkPlugin(),
|
|
|
|
TemperaturesPlugin(),
|
2020-04-15 20:29:29 +00:00
|
|
|
PingPlugin(),
|
|
|
|
|
|
|
|
# finance
|
2020-04-17 16:16:58 +00:00
|
|
|
StocksPlugin(),
|
2020-04-15 20:29:29 +00:00
|
|
|
RoborPlugin()
|
2020-04-14 22:49:22 +00:00
|
|
|
]
|
|
|
|
self.event = Event()
|
2020-04-17 16:16:58 +00:00
|
|
|
self.scheduler = BlockingScheduler()
|
2020-04-14 22:49:22 +00:00
|
|
|
|
|
|
|
def collect_models(self):
|
|
|
|
models = []
|
|
|
|
for plugin in self.plugins:
|
|
|
|
models.extend(plugin.models)
|
|
|
|
return models
|
|
|
|
|
2020-04-17 16:16:58 +00:00
|
|
|
def schedule_plugins(self):
|
|
|
|
for plugin in self.plugins:
|
|
|
|
self.scheduler.add_job(plugin.execute, 'interval', seconds=plugin.get_interval())
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
logging.basicConfig()
|
|
|
|
logging.getLogger('apscheduler').setLevel(logging.INFO)
|
|
|
|
|
2020-04-14 22:49:22 +00:00
|
|
|
models = self.collect_models()
|
|
|
|
database.initialize_db()
|
|
|
|
database.DB.create_tables(models)
|
|
|
|
|
2020-04-17 16:16:58 +00:00
|
|
|
self.schedule_plugins()
|
|
|
|
# signal.signal(signal.SIGHUP, self.abort)
|
|
|
|
# signal.signal(signal.SIGTERM, self.abort)
|
|
|
|
# signal.signal(signal.SIGINT, self.abort)
|
2020-04-14 22:49:22 +00:00
|
|
|
print(f'Started.')
|
|
|
|
|
2020-04-17 16:16:58 +00:00
|
|
|
try:
|
|
|
|
self.scheduler.start()
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
pass
|
2020-04-14 22:49:22 +00:00
|
|
|
|
|
|
|
print(f'Stopped.')
|
|
|
|
|
|
|
|
def abort(self, signum, frame):
|
|
|
|
print(f'Received signal {signum}, aborting...')
|
|
|
|
self.event.set()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
Collector().run()
|