本文整理汇总了Python中scalrpy.util.helper.exc_info函数的典型用法代码示例。如果您正苦于以下问题:Python exc_info函数的具体用法?Python exc_info怎么用?Python exc_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exc_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_webhook_exception
def _handle_webhook_exception(self, webhook):
exc = sys.exc_info()[1]
if isinstance(exc, (
requests.exceptions.Timeout,
requests.exceptions.ProxyError,
requests.exceptions.ConnectionError)):
if webhook['handle_attempts'] < webhook['attempts']:
webhook['status'] = 0
else:
webhook['status'] = 2
webhook['error_msg'] = str(sys.exc_info()[0].__name__)
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
elif isinstance(exc, (
requests.exceptions.RequestException,
requests.packages.urllib3.exceptions.HTTPError,
requests.packages.urllib3.exceptions.HTTPWarning)):
webhook['status'] = 2
webhook['error_msg'] = str(sys.exc_info()[0].__name__)
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
else:
webhook['status'] = 2
webhook['error_msg'] = 'Internal error'
msg = "Unable to process webhook: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.error(msg)
示例2: _send
def _send(self, task):
if not task:
return
try:
msg = task['msg']
req = task['req']
try:
LOG.debug('Send message %s host %s header %s'
% (msg['messageid'], req.get_host(), req.header_items()))
code = urllib2.urlopen(
req, timeout=CONFIG['instances_connection_timeout']).getcode()
if code != 201:
raise Exception('Server response code %s' % code)
LOG.debug('Delivery ok, message %s, host %s'
% (msg['messageid'], req.get_host()))
try:
self._db_update(True, msg)
except:
LOG.error('Unable to update database %s' %helper.exc_info())
except:
e = sys.exc_info()[1]
if type(e) in (urllib2.URLError, socket.timeout) and\
('Connection refused' in str(e) or 'timed out' in str(e)):
LOG.warning('Delivery failed message id %s host %s error %s'
% (msg['messageid'], req.get_host(), helper.exc_info()))
else:
LOG.error('Delivery failed message id %s host %s error %s'
% (msg['messageid'], req.get_host(), helper.exc_info()))
self._db_update(False, msg)
except:
LOG.error(helper.exc_info())
示例3: run
def run(self):
while True:
try:
count = self._get_events_count()
LOG.info(count)
if count < CONFIG['warning_threshold']:
time.sleep(CONFIG['interval'])
continue
message = 'DBQueueEvent alert. Events do not processed: %s' % count
mail = MIMEText(message.encode('utf-8'), _charset='utf-8')
mail['From'] = CONFIG['email_from']
mail['To'] = CONFIG['email_to']
if count > CONFIG['critical_threshold']:
mail['Subject'] = 'DBQueueEvent critical alert'
else:
mail['Subject'] = 'DBQueueEvent warning alert'
LOG.debug('Send mail\n%s' % mail.as_string())
try:
server = smtplib.SMTP('localhost')
server.sendmail(mail['From'], mail['To'], mail.as_string())
except:
LOG.error('Send mail fail: %s' % helper.exc_info())
time.sleep(CONFIG['interval'])
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
LOG.error(helper.exc_info())
time.sleep(10)
示例4: _average
def _average(self, results, ra=None, fa=None, rs=None, fs=None):
ra = ra or dict()
fa = fa or dict()
rs = rs or dict()
fs = fs or dict()
for result in results:
try:
r_key, f_key = self._get_rf_keys(result)
if 'snum' in self.config['metrics']:
rs.setdefault(r_key, {'snum': {'s_running': 0}})
fs.setdefault(f_key, {'snum': {'s_running': 0}})
rs[r_key]['snum']['s_running'] += 1
fs[f_key]['snum']['s_running'] += 1
if not result['data']:
continue
for metrics_group_name, metrics_data in result['data'].iteritems():
if not metrics_data or metrics_group_name == 'io':
continue
for metric_name, value in metrics_data.iteritems():
try:
ra.setdefault(r_key, {})
ra[r_key].setdefault(metrics_group_name, {})
ra[r_key][metrics_group_name].setdefault(metric_name, Average())
fa.setdefault(f_key, {})
fa[f_key].setdefault(metrics_group_name, {})
fa[f_key][metrics_group_name].setdefault(metric_name, Average())
ra[r_key][metrics_group_name][metric_name] += value
fa[f_key][metrics_group_name][metric_name] += value
except:
LOG.error(helper.exc_info())
except:
LOG.error(helper.exc_info())
return ra, fa, rs, fs
示例5: get_metrics
def get_metrics(host, port, key, api_type, metrics, headers=None, timeout=5):
assert host, 'host'
assert port, 'port'
assert key, 'key'
assert api_type, 'api_type'
assert metrics, 'metrics'
data = dict()
endpoint = 'http://%s:%s' % (host, port)
security = rpc.Security(key)
hsp = rpc.HttpServiceProxy(endpoint, security=security, headers=headers)
getters = {
'cpu': get_cpu_stat,
'la': get_la_stat,
'mem': get_mem_info,
'net': get_net_stat,
'io': get_io_stat,
}
for metric in metrics:
try:
data.update({metric: getters[metric](hsp, api_type, timeout=timeout)})
except (urllib2.URLError, urllib2.HTTPError, socket.timeout):
msg = "Endpoint: {endpoint}, headers: {headers}, metric: '{metric}', reason: {err}"
msg = msg.format(
endpoint=endpoint, headers=headers, metric=metric, err=helper.exc_info())
raise Exception(msg)
except:
msg = "Endpoint: {endpoint}, headers: {headers}, metric '{metric}' failed, reason: {er}"
msg = msg.format(
endpoint=endpoint, headers=headers, metric=metric, err=helper.exc_info())
LOG.warning(msg)
continue
return data
示例6: do_iteration
def do_iteration(self):
self.iteration_timestamp = time.time()
webhooks = self.get_webhooks()
if not webhooks:
raise NothingToDoError()
for webhook in webhooks:
try:
wait_pool()
webhook['async_result'] = POOL.apply_async(self.post_webhook, (webhook,))
except:
msg = "Unable to process webhook history_id: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
for webhook in webhooks:
try:
webhook['response_code'] = webhook['async_result'].get(timeout=60)
except DBQueueEvent.PostError:
error_msg = str(sys.exc_info()[1])
self._handle_error(webhook, error_msg)
except:
error_msg = 'Internal error'
self._handle_error(webhook, error_msg)
try:
wait_pool()
POOL.apply_async(self.update_webhook, (webhook,))
except:
msg = "Unable to update webhook history_id: {0}, reason: {1}"
msg = msg.format(webhook['history_id'], helper.exc_info())
LOG.warning(msg)
POOL.join()
示例7: rest_event_observer
def rest_event_observer(self, event, config):
try:
key = "On%sNotifyURL" % event["type"]
if key not in config or not config[key]:
return
payload = {"event": event["type"], "message": event["message"]}
r = requests.post(config[key], params=payload, timeout=10)
LOG.debug("Event:%s. Send request:'url:%s' status:'%s'" % (event["id"], config[key], r.status_code))
except requests.exceptions.RequestException:
LOG.warning(helper.exc_info())
except:
LOG.error(helper.exc_info())
示例8: rest_event_observer
def rest_event_observer(self, event, config):
try:
key = 'On%sNotifyURL' % event['type']
if key not in config or not config[key]:
return
payload = {'event': event['type'], 'message': event['message']}
r = requests.post(config[key], params=payload, timeout=10)
LOG.debug('Event:%s. Send request url:%s status %s' \
% (event['id'], config[key], r.status))
except requests.exceptions.RequestException:
LOG.warning(helper.exc_info())
except:
LOG.error(helper.exc_info())
示例9: __call__
def __call__(self):
poller_ps, plotter_ps = None, None
if self.args['--plotter']:
plotter = Plotter(self.config)
plotter_ps = plotter.run_in_process()
time.sleep(5)
if not plotter_ps.is_alive():
LOG.critical('Failed to start CherryPy web server')
sys.exit(1)
self.change_permissions()
if self.args['--poller']:
poller = Poller(self.config, self.scalr_config)
while True:
start_time = time.time()
try:
LOG.info('Start poller iteration')
rrdcached_sock_file = self.config['rrd']['rrdcached_sock_path']
if not os.path.exists(rrdcached_sock_file):
raise Exception('rrdcached process is not running')
poller_ps = poller.run_in_process()
poller_ps.join(self.config['interval'] * 2)
if poller_ps.is_alive():
LOG.error('Poller iteration timeout. Terminating')
try:
poller_ps.terminate()
except:
msg = 'Unable to terminate, reason: {error}'.format(
error=helper.exc_info())
raise Exception(msg)
LOG.info('Poller iteration time: %.2f' % (time.time() - start_time))
except KeyboardInterrupt:
raise
except:
msg = 'Poller iteration failed, reason: {error}'.format(
error=helper.exc_info())
LOG.error(msg)
finally:
sleep_time = start_time + self.config['interval'] - time.time() - 0.1
if sleep_time > 0:
time.sleep(sleep_time)
if plotter_ps:
plotter_ps.join()
示例10: update_server
def update_server(self, server):
try:
szr_upd_client = self._get_szr_upd_client(server)
timeout = self.config["instances_connection_timeout"]
msg = "Trying to update server: {0}, version: {1}".format(server["server_id"], server["scalarizr.version"])
LOG.debug(msg)
try:
result_id = szr_upd_client.update(async=True, timeout=timeout)
except:
msg = "Unable to update, reason: {0}".format(helper.exc_info())
raise Exception(msg)
LOG.debug("Server: {0}, result: {1}".format(server["server_id"], result_id))
except:
msg = "Server failed: {0}, reason: {1}".format(server["server_id"], helper.exc_info())
LOG.warning(msg)
示例11: do_iteration
def do_iteration(self):
servers = self.get_servers_for_update()
for server in servers:
try:
self._pool.wait()
self._pool.apply_async(self.update_server, (server,))
gevent.sleep(0) # force switch
except:
LOG.warning(helper.exc_info())
self._pool.join()
try:
self.update_scalr_repo_data()
except:
msg = "Unable to update scalr.settings table, reason: {0}".format(helper.exc_info())
LOG.error(msg)
示例12: process_message
def process_message(self, message, server):
try:
status = None
try:
request = self.make_request(message, server)
if not request['url']:
msg = "Wrong request: {request}".format(request=request)
raise Exception(msg)
except:
self.update_error(message)
raise sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
try:
msg = "Send message: {message_id}, request: {request}"
msg = msg.format(
message_id=message['messageid'],
request={'url': request['url'], 'headers': request['headers']})
LOG.debug(msg)
r = requests.post(
request['url'],
data=request['data'],
headers=request['headers'],
timeout=CONFIG['instances_connection_timeout'])
if r.status_code != 201:
msg = "Bad response code: {code}".format(code=r.status_code)
raise Exception(msg)
msg = "Message: {message_id}, delivery ok"
msg = msg.format(message_id=message['messageid'])
LOG.debug(msg)
status = True
except:
msg = "Message: {message_id}, delivery failed, reason: {error}"
msg = msg.format(message_id=message['messageid'], error=helper.exc_info())
LOG.warning(msg)
status = False
if status:
self.update_ok(message)
else:
self.update_not_ok(message)
except:
msg = "Unable to process message: {message_id}, server: {server}, reason: {error}"
msg = msg.format(message_id=message['messageid'], server=server, error=helper.exc_info())
LOG.warning(msg)
raise sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
示例13: _get_statuses
def _get_statuses(self, servers):
async_results = {}
for server in servers:
if 'scalarizr.key' not in server:
msg = "Server: {0}, reason: Missing scalarizr key".format(server['server_id'])
LOG.warning(msg)
continue
if 'scalarizr.updc_port' not in server:
api_port = self.scalr_config['scalarizr_update'].get('api_port', 8008)
server['scalarizr.updc_port'] = api_port
self._pool.wait()
async_results[server['server_id']] = self._pool.apply_async(self._get_status, (server,))
gevent.sleep(0) # force switch
statuses = {}
timeout = self.config['instances_connection_timeout']
for server in servers:
try:
server_id = server['server_id']
statuses[server_id] = async_results[server_id].get(timeout=timeout)
except:
msg = 'Unable to get update client status, server: {0}, reason: {1}'
msg = msg.format(server['server_id'], helper.exc_info())
LOG.warning(msg)
return statuses
示例14: encrypt_data
def encrypt_data(self, data):
if not self.encrypt:
return data
try:
return cryptotool.encrypt(self.crypto_algo, data, self.crypto_key)
except:
raise InvalidRequestError('Failed to encrypt data. Error:%s' % helper.exc_info())
示例15: _ec2_region
def _ec2_region(region, cred):
try:
access_key = cryptotool.decrypt_scalr(app.crypto_key, cred["access_key"])
secret_key = cryptotool.decrypt_scalr(app.crypto_key, cred["secret_key"])
kwds = {"aws_access_key_id": access_key, "aws_secret_access_key": secret_key}
proxy_settings = app.proxy_settings.get(cred.platform, {})
kwds["proxy"] = proxy_settings.get("host")
kwds["proxy_port"] = proxy_settings.get("port")
kwds["proxy_user"] = proxy_settings.get("user")
kwds["proxy_pass"] = proxy_settings.get("pass")
msg = "List nodes for platform: 'ec2', region: '{}', envs_ids: {}"
msg = msg.format(region, cred.envs_ids)
LOG.debug(msg)
conn = boto.ec2.connect_to_region(region, **kwds)
cloud_nodes = _ec2_get_only_instances(conn)
timestamp = int(time.time())
nodes = list()
for cloud_node in cloud_nodes:
node = {
"instance_id": cloud_node.id,
"instance_type": cloud_node.instance_type,
"os": cloud_node.platform if cloud_node.platform else "linux",
}
nodes.append(node)
return {"region": region, "timestamp": timestamp, "nodes": nodes} if nodes else dict()
except:
e = sys.exc_info()[1]
msg = "platform: '{platform}', region: '{region}', envs_ids: {envs_ids}. Reason: {error}"
msg = msg.format(
platform=cred.platform, region=region, envs_ids=cred.envs_ids, error=helper.exc_info(where=False)
)
_handle_exception(e, msg)