Python collectd.register_read() Examples

The following are 16 code examples of collectd.register_read(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module collectd , or try the search function .
Example #1
Source File: dump1090.py    From dump1090-tools with ISC License 6 votes vote down vote up
def handle_config(root):
    for child in root.children:
        instance_name = None

        if child.key == 'Instance':
            instance_name = child.values[0]
            url = None
            for ch2 in child.children:
                if ch2.key == 'URL':
                    url = ch2.values[0]
            if not url:
                collectd.warning('No URL found in dump1090 Instance ' + instance_name)
            else:
                collectd.register_read(callback=handle_read,
                                       data=(instance_name, urlparse.urlparse(url).hostname, url),
                                       name='dump1090.' + instance_name)
                collectd.register_read(callback=handle_read_1min,
                                       data=(instance_name, urlparse.urlparse(url).hostname, url),
                                       name='dump1090.' + instance_name + '.1min',
                                       interval=60)

        else:
            collectd.warning('Ignored config entry: ' + child.key) 
Example #2
Source File: dockerplugin.py    From docker-collectd-plugin with GNU General Public License v2.0 6 votes vote down vote up
def init_callback(self):
        self.client = docker.Client(
            base_url=self.docker_url,
            version=DockerPlugin.MIN_DOCKER_API_VERSION)
        self.client.timeout = self.timeout

        # Check API version for stats endpoint support.
        try:
            version = self.client.version()['ApiVersion']
            if StrictVersion(version) < \
                    StrictVersion(DockerPlugin.MIN_DOCKER_API_VERSION):
                raise Exception
        except:
            collectd.warning(('Docker daemon at {url} does not '
                              'support container statistics!')
                             .format(url=self.docker_url))
            return False

        collectd.register_read(self.read_callback)
        collectd.info(('Collecting stats about Docker containers from {url} '
                       '(API version {version}; timeout: {timeout}s).')
                      .format(url=self.docker_url,
                              version=version,
                              timeout=self.timeout))
        return True 
Example #3
Source File: collectd_rabbitmq_monitoring.py    From browbeat with Apache License 2.0 6 votes vote down vote up
def configure(configobj):
    global INTERVAL
    global cl
    global queues_to_count

    config = {c.key: c.values for c in configobj.children}
    INTERVAL = config['interval'][0]
    host = config['host'][0]
    port = int(config['port'][0])
    username = config['username'][0]
    password = config['password'][0]
    queues_to_count = []
    if 'message_count' in config:
        queues_to_count = config['message_count']
    collectd.info('rabbitmq_monitoring: Interval: {}'.format(INTERVAL))
    cl = Client('{}:{}'.format(host, port), username, password)
    collectd.info(
        'rabbitmq_monitoring: Connecting to: {}:{} as user:{} password:{}'
        .format(host, port, username, password))
    collectd.info(
        'rabbitmq_monitoring: Counting messages on: {}'
        .format(queues_to_count))
    collectd.register_read(read, INTERVAL) 
Example #4
Source File: collectd_rabbitmq_monitoring.py    From browbeat with Apache License 2.0 6 votes vote down vote up
def configure(configobj):
    global INTERVAL
    global cl
    global queues_to_count

    config = {c.key: c.values for c in configobj.children}
    INTERVAL = config['interval'][0]
    host = config['host'][0]
    port = int(config['port'][0])
    username = config['username'][0]
    password = config['password'][0]
    queues_to_count = []
    if 'message_count' in config:
        queues_to_count = config['message_count']
    collectd.info('rabbitmq_monitoring: Interval: {}'.format(INTERVAL))
    cl = Client('{}:{}'.format(host, port), username, password)
    collectd.info(
        'rabbitmq_monitoring: Connecting to: {}:{} as user:{} password:{}'
        .format(host, port, username, password))
    collectd.info(
        'rabbitmq_monitoring: Counting messages on: {}'
        .format(queues_to_count))
    collectd.register_read(read, INTERVAL) 
Example #5
Source File: dockerplugin.py    From docker-collectd-plugin with GNU General Public License v2.0 5 votes vote down vote up
def register_read(self, docker_plugin):
            pass 
Example #6
Source File: plugin.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def add_read_callback(self, callback, **kwargs):
        """Register a read callback with collectd.

        kwargs will be passed to collectd.register_read.
        The callback will be called by collectd without arguments.
        """
        collectd.register_read(callback, **kwargs) 
Example #7
Source File: plugin.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def add_write_callback(self, callback, **kwargs):
        """Register a write callback with collectd.

        kwargs will be passed to collectd.register_read.
        The callback will be called by collectd with a collectd.
        Values object as the only argument.
        """

        collectd.register_write(callback) 
Example #8
Source File: collectd_ovsagent.py    From browbeat with Apache License 2.0 5 votes vote down vote up
def configure(cfg):
    global INTERVAL
    global interfaces
    global namespaces
    interfaces = []
    namespaces = []
    config = {c.key: c.values for c in cfg.children}
    INTERVAL = config['interval'][0]
    collectd.register_read(read, INTERVAL)
    if 'interfaces' in config:
        interfaces = config['interfaces']
    if 'namespaces' in config :
        namespaces = config['namespaces'] 
Example #9
Source File: collectd_ovsagent.py    From browbeat with Apache License 2.0 5 votes vote down vote up
def configure(cfg):
    global INTERVAL
    global interfaces
    global namespaces
    interfaces = []
    namespaces = []
    config = {c.key: c.values for c in cfg.children}
    INTERVAL = config['interval'][0]
    collectd.register_read(read, INTERVAL)
    if 'interfaces' in config:
        interfaces = config['interfaces']
    if 'namespaces' in config :
        namespaces = config['namespaces'] 
Example #10
Source File: collectd_swift_stat.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, configobj):
        for node in configobj.children:
            val = str(node.values[0])
            if node.key == 'Interval':
                self.interval = int(float(val))
            elif node.key == 'Prefix':
                self.prefix = val
            elif node.key == 'User':
                self.user = val
            elif node.key == 'Password':
                self.password = val
            elif node.key == 'AuthURL':
                self.authurl = val
            elif node.key == 'AuthVersion':
                self.authversion = val
            elif node.key == 'Project':
                self.project = val
            else:
                collectd.warning(
                    'collectd-swift-stat: Unknown config key: {}'
                    .format(node.key))

        read_plugin = True
        if not self.prefix:
            collectd.error('collectd-swift-stat: Prefix Undefined')
            read_plugin = False
        if not self.user:
            collectd.error('collectd-swift-stat: User Undefined')
            read_plugin = False
        if not self.password:
            collectd.error('collectd-swift-stat: Password Undefined')
            read_plugin = False
        if not self.authurl:
            collectd.error('collectd-swift-stat: AuthURL Undefined')
            read_plugin = False
        if not self.authversion:
            collectd.error('collectd-swift-stat: AuthVersion Undefined')
            read_plugin = False
        if not self.project:
            collectd.error('collectd-swift-stat: Project Undefined')
            read_plugin = False

        if read_plugin:
            collectd.info(
                'swift_stat: Connecting with user={}, password={}, tenant={}, auth_url={},'
                ' auth_version={}'.format(
                    self.user, self.password, self.project, self.authurl, self.authversion))

            self.swift_conn = self.create_swift_session()
            collectd.register_read(self.read_swift_stat, self.interval)
        else:
            collectd.error('collectd_swift_stat: Invalid configuration') 
