diff --git a/bin/linspector b/bin/linspector index 452f42f..8988ea4 100755 --- a/bin/linspector +++ b/bin/linspector @@ -1,6 +1,7 @@ #!/usr/bin/python2.7 -tt """ +Copyright (c) 2014-2015 by Johannes Findeisen Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). @@ -20,9 +21,10 @@ along with this program. If not, see . """ -__version__ = "0.15.1/AMNESIA" +__version__ = "0.16/AMNESIA" import argparse +import copy import datetime import logging import logging.handlers @@ -33,10 +35,14 @@ import sys from linspector.config.parser import FullConfigParser from linspector.core.interface import LinspectorInterface from linspector.core.job import LinspectorJob -from linspector.core.scheduler import LinspectorScheduler +#from linspector.core.scheduler import LinspectorScheduler from linspector.frontends.lish import LishFrontend from linspector.tasks.task import TaskExecutor +from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.jobstores.memory import MemoryJobStore +from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor + logger = logging.getLogger(__name__) @@ -67,8 +73,8 @@ def parse_args(): parser.add_argument("-t", "--threads", default=3500, type=int, help="maximum number of scheduler threads (default: 3500)") - parser.add_argument("-k", "--corethreads", default=0, type=int, - help="number of scheduler core threads (default: 0)") + parser.add_argument("-p", "--processes", default=0, type=int, + help="number of scheduler processes (default: 0)") parser.add_argument("-x", "--delay", default=1.135791, type=float, help="seconds delay between scheduled jobs (default: 1.135791)") @@ -115,9 +121,18 @@ def main(): print("Configuration error: " + str(msg) + ". Exiting now.") logger.error(msg) exit() - - scheduler = LinspectorScheduler({"apscheduler.threadpool.core_threads": args.corethreads, - "apscheduler.threadpool.max_threads": args.threads}) + + jobstores = { + 'memory': MemoryJobStore() + } + executors = { + 'default': ThreadPoolExecutor(args.threads), + 'processpool': ProcessPoolExecutor(args.processes) + } + job_defaults = { + 'max_instances': 10000 + } + scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults) TaskExecutor.Instance() @@ -193,4 +208,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/examples/stress.json b/examples/stress.json index e01443c..0629d96 100644 --- a/examples/stress.json +++ b/examples/stress.json @@ -12,7 +12,7 @@ } }, "periods": { - "fast": { "seconds": 60 }, + "fast": { "seconds": 15 }, "medium": { "seconds": 120 }, "slow": { "seconds": 480 } }, diff --git a/linspector/config/periods.py b/linspector/config/periods.py index 80fd8c8..95b1b4f 100644 --- a/linspector/config/periods.py +++ b/linspector/config/periods.py @@ -52,8 +52,8 @@ class IntervalPeriod(Period): if "start_date" in kwargs: start_date = kwargs["start_date"] - return scheduler.add_interval_job(func, weeks=self.weeks, hours=self.hours, minutes=self.minutes, - seconds=self.seconds, start_date=start_date, args=[jobInfo]) + return scheduler.add_job(func, trigger="interval", weeks=self.weeks, hours=self.hours, minutes=self.minutes, + seconds=self.seconds, start_date=start_date, args=[jobInfo], timezone="CET") def __str__(self): ret = "IntervalPeriod(Name: " + self.name + ")" @@ -85,7 +85,7 @@ class CronPeriod(Period): if "start_date" in kwargs: start_date = kwargs["start_date"] - return scheduler.add_cron_job(func, year=self.year, month=self.month, day=self.day, week=self.week, + return scheduler.add_job(func, trigger="cron", year=self.year, month=self.month, day=self.day, week=self.week, day_of_week=self.day_of_week, hour=self.hour, minute=self.minute, second=self.second, start_date=start_date, args=[jobInfo]) @@ -108,6 +108,6 @@ class DatePeriod(Period): if date < earliest: self.date = earliest - return scheduler.add_date_job(func=func, date=self.date, args=[jobInfo]) + return scheduler.add_job(func=func, trigger="date", date=self.date, args=[jobInfo]) except Exception, e: - logger.error("exception while creating job out of DatePeriod!\n%s" % e) \ No newline at end of file + logger.error("exception while creating job out of DatePeriod!\n%s" % e) diff --git a/linspector/core/interface.py b/linspector/core/interface.py index c30972d..b34153c 100644 --- a/linspector/core/interface.py +++ b/linspector/core/interface.py @@ -63,7 +63,7 @@ class LinspectorInterface(object): d["Members"] = str([member.name for member in job.members]) d["Period"] = str(job.scheduler_job.trigger) d["Next run"] = str(job.scheduler_job.next_run_time) - d["Runs"] = str(job.scheduler_job.runs) + d["Runs"] = str(job.job_information.job_overall_fails) d["Enabled"] = str(job.enabled) d["Threshold"] = str(job.service.get_threshold()) d["Fails"] = str(job.job_threshold) diff --git a/linspector/core/job.py b/linspector/core/job.py index c0168b2..b6aa1ff 100644 --- a/linspector/core/job.py +++ b/linspector/core/job.py @@ -49,6 +49,7 @@ class LinspectorJob: self.enabled = True self.scheduler_job = None self.job_id = self.hex_string() + """ NONE job was not executed OK when everything is fine diff --git a/linspector/core/scheduler.py b/linspector/core/scheduler.py index aee9501..ceb6439 100644 --- a/linspector/core/scheduler.py +++ b/linspector/core/scheduler.py @@ -1,4 +1,5 @@ """ +Copyright (c) 2014 by Johannes Findeisen Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). @@ -19,11 +20,12 @@ along with this program. If not, see . from logging import getLogger -from apscheduler.scheduler import Scheduler +from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor logger = getLogger(__name__) class LinspectorScheduler(Scheduler): def test(self): - pass \ No newline at end of file + pass diff --git a/linspector/frontends/lish.py b/linspector/frontends/lish.py index 644f69f..fea755c 100644 --- a/linspector/frontends/lish.py +++ b/linspector/frontends/lish.py @@ -220,7 +220,6 @@ class NewLish(CmdWrapper): count to get a job count''') - class Job(CmdWrapper): def __init__(self, interface): @@ -478,8 +477,8 @@ Usage: print GREEN + "Hostname" + END + ":\t" + socket.gethostname() # TODO: print instance uptime print GREEN + "Job Count" + END + ":\t" + str(self.interface.get_job_count()) - thread_info = self.interface.get_thread_count() - print GREEN + "Threads" + END + ":\t" + str(thread_info["Num Threads"]) + "/" + str(thread_info["Max Threads"]) + ###thread_info = self.interface.get_thread_count() + ###print GREEN + "Threads" + END + ":\t" + str(thread_info["Num Threads"]) + "/" + str(thread_info["Max Threads"]) print GREEN + "Core Version" + END + ":\t" + self.interface.get_version() print GREEN + "Lish Version" + END + ":\t" + __version__ @@ -489,13 +488,12 @@ Show status information about the Linspector instance ''') def do_about(self, text): - self.print_color(GREEN, "Linspector Monitoring\n") + self.print_color(GREEN, "Linspector System Monitoring\n") self.print_color(YELLOW, "Developers:") self.print_color(BLUE, " - Johannes Findeisen ") - self.print_color(BLUE, " - Rafael Timmerberg \n") - self.print_color(PURPLE, "(c) 2011 - 2013") + self.print_color(PURPLE, "(c) 2011 - 2015") self.print_color(PURPLE, "Web: http://linspector.org") - self.print_color(PURPLE, "License: GNU Affero General Public License Version 3.0") + self.print_color(PURPLE, "License: GNU General Public License Version 2") def help_about(self): print(''' diff --git a/linspector/services/etc/dummy.py b/linspector/services/etc/dummy.py index 4d32c05..a94d8d9 100644 --- a/linspector/services/etc/dummy.py +++ b/linspector/services/etc/dummy.py @@ -66,7 +66,7 @@ class DummyService(Service): return False def execute(self, execution): - + #print(str(self.sleep)) time.sleep(self.sleep) d = {"Fail": str(self.fail), "Sleep": str(self.sleep)}