當前位置: 首頁>>代碼示例>>Python>>正文


Python collectd.Values方法代碼示例

本文整理匯總了Python中collectd.Values方法的典型用法代碼示例。如果您正苦於以下問題:Python collectd.Values方法的具體用法?Python collectd.Values怎麽用?Python collectd.Values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collectd的用法示例。


在下文中一共展示了collectd.Values方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read(self):
        try:
            params = {"filters": '{"name": ["rebellion.service"]}'}
            containers = requests.get(
                "{}/containers/json".format(self.DOCKER_URL_PREFIX),
                params=params,
                timeout=self.TIMEOUT).json()
            metric = collectd.Values()
            metric.plugin = self.NAME
            metric.plugin_instance = "rebellion_service"
            metric.type = "val"
            metric.values = [len(containers)]
            metric.dispatch()
        except Exception as e:
            collectd.error(
                "rebellion_monitor.read() failed, exception: {}".format(e)) 
開發者ID:laincloud,項目名稱:lain,代碼行數:18,代碼來源:rebellion_monitor.py

示例2: read_docker_reserved_cpu_cores

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read_docker_reserved_cpu_cores(self, container_ids):
        '''
        Unit: CPU Cores
        '''
        docker_reserved_cpu_cores = 0
        for container_id in container_ids:
            inspect_info = self.__get("/containers/{}/json".format(
                container_id))
            docker_reserved_cpu_cores += self.__calculate_docker_reserved_cpu_cores(
                inspect_info)

        metric = collectd.Values()
        metric.plugin = self.NAME
        metric.plugin_instance = "docker_reserved_cpu_cores"
        metric.type = "val"
        metric.values = [docker_reserved_cpu_cores]
        metric.dispatch() 
開發者ID:laincloud,項目名稱:lain,代碼行數:19,代碼來源:node_monitor.py

示例3: read_docker_used_cpu_cores

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read_docker_used_cpu_cores(self, container_ids):
        '''
        Unit: CPU Cores
        '''
        docekr_used_cpu_cores = 0
        for container_id in container_ids:
            stats = self.__get("/containers/{}/stats?stream=false".format(
                container_id))
            docekr_used_cpu_cores += self.__calculate_docker_used_cpu_cores(
                stats)
        metric = collectd.Values()
        metric.plugin = self.NAME
        metric.plugin_instance = "docker_used_cpu_cores"
        metric.type = "val"
        metric.values = [docekr_used_cpu_cores]
        metric.dispatch() 
開發者ID:laincloud,項目名稱:lain,代碼行數:18,代碼來源:node_monitor.py

示例4: emit

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def emit(cls, container, type, value, t=None, type_instance=None):
        val = collectd.Values()
        val.plugin = 'docker'
        val.plugin_instance = container['Name']

        if type:
            val.type = type
        if type_instance:
            val.type_instance = type_instance

        if t:
            val.time = calendar.timegm(dateutil.parser.parse(t).utctimetuple())
        else:
            val.time = time.time()

        # With some versions of CollectD, a dummy metadata map must to be added
        # to each value for it to be correctly serialized to JSON by the
        # write_http plugin. See
        # https://github.com/collectd/collectd/issues/716
        val.meta = {'true': 'true'}

        val.values = value
        val.dispatch() 
開發者ID:lebauce,項目名稱:docker-collectd-plugin,代碼行數:25,代碼來源:dockerplugin.py

示例5: read_callback

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read_callback():
    """Get stats for all the servers in the cluster."""
    stats = {}
    for conf in CONFIGS:
        for host in conf["hosts"]:
            zk = ZooKeeperServer(host, conf["port"])
            stats = zk.get_stats()
            zk_version = stats["zk_version"].split(",")[0]
            del stats["zk_version"]
            for k, v in list(stats.items()):
                try:
                    val = collectd.Values(plugin="zookeeper", meta={"0": True})
                    val.type = "counter" if k in COUNTERS else "gauge"
                    val.type_instance = k
                    val.values = [v]
                    val.plugin_instance = "%s[zk_version=%s]" % (conf["instance"], zk_version)
                    val.dispatch()
                except (TypeError, ValueError):
                    log(("error dispatching stat; host=%s, " "key=%s, val=%s") % (host, k, v))
                    pass

    return stats 
