本文整理汇总了Python中collectd.error方法的典型用法代码示例。如果您正苦于以下问题:Python collectd.error方法的具体用法?Python collectd.error怎么用?Python collectd.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collectd
的用法示例。
在下文中一共展示了collectd.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [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_swift_stat
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [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))
示例3: run_command
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def run_command(self, command, check_output=True):
"""Run a command for this collectd plugin. Returns a tuple with command
success and output or False and None for output.
"""
output = None
try:
if check_output:
output = subprocess.check_output(command)
else:
stdin, stdout, stderr = os.popen3(' '.join(command))
output = stdout.read()
except Exception as exc:
collectd.error(
'collectd-ceph-storage: {} exception: {}'.format(command, exc))
collectd.error(
'collectd-ceph-storage: {} traceback: {}'
.format(command, traceback.format_exc()))
return False, None
if output is None:
collectd.error(
'collectd-ceph-storage: failed to {}: output is None'
.format(command))
return False, None
return True, output
示例4: get_stats
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def get_stats(self):
"""Retrieves stats from ceph mons"""
ceph_cluster = "%s-%s" % (self.prefix, self.cluster)
data = { ceph_cluster: { 'mon': { 'number': 0, 'quorum': 0 } } }
output = None
try:
cephmoncmdline='ceph mon dump --format json --cluster ' + self.cluster
output = subprocess.check_output(cephmoncmdline, shell=True)
except Exception as exc:
collectd.error("ceph-mon: failed to ceph mon dump :: %s :: %s"
% (exc, traceback.format_exc()))
return
if output is None:
collectd.error('ceph-mon: failed to ceph mon dump :: output was None')
json_data = json.loads(output)
data[ceph_cluster]['mon']['number'] = len(json_data['mons'])
data[ceph_cluster]['mon']['quorum'] = len(json_data['quorum'])
return data
示例5: read_callback
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [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))
示例6: read
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def read(self):
try:
container_ids = self.__get_all_container_ids()
self.read_docker_used_cpu_cores(container_ids)
time.sleep(10)
self.read_docker_reserved_cpu_cores(container_ids)
except Exception as e:
collectd.error("read() failed, exception: {}".format(e))
示例7: fetch_json
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def fetch_json(url):
"""Fetch json from url"""
try:
return json.load(urllib2.urlopen(url, timeout=5))
except urllib2.URLError, e:
collectd.error("mesos-tasks plugin: Error connecting to %s - %r" % (url, e))
return None
示例8: get_stats
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def get_stats():
"""
Makes two calls to haproxy to fetch server info and server stats.
Returns the dict containing metric name as the key and a tuple of metric value and the dict of dimensions if any
"""
if HAPROXY_SOCKET is None:
collectd.error("Socket configuration parameter is undefined. Couldn't get the stats")
return
stats = []
haproxy = HAProxySocket(HAPROXY_SOCKET)
try:
server_info = haproxy.get_server_info()
server_stats = haproxy.get_server_stats()
except socket.error:
collectd.warning(
'status err Unable to connect to HAProxy socket at %s' %
HAPROXY_SOCKET)
return stats
for key, val in server_info.iteritems():
try:
stats.append((key, int(val), None))
except (TypeError, ValueError):
pass
for statdict in server_stats:
if not (statdict['svname'].lower() in PROXY_MONITORS or statdict['pxname'].lower() in PROXY_MONITORS):
continue
for metricname, val in statdict.items():
try:
stats.append((metricname, int(val), {'proxy_name': statdict['pxname'], 'service_name': statdict['svname']}))
except (TypeError, ValueError):
pass
return stats
示例9: error
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def error(self, msg):
pass
示例10: error
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def error(self, message):
"""Log an error message to the collectd logger. """
collectd.error('%s plugin: %s' % (self.name, message))
示例11: read
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def read(data=None):
starttime = time.time()
gnocchi = client.Client(session=keystone_session)
try:
status = gnocchi.status.get()
metric = collectd.Values()
metric.plugin = 'gnocchi_status'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = 'measures'
metric.values = [status['storage']['summary']['measures']]
metric.dispatch()
metric = collectd.Values()
metric.plugin = 'gnocchi_status'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = 'metrics'
metric.values = [status['storage']['summary']['metrics']]
metric.dispatch()
except Exception as err:
collectd.error(
'gnocchi_status: Exception getting status: {}'
.format(err))
timediff = time.time() - starttime
if timediff > INTERVAL:
collectd.warning(
'gnocchi_status: Took: {} > {}'
.format(round(timediff, 2), INTERVAL))
示例12: dispatch
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def dispatch(self, stats):
"""
Dispatches the given stats.
stats should be something like:
{'plugin': {'plugin_instance': {'type': {'type_instance': <value>, ...}}}}
"""
if not stats:
collectd.error("%s: failed to retrieve stats" % self.prefix)
return
self.logdebug("dispatching %d new stats :: %s" % (len(stats), stats))
try:
for plugin in stats.keys():
for plugin_instance in stats[plugin].keys():
for type in stats[plugin][plugin_instance].keys():
type_value = stats[plugin][plugin_instance][type]
if not isinstance(type_value, dict):
self.dispatch_value(plugin, plugin_instance, type, None, type_value)
else:
for type_instance in stats[plugin][plugin_instance][type].keys():
self.dispatch_value(plugin, plugin_instance,
type, type_instance,
stats[plugin][plugin_instance][type][type_instance])
except Exception as exc:
collectd.error("%s: failed to dispatch values :: %s :: %s"
% (self.prefix, exc, traceback.format_exc()))
示例13: read_callback
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def read_callback(self):
try:
start = datetime.datetime.now()
stats = self.get_stats()
self.logverbose("collectd new data from service :: took %d seconds"
% (datetime.datetime.now() - start).seconds)
except Exception as exc:
collectd.error("%s: failed to get stats :: %s :: %s"
% (self.prefix, exc, traceback.format_exc()))
self.dispatch(stats)
示例14: get_stats
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def get_stats(self):
collectd.error('Not implemented, should be subclassed')
示例15: dispatch
# 需要导入模块: import collectd [as 别名]
# 或者: from collectd import error [as 别名]
def dispatch(self, stats):
"""
Dispatches the given stats.
stats should be something like:
{'plugin': {'plugin_instance': {'type': {'type_instance': <value>, ...}}}}
"""
if not stats:
collectd.error("%s: failed to retrieve stats" % self.prefix)
return
self.logdebug("dispatching %d new stats :: %s" % (len(stats), stats))
try:
for plugin in stats.keys():
for plugin_instance in stats[plugin].keys():
for type in stats[plugin][plugin_instance].keys():
type_value = stats[plugin][plugin_instance][type]
if not isinstance(type_value, dict):
self.dispatch_value(plugin, plugin_instance, type, None, type_value)
else:
for type_instance in stats[plugin][plugin_instance][type].keys():
self.dispatch_value(plugin, plugin_instance,
type, type_instance,
stats[plugin][plugin_instance][type][type_instance])
except Exception as exc:
collectd.error("%s: failed to dispatch values :: %s :: %s"
% (self.prefix, exc, traceback.format_exc()))