Beispiel #1
0
def main():
    '''Main function for pmort.  Does all the things…sort of.

    Performs the basic loop of pmort but none of the normal daemon setup items.
    The basic logic in pmort is log all the things, sleep until the next time,
    and do it again.

    Returns
    -------

    1 if an error occurred; otherwise, it keeps running.

    '''

    error = 0

    global PARAMETERS
    PARAMETERS = PARAMETERS.parse()

    if os.access(PARAMETERS['logging.configuration_file_path'], os.R_OK):
        logging.config.fileConfig(PARAMETERS['logging.configuration_file_path'])

    # TODO Add last crash symlink.

    while True:
        for collector in COLLECTORS:
            thread = threading.Thread(
                    target = output.write_output,
                    group = 'pmort.collectors',
                    name = collector.__name__,
                    args = (collector.__name__.replace('_collector', ''), collector())
                    )
            thread.start()

        logging.info('started %s threads', len(COLLECTORS))
        logging.info('active threads: %s', threading.active_count())

        signal.alarm(LEARNERS[PARAMETERS['learner.active']].time())
        signal.pause()

    return error
Beispiel #2
0
import os
import itertools
import subprocess
import re

from pmort.parameters import PARAMETERS
from pmort.parameters import CONFIGURATION_DIRECTORY
from pmort.collectors import COLLECTORS
from pmort.output import write_output

logger = logging.getLogger(__name__)

PARAMETERS.add_parameter(
        options = [ '--directory' ],
        group = 'collector_execute',
        default = os.path.join(CONFIGURATION_DIRECTORY, 'collectors.d'),
        help = \
                'Directory in which to search for non-standard collectors.  ' \
                'Default: %(default)s'
        )

def find_scripts(directory = os.path.dirname(__file__)):
    '''Find executable scripts (with shebang) in specified directory.

    Finds the scripts that can be executed in the specified directory.  Any
    scripts that are missing a shebang or the executable bit will be skipped.

    .. note::
        All python files are excluded as it's assumed that the main collector
        loading function will load those and run them.

    Arguments
Beispiel #3
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 by Alex Brandt <*****@*****.**>
#
# pmort is freely distributable under the terms of an MIT-style license.
# See COPYING or http://www.opensource.org/licenses/mit-license.php.

import logging
import os

from pmort.collectors import COLLECTORS
from pmort.parameters import PARAMETERS

logger = logging.getLogger(__name__)


def load_average_collector():
    """Collector—Load Average"""

    return ", ".join([str(_) for _ in os.getloadavg()])


COLLECTORS["load_average"] = load_average_collector

if __name__ == "__main__":
    PARAMETERS.parse()
    print(load_average_collector())
Beispiel #4
0
import logging
import os
import sys
import itertools
import importlib

from pmort.parameters import PARAMETERS
from pmort.parameters import CONFIGURATION_DIRECTORY

logger = logging.getLogger(__name__)

PARAMETERS.add_parameter(
        options = [ '--directory', ],
        group = 'collectors',
        default = os.path.join(CONFIGURATION_DIRECTORY, 'collectors.d'),
        help = \
                'Specify another directory to read collectors from.  The ' \
                'default directory is in the pmort configuration directory. ' \
                'Default: %(default)s'
        )

COLLECTORS = {}

# TODO Clean up this module …

def load_collectors(module_basename = __name__, directory = os.path.dirname(__file__), update_path = False):
    '''Load all modules (allowing collectors to register) in directory.

    All python modules in the given directory will be imported.  Collectors
    should be registering themselves by adding themselves to the COLLECTORS
    dict provided by this module.
Beispiel #5
0
        'LEARNERS',
        ]

import logging
import os
import itertools
import importlib

from pmort.parameters import PARAMETERS

logger = logging.getLogger(__name__)

PARAMETERS.add_parameter(
        options = [ '--active', ],
        group = 'learner',
        default = 'linear', # TODO Switch to predictive.
        help = \
                'The learner algorithm to utilize for determining inter-run ' \
                'timings.  Default %(default)s'
        )

PARAMETERS.add_parameter(
        options = [ '--maximum-interval', ],
        group = 'learner',
        default = 600,
        type = int,
        help = \
                'Set the maximum time between collections by %(prog)s.  This ' \
                'specifies the maximum number of seconds between ' \
                'collections.  Default %(default)s'
        )