Example #11
Source File: collectd_iostat_python.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, conf):
        """
        Receive configuration block
        """
        for node in conf.children:
            val = str(node.values[0])

            if node.key == 'Path':
                self.iostat_path = val
            elif node.key == 'Interval':
                self.interval = float(val)
            elif node.key == 'IostatInterval':
                self.iostat_interval = int(float(val))
            elif node.key == 'Count':
                self.iostat_count = int(float(val))
            elif node.key == 'Disks':
                self.iostat_disks = val.split(',')
            elif node.key == 'NiceNames':
                self.iostat_nice_names = val in ['True', 'true']
            elif node.key == 'DisksRegex':
                self.iostat_disks_regex = val
            elif node.key == 'UdevNameAttr':
                self.iostat_udevnameattr = val
            elif node.key == 'PluginName':
                self.plugin_name = val
            elif node.key == 'Verbose':
                self.verbose_logging = val in ['True', 'true']
            elif node.key == 'SkipPhysicalMultipath':
                self.skip_multipath = val in [ 'True', 'true' ]
            elif node.key == 'NoDisplayDMName':
                self.iostat_no_dm_name = val in [ 'True', 'true' ]
            else:
                collectd.warning(
                    '%s plugin: Unknown config key: %s.' % (
                        self.plugin_name,
                        node.key))

        self.log_verbose(
            'Configured with iostat=%s, interval=%s, count=%s, disks=%s, '
            'disks_regex=%s udevnameattr=%s skip_multipath=%s no_dm_name=%s' % (
                self.iostat_path,
                self.iostat_interval,
                self.iostat_count,
                self.iostat_disks,
                self.iostat_disks_regex,
                self.iostat_udevnameattr,
                self.skip_multipath,
                self.iostat_no_dm_name))

        collectd.register_read(self.read_callback, self.interval) 
