Ejemplo n.º 1
0
class DashboardPlugin(object):
    PG_MIN_VERSION = 90400
    s = 'dashboard'
    option_specs = [
        OptionSpec(s, 'scheduler_interval', default=2, validator=int),
        OptionSpec(s, 'history_length', default=150, validator=int),
    ]
    del s

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

    def load(self):
        pg_version = self.app.postgres.fetch_version()
        if pg_version < self.PG_MIN_VERSION:
            msg = "%s is incompatible with Postgres below 9.4" % (
                self.__class__.__name__)
            raise UserError(msg)

        self.app.router.add(routes)
        self.app.worker_pool.add(workers)
        workers.schedule(
            id='dashboard_collector',
            redo_interval=self.app.config.dashboard.scheduler_interval)(
                dashboard_collector_worker)
        self.app.scheduler.add(workers)

    def unload(self):
        self.app.scheduler.remove(workers)
        self.app.worker_pool.remove(workers)
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 2
0
class MonitoringPlugin(object):
    PG_MIN_VERSION = (90400, 9.4)
    s = 'monitoring'
    option_specs = [
        OptionSpec(s, 'dbnames', default='*', validator=commalist),
        OptionSpec(s, 'scheduler_interval', default=60, validator=int),
        OptionSpec(s, 'probes', default='*', validator=commalist),
    ]
    del s

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

    def bootstrap(self):
        db.bootstrap(self.app.config.temboard.home, 'monitoring.db')

    def load(self):
        self.app.router.add(routes)
        self.app.worker_pool.add(workers)
        workers.schedule(
            id='monitoring_collector',
            redo_interval=self.app.config.monitoring.scheduler_interval,
        )(monitoring_collector_worker)
        self.app.scheduler.add(workers)

    def unload(self):
        self.app.scheduler.remove(workers)
        self.app.worker_pool.remove(workers)
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 3
0
class Hello(object):
    pg_min_version = 90400
    my_options_specs = [
        OptionSpec('hello', 'name', default='World'),
        OptionSpec(
            'hello', 'background_worker_interval', default=10, validator=int),
    ]

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.my_options_specs)

    def load(self):
        pg_version = self.app.postgres.fetch_version()
        if pg_version < self.pg_min_version:
            raise UserError("hellong is incompatible with Postgres below 9.4")

        self.app.router.add(routes)
        self.app.worker_pool.add(workers)
        self.app.scheduler.add(workers)

    def unload(self):
        self.app.scheduler.remove(workers)
        self.app.worker_pool.remove(workers)
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.my_options_specs)
        logger.info("Good by from hellong!")
Ejemplo n.º 4
0
class DashboardPlugin(object):
    PG_MIN_VERSION = (90400, 9.4)
    s = 'dashboard'
    option_specs = [
        OptionSpec(s, 'scheduler_interval', default=2, validator=int),
        OptionSpec(s, 'history_length', default=150, validator=int),
    ]
    del s

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

    def bootstrap(self):
        db.bootstrap(self.app.config.temboard.home, 'dashboard.db')

    def load(self):
        self.app.router.add(routes)
        self.app.worker_pool.add(workers)
        workers.schedule(
            id='dashboard_collector',
            redo_interval=self.app.config.dashboard.scheduler_interval)(
                dashboard_collector_worker)
        self.app.scheduler.add(workers)

    def unload(self):
        self.app.scheduler.remove(workers)
        self.app.worker_pool.remove(workers)
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 5
0
class BackupPlugin(object):
    s = 'backup'
    option_specs = [
        OptionSpec(s,
                   'tool',
                   default='pgbackrest',
                   validator=functions.check_tool),
        OptionSpec(s, 'path', default=None, validator=file_),
        OptionSpec(s, 'configfile', default=None, validator=file_),
        OptionSpec(s, 'stanza', default=None)
    ]

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

        # Use the same logging level as the whole agent
        logger.setLevel(self.app.config.logging.level)

    def load(self):
        if self.app.config.backup.tool == 'pitrery':
            if self.app.config.backup.path is None:
                self.app.config.backup.path = 'pitrery'
        else:
            if self.app.config.backup.path is None:
                self.app.config.backup.path = 'pgbackrest'

        self.app.router.add(routes)
        for route in routes:
            logger.debug(route)

    def unload(self):
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 6
0
class MonitoringPlugin(object):
    PG_MIN_VERSION = 90400
    s = 'monitoring'
    option_specs = [
        OptionSpec(s, 'dbnames', default='*', validator=commalist),
        OptionSpec(s, 'scheduler_interval', default=60, validator=int),
        OptionSpec(s, 'probes', default='*', validator=commalist),
        OptionSpec(s, 'collector_url', default=OptionSpec.REQUIRED),
        OptionSpec(s, 'ssl_ca_cert_file', default=None, validator=file_),
    ]
    del s

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

    def load(self):
        pg_version = self.app.postgres.fetch_version()
        if pg_version < self.PG_MIN_VERSION:
            msg = "%s is incompatible with Postgres below 9.4" % (
                self.__class__.__name__)
            raise UserError(msg)

        self.app.router.add(routes)
        self.app.worker_pool.add(workers)
        workers.schedule(
            id='monitoring_collector',
            redo_interval=self.app.config.monitoring.scheduler_interval,
        )(monitoring_collector_worker)
        workers.schedule(
            id='monitoring_sender',
            redo_interval=self.app.config.monitoring.scheduler_interval,
        )(monitoring_sender_worker)
        self.app.scheduler.add(workers)

    def unload(self):
        self.app.scheduler.remove(workers)
        self.app.worker_pool.remove(workers)
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 7
0
class StatementsPlugin(object):
    PG_MIN_VERSION = (90500, 9.5)
    s = "statements"
    option_specs = [OptionSpec(s, "dbname", default="postgres")]
    del s

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.option_specs)

    def load(self):
        self.app.router.add(routes)

    def unload(self):
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.option_specs)
Ejemplo n.º 8
0
class AdministrationPlugin:
    PG_MIN_VERSION = (90400, 9.4)
    options_specs = [
        OptionSpec('administration', 'pg_ctl', default=None, validator=quoted),
    ]

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.options_specs)

    def load(self):
        self.app.router.add(routes)

    def unload(self):
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.options_specs)
Ejemplo n.º 9
0
class AdministrationPlugin(object):
    PG_MIN_VERSION = 90400
    options_specs = [
        OptionSpec('administration', 'pg_ctl', default=None, validator=quoted),
    ]

    def __init__(self, app, **kw):
        self.app = app
        self.app.config.add_specs(self.options_specs)

    def load(self):
        pg_version = self.app.postgres.fetch_version()
        if pg_version < self.PG_MIN_VERSION:
            msg = "%s is incompatible with Postgres below 9.4" % (
                self.__class__.__name__)
            raise UserError(msg)

        self.app.router.add(routes)

    def unload(self):
        self.app.router.remove(routes)
        self.app.config.remove_specs(self.options_specs)