本文整理汇总了Python中shinken.http_client.HTTPClient.set_proxy方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPClient.set_proxy方法的具体用法?Python HTTPClient.set_proxy怎么用?Python HTTPClient.set_proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shinken.http_client.HTTPClient
的用法示例。
在下文中一共展示了HTTPClient.set_proxy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stats
# 需要导入模块: from shinken.http_client import HTTPClient [as 别名]
# 或者: from shinken.http_client.HTTPClient import set_proxy [as 别名]
class Stats(object):
def __init__(self):
self.name = ''
self.type = ''
self.app = None
self.stats = {}
# There are two modes that are not exclusive
# first the kernel mode
self.api_key = ''
self.secret = ''
self.http_proxy = ''
self.con = HTTPClient(uri='http://kernel.shinken.io')
# then the statsd one
self.statsd_sock = None
self.statsd_addr = None
def launch_reaper_thread(self):
self.reaper_thread = threading.Thread(None, target=self.reaper, name='stats-reaper')
self.reaper_thread.daemon = True
self.reaper_thread.start()
def register(self, app, name, _type, api_key='', secret='', http_proxy='',
statsd_host='localhost', statsd_port=8125, statsd_prefix='shinken',
statsd_enabled=False):
self.app = app
self.name = name
self.type = _type
# kernel.io part
self.api_key = api_key
self.secret = secret
self.http_proxy = http_proxy
# local statsd part
self.statsd_host = statsd_host
self.statsd_port = statsd_port
self.statsd_prefix = statsd_prefix
self.statsd_enabled = statsd_enabled
if self.statsd_enabled:
logger.debug('Loading statsd communication with %s:%s.%s',
self.statsd_host, self.statsd_port, self.statsd_prefix)
self.load_statsd()
# Also load the proxy if need
self.con.set_proxy(self.http_proxy)
# Let be crystal clear about why I don't use the statsd lib in python: it's crappy.
# how guys did you fuck this up to this point? django by default for the conf?? really?...
# So raw socket are far better here
def load_statsd(self):
try:
self.statsd_addr = (socket.gethostbyname(self.statsd_host), self.statsd_port)
self.statsd_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except (socket.error, socket.gaierror), exp:
logger.error('Cannot create statsd socket: %s' % exp)
return
示例2: Stats
# 需要导入模块: from shinken.http_client import HTTPClient [as 别名]
# 或者: from shinken.http_client.HTTPClient import set_proxy [as 别名]
class Stats(object):
def __init__(self):
self.name = ""
self.type = ""
self.app = None
self.stats = {}
# There are two modes that are not exclusive
# first the kernel mode
self.api_key = ""
self.secret = ""
self.http_proxy = ""
self.con = HTTPClient(uri="http://kernel.shinken.io")
# then the statsd one
self.statsd_interval = 5
self.statsd_types = ["system", "queue", "perf"]
self.statsd_sock = None
self.statsd_addr = None
self.statsd_types = "system,object,queue,perf"
self.statsd_pattern = None
self.name_cache = {}
def launch_reaper_thread(self):
self.reaper_thread = threading.Thread(None, target=self.reaper, name="stats-reaper")
self.reaper_thread.daemon = True
self.reaper_thread.start()
def launch_harvester_thread(self):
self.harvester_thread = threading.Thread(None, target=self.harvester, name="stats-harvester")
self.harvester_thread.daemon = True
self.harvester_thread.start()
def register(
self,
app,
name,
_type,
api_key="",
secret="",
http_proxy="",
statsd_host="localhost",
statsd_port=8125,
statsd_prefix="shinken",
statsd_enabled=False,
statsd_interval=5,
statsd_types=None,
statsd_pattern=None,
):
self.app = app
self.name = name
self.type = _type
# kernel.io part
self.api_key = api_key
self.secret = secret
self.http_proxy = http_proxy
# local statsd part
self.statsd_host = statsd_host
self.statsd_port = statsd_port
self.statsd_prefix = statsd_prefix
self.statsd_enabled = statsd_enabled
self.statsd_interval = statsd_interval
if statsd_types is not None:
self.statsd_types = [t.strip() for t in statsd_types.split(",") if t.strip()]
if statsd_pattern is not None:
self.statsd_pattern = statsd_pattern
self.name_cache = {}
if self.statsd_enabled:
logger.debug(
"Loading statsd communication with %s:%s.%s", self.statsd_host, self.statsd_port, self.statsd_prefix
)
self.load_statsd()
# Also load the proxy if need
self.con.set_proxy(self.http_proxy)
# Tells whether statsd is enabled and stats should be sent
def is_statsd_enabled(self):
return self.statsd_sock is not None and self.name and self.app is not None
# Tells whether kernel.status.io exporter is enabled
def is_shinkenio_enabled(self):
return self.name and self.api_key and self.secret
# Let be crystal clear about why I don't use the statsd lib in python: it's crappy.
# how guys did you fuck this up to this point? django by default for the conf?? really?...
# So raw socket are far better here
def load_statsd(self):
try:
self.statsd_addr = (socket.gethostbyname(self.statsd_host), self.statsd_port)
self.statsd_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except (socket.error, socket.gaierror), exp:
logger.error("Cannot create statsd socket: %s" % exp)
return