Example #12
Source File: collectd_ceph_storage.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, config):
        for node in config.children:
            val = str(node.values[0])
            if node.key == 'CephRadosBench':
                self.ceph_rados_bench = val in ['True', 'true']
            elif node.key == 'CephMONStats':
                self.ceph_mon_stats = val in ['True', 'true']
            elif node.key == 'CephOSDStats':
                self.ceph_osd_stats = val in ['True', 'true']
            elif node.key == 'CephPGStats':
                self.ceph_pg_stats = val in ['True', 'true']
            elif node.key == 'CephPoolStats':
                self.ceph_pool_stats = val in ['True', 'true']
            elif node.key == 'CephCluster':
                self.ceph_cluster = val
            elif node.key == 'CephRadosBenchInterval':
                self.ceph_rados_bench_interval = int(float(val))
            elif node.key == 'CephMONStatsInterval':
                self.ceph_mon_stats_interval = int(float(val))
            elif node.key == 'CephOSDStatsInterval':
                self.ceph_osd_stats_interval = int(float(val))
            elif node.key == 'CephPGStatsInterval':
                self.ceph_pg_stats_interval = int(float(val))
            elif node.key == 'CephPoolStatsInterval':
                self.ceph_pool_stats_interval = int(float(val))
            else:
                collectd.warning(
                    'collectd-ceph-storage: Unknown config key: {}'
                    .format(node.key))

        if not self.ceph_cluster:
            collectd.warning('collectd-ceph-storage: CephCluster Undefined')

        if self.ceph_rados_bench:
            collectd.info('Registered Ceph Rados Bench')
            collectd.register_read(
                self.read_ceph_rados_bench,
                self.ceph_rados_bench_interval, name='ceph-rados-bench')
        if self.ceph_mon_stats:
            collectd.info('Registered Ceph Mon')
            collectd.register_read(
                self.read_ceph_mon, self.ceph_mon_stats_interval,
                name='ceph-monitor')
        if self.ceph_osd_stats:
            collectd.info('Registered Ceph OSD')
            collectd.register_read(
                self.read_ceph_osd, self.ceph_osd_stats_interval,
                name='ceph-osd')
        if self.ceph_pg_stats:
            collectd.info('Registered Ceph PG')
            collectd.register_read(
                self.read_ceph_pg, self.ceph_pg_stats_interval, name='ceph-pg')
        if self.ceph_pool_stats:
            collectd.info('Registered Ceph Pool')
            collectd.register_read(
                self.read_ceph_pool, self.ceph_pool_stats_interval,
                name='ceph-pool') 
