本文整理汇总了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))
示例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()
示例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()
示例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()
示例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
示例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()
示例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))
示例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()
示例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))
示例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()
示例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()
示例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))
示例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()
示例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()
示例15: Values
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import Values [as 别名]
def Values(self):
return ExecCollectdValues()