開發者ID:signalfx,項目名稱:collectd-zookeeper,代碼行數:24,代碼來源:zk-collectd.py

示例6: dispatch_value

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def dispatch_value(prefix, key, value, type, type_instance=None):
	if not type_instance:
		type_instance = key

	log_verbose('Sending value: %s/%s=%s' % (prefix, type_instance, value))
	if value is None:
		return
	try:
		value = int(value)
	except ValueError:
		value = float(value)

	if COLLECTD_ENABLED:
		val               = collectd.Values(plugin='mysql', plugin_instance=prefix)
		val.type          = type
		val.type_instance = type_instance
		val.values        = [value]
		val.dispatch() 
開發者ID:chrisboulton,項目名稱:collectd-python-mysql,代碼行數:20,代碼來源:mysql.py

示例7: read_swift_stat

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read_swift_stat(self, data=None):
        starttime = time.time()

        stats = self.swift_conn.head_account()

        for m_instance, name in CollectdSwiftStat.SWIFT_STATS.iteritems():
            if m_instance in stats:
                metric = collectd.Values()
                metric.plugin = 'swift_stat'
                metric.interval = self.interval
                metric.type = 'gauge'
                metric.type_instance = '{}-{}'.format(self.prefix, name)
                metric.values = [stats[m_instance]]
                metric.dispatch()
            else:
                collectd.error(
                    'swift_stat: Can not find: {}'.format(m_instance))

        timediff = time.time() - starttime
        if timediff > self.interval:
            collectd.warning(
                'swift_stat: Took: {} > {}'
                .format(round(timediff, 2), self.interval)) 
開發者ID:cloud-bulldozer,項目名稱:browbeat,代碼行數:25,代碼來源:collectd_swift_stat.py

示例8: dispatch_value

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def dispatch_value(self, plugin_instance, val_type, type_instance, value):
        """
        Dispatch a value to collectd
        """
        self.log_verbose(
            'Sending value: %s-%s.%s=%s' % (
                self.plugin_name,
                plugin_instance,
                '-'.join([val_type, type_instance]),
                value))

        val = collectd.Values()
        val.plugin = self.plugin_name
        val.plugin_instance = plugin_instance
        val.type = val_type
        if len(type_instance):
            val.type_instance = type_instance
        val.values = [value, ]
        val.meta={'0': True}
        val.dispatch() 
開發者ID:cloud-bulldozer,項目名稱:browbeat,代碼行數:22,代碼來源:collectd_iostat_python.py

示例9: dispatch_value

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def dispatch_value(self, plugin, plugin_instance, type, type_instance, value):
        """Looks for the given stat in stats, and dispatches it"""
        self.logdebug("dispatching value %s.%s.%s.%s=%s"
                % (plugin, plugin_instance, type, type_instance, value))

        val = collectd.Values(type='gauge')
        val.plugin=plugin
        val.plugin_instance=plugin_instance
        if type_instance is not None:
            val.type_instance="%s-%s" % (type, type_instance)
        else:
            val.type_instance=type
        val.values=[value]
        val.interval = self.interval
        val.dispatch()
        self.logdebug("sent metric %s.%s.%s.%s.%s"
                % (plugin, plugin_instance, type, type_instance, value)) 
開發者ID:rochaporto,項目名稱:collectd-openstack,代碼行數:19,代碼來源:base.py

示例10: dispatch_stat

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def dispatch_stat(result, name, key, conf):
    """Read a key from info response data and dispatch a value"""
    if result is None:
        collectd.warning('mesos-master plugin: Value not found for %s' % name)
        return
    estype = key.type
    value = result
    log_verbose(conf['verboseLogging'], 'Sending value[%s]: %s=%s for instance:%s' % (estype, name, value, conf['instance']))

    val = collectd.Values(plugin='mesos-master')
    val.type = estype
    val.type_instance = name
    val.values = [value]
    val.plugin_instance = conf['instance']
    # https://github.com/collectd/collectd/issues/716
    val.meta = {'0': True}
    val.dispatch() 