Example #13
Source File: collectd_swift_stat.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, configobj):
        for node in configobj.children:
            val = str(node.values[0])
            if node.key == 'Interval':
                self.interval = int(float(val))
            elif node.key == 'Prefix':
                self.prefix = val
            elif node.key == 'User':
                self.user = val
            elif node.key == 'Password':
                self.password = val
            elif node.key == 'AuthURL':
                self.authurl = val
            elif node.key == 'AuthVersion':
                self.authversion = val
            elif node.key == 'Project':
                self.project = val
            else:
                collectd.warning(
                    'collectd-swift-stat: Unknown config key: {}'
                    .format(node.key))

        read_plugin = True
        if not self.prefix:
            collectd.error('collectd-swift-stat: Prefix Undefined')
            read_plugin = False
        if not self.user:
            collectd.error('collectd-swift-stat: User Undefined')
            read_plugin = False
        if not self.password:
            collectd.error('collectd-swift-stat: Password Undefined')
            read_plugin = False
        if not self.authurl:
            collectd.error('collectd-swift-stat: AuthURL Undefined')
            read_plugin = False
        if not self.authversion:
            collectd.error('collectd-swift-stat: AuthVersion Undefined')
            read_plugin = False
        if not self.project:
            collectd.error('collectd-swift-stat: Project Undefined')
            read_plugin = False

        if read_plugin:
            collectd.info(
                'swift_stat: Connecting with user={}, password={}, tenant={}, auth_url={},'
                ' auth_version={}'.format(
                    self.user, self.password, self.project, self.authurl, self.authversion))

            self.swift_conn = self.create_swift_session()
            collectd.register_read(self.read_swift_stat, self.interval)
        else:
            collectd.error('collectd_swift_stat: Invalid configuration') 
Example #14
Source File: collectd_iostat_python.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, conf):
        """
        Receive configuration block
        """
        for node in conf.children:
            val = str(node.values[0])

            if node.key == 'Path':
                self.iostat_path = val
            elif node.key == 'Interval':
                self.interval = float(val)
            elif node.key == 'IostatInterval':
                self.iostat_interval = int(float(val))
            elif node.key == 'Count':
                self.iostat_count = int(float(val))
            elif node.key == 'Disks':
                self.iostat_disks = val.split(',')
            elif node.key == 'NiceNames':
                self.iostat_nice_names = val in ['True', 'true']
            elif node.key == 'DisksRegex':
                self.iostat_disks_regex = val
            elif node.key == 'UdevNameAttr':
                self.iostat_udevnameattr = val
            elif node.key == 'PluginName':
                self.plugin_name = val
            elif node.key == 'Verbose':
                self.verbose_logging = val in ['True', 'true']
            elif node.key == 'SkipPhysicalMultipath':
                self.skip_multipath = val in [ 'True', 'true' ]
            elif node.key == 'NoDisplayDMName':
                self.iostat_no_dm_name = val in [ 'True', 'true' ]
            else:
                collectd.warning(
                    '%s plugin: Unknown config key: %s.' % (
                        self.plugin_name,
                        node.key))

        self.log_verbose(
            'Configured with iostat=%s, interval=%s, count=%s, disks=%s, '
            'disks_regex=%s udevnameattr=%s skip_multipath=%s no_dm_name=%s' % (
                self.iostat_path,
                self.iostat_interval,
                self.iostat_count,
                self.iostat_disks,
                self.iostat_disks_regex,
                self.iostat_udevnameattr,
                self.skip_multipath,
                self.iostat_no_dm_name))

        collectd.register_read(self.read_callback, self.interval) 
Example #15
Source File: collectd_ceph_storage.py    From browbeat with Apache License 2.0 4 votes vote down vote up
def configure_callback(self, config):
        for node in config.children:
            val = str(node.values[0])
            if node.key == 'CephRadosBench':
                self.ceph_rados_bench = val in ['True', 'true']
            elif node.key == 'CephMONStats':
                self.ceph_mon_stats = val in ['True', 'true']
            elif node.key == 'CephOSDStats':
                self.ceph_osd_stats = val in ['True', 'true']
            elif node.key == 'CephPGStats':
                self.ceph_pg_stats = val in ['True', 'true']
            elif node.key == 'CephPoolStats':
                self.ceph_pool_stats = val in ['True', 'true']
            elif node.key == 'CephCluster':
                self.ceph_cluster = val
            elif node.key == 'CephRadosBenchInterval':
                self.ceph_rados_bench_interval = int(float(val))
            elif node.key == 'CephMONStatsInterval':
                self.ceph_mon_stats_interval = int(float(val))
            elif node.key == 'CephOSDStatsInterval':
                self.ceph_osd_stats_interval = int(float(val))
            elif node.key == 'CephPGStatsInterval':
                self.ceph_pg_stats_interval = int(float(val))
            elif node.key == 'CephPoolStatsInterval':
                self.ceph_pool_stats_interval = int(float(val))
            else:
                collectd.warning(
                    'collectd-ceph-storage: Unknown config key: {}'
                    .format(node.key))

        if not self.ceph_cluster:
            collectd.warning('collectd-ceph-storage: CephCluster Undefined')

        if self.ceph_rados_bench:
            collectd.info('Registered Ceph Rados Bench')
            collectd.register_read(
                self.read_ceph_rados_bench,
                self.ceph_rados_bench_interval, name='ceph-rados-bench')
        if self.ceph_mon_stats:
            collectd.info('Registered Ceph Mon')
            collectd.register_read(
                self.read_ceph_mon, self.ceph_mon_stats_interval,
                name='ceph-monitor')
        if self.ceph_osd_stats:
            collectd.info('Registered Ceph OSD')
            collectd.register_read(
                self.read_ceph_osd, self.ceph_osd_stats_interval,
                name='ceph-osd')
        if self.ceph_pg_stats:
            collectd.info('Registered Ceph PG')
            collectd.register_read(
                self.read_ceph_pg, self.ceph_pg_stats_interval, name='ceph-pg')
        if self.ceph_pool_stats:
            collectd.info('Registered Ceph Pool')
            collectd.register_read(
                self.read_ceph_pool, self.ceph_pool_stats_interval,
                name='ceph-pool') 
Example #16
Source File: collectd_iostat_python.py    From collectd-iostat-python with MIT License 4 votes vote down vote up
def configure_callback(self, conf):
        """
        Receive configuration block
        """
        for node in conf.children:
            val = str(node.values[0])

            if node.key == 'Path':
                self.iostat_path = val
            elif node.key == 'Interval':
                self.interval = float(val)
            elif node.key == 'IostatInterval':
                self.iostat_interval = int(float(val))
            elif node.key == 'Count':
                self.iostat_count = int(float(val))
            elif node.key == 'Disks':
                self.iostat_disks = val.split(',')
            elif node.key == 'NiceNames':
                self.iostat_nice_names = val in ['True', 'true']
            elif node.key == 'DisksRegex':
                self.iostat_disks_regex = val
            elif node.key == 'UdevNameAttr':
                self.iostat_udevnameattr = val
            elif node.key == 'PluginName':
                self.plugin_name = val
            elif node.key == 'Verbose':
                self.verbose_logging = val in ['True', 'true']
            elif node.key == 'SkipPhysicalMultipath':
                self.skip_multipath = val in [ 'True', 'true' ]
            elif node.key == 'NoDisplayDMName':
                self.iostat_no_dm_name = val in [ 'True', 'true' ]
            else:
                collectd.warning(
                    '%s plugin: Unknown config key: %s.' % (
                        self.plugin_name,
                        node.key))

        self.log_verbose(
            'Configured with iostat=%s, interval=%s, count=%s, disks=%s, '
            'disks_regex=%s udevnameattr=%s skip_multipath=%s no_dm_name=%s' % (
                self.iostat_path,
                self.iostat_interval,
                self.iostat_count,
                self.iostat_disks,
                self.iostat_disks_regex,
                self.iostat_udevnameattr,
                self.skip_multipath,
                self.iostat_no_dm_name))

        collectd.register_read(self.read_callback, self.interval)