開發者ID:mantl,項目名稱:mantl,代碼行數:19,代碼來源:mesos-master.py

示例11: dispatch_stat

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def dispatch_stat(result, name, key, conf):
    """Read a key from info response data and dispatch a value"""
    if result is None:
        collectd.warning('mesos-slave plugin: Value not found for %s' % name)
        return
    estype = key.type
    value = result
    log_verbose(conf['verboseLogging'], 'Sending value[%s]: %s=%s for instance:%s' % (estype, name, value, conf['instance']))

    val = collectd.Values(plugin='mesos-slave')
    val.type = estype
    val.type_instance = name
    val.values = [value]
    val.plugin_instance = conf['instance']
    # https://github.com/collectd/collectd/issues/716
    val.meta = {'0': True}
    val.dispatch() 
開發者ID:mantl,項目名稱:mantl,代碼行數:19,代碼來源:mesos-agent.py

示例12: read_callback

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read_callback():
    """ Get stats for all the servers in the cluster """
    for host in ZK_HOSTS:
        try:
            zk = ZooKeeperServer(host)
            stats = zk.get_stats()
            for k, v in stats.items():
                try:
                    val = collectd.Values(plugin='zookeeper', meta={'0':True})
                    val.type = "counter" if k in COUNTERS else "gauge"
                    val.type_instance = k
                    val.values = [v]
                    val.dispatch()
                except (TypeError, ValueError):
                    collectd.error('error dispatching stat; host=%s, key=%s, val=%s' % (host, k, v))
                    pass
        except socket.error, e:
            # ignore because the cluster can still work even
            # if some servers fail completely

            # this error should be also visible in a variable
            # exposed by the server in the statistics

            log('unable to connect to server "%s"' % (host)) 
開發者ID:mantl,項目名稱:mantl,代碼行數:26,代碼來源:zookeeper-collectd-plugin.py

示例13: write_stats

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def write_stats(role_metrics, stats):

    flat_stats = flatten_dict(stats, '.')
    
    for key_name in flat_stats:
        attr_name = key_name.split('.')[-1]

        # TODO: this needs some more think time, since the key from the name
        # is not the key of the all_metrics dict
        if attr_name in role_metrics:
            attr_type = role_metrics[attr_name][1]     # gauge / derive etc
        else:
            # assign a default
            attr_type = 'gauge'

        attr_value = flat_stats[key_name]

        val = collectd.Values(plugin=PLUGIN_NAME, type=attr_type)
        instance_name = "{}.{}".format(CEPH.cluster_name,
                                       key_name)
        val.type_instance = instance_name
        val.values = [attr_value]
        val.dispatch() 
開發者ID:ceph,項目名稱:cephmetrics,代碼行數:25,代碼來源:cephmetrics.py

示例14: read

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def read(self):
        metric = collectd.Values()
        metric.plugin = "lain.cluster.docker_daemon"
        metric.plugin_instance = "docker_ps_time"
        metric.type = "val"
        start_at = time.time()
        requests.get(
            self.DOCKER_PS_URL, params={"limit": 1}, timeout=self.TIMEOUT)
        docker_ps_time = time.time() - start_at
        metric.values = [docker_ps_time]
        metric.dispatch() 
開發者ID:laincloud,項目名稱:lain,代碼行數:13,代碼來源:docker_daemon_monitor.py

示例15: Values

# 需要導入模塊: import collectd [as 別名]
# 或者: from collectd import Values [as 別名]
def Values(self):
            return ExecCollectdValues() 
開發者ID:lebauce,項目名稱:docker-collectd-plugin,代碼行數:4,代碼來源:dockerplugin.py


注:本文中的collectd.Values方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。