本文整理汇总了Python中Handler.Handler类的典型用法代码示例。如果您正苦于以下问题:Python Handler类的具体用法?Python Handler怎么用?Python Handler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, config=None):
"""
Create a new instance of the InfluxdbeHandler
"""
# Initialize Handler
Handler.__init__(self, config)
if not InfluxDBClient:
self.log.error('influxdb.client.InfluxDBClient import failed. '
'Handler disabled')
# Initialize Options
if self.config['ssl'] == "True":
self.ssl = True
else:
self.ssl = False
self.hostname = self.config['hostname']
self.port = int(self.config['port'])
self.username = self.config['username']
self.password = self.config['password']
self.database = self.config['database']
self.batch_size = int(self.config['batch_size'])
self.batch_count = 0
self.time_precision = self.config['time_precision']
# Initialize Data
self.batch = {}
self.influx = None
# Connect
self._connect()
示例2: __init__
def __init__(self, config=None):
"""
Create a new instance of cloudwatchHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
# Initialize Data
self.connection = None
# Initialize Options
self.region = self.config['region']
self.instance_id = boto.utils.get_instance_metadata()['instance-id']
self.log.debug("Setting InstanceID: " + self.instance_id)
self.valid_config = ('region', 'collector', 'metric', 'namespace', "name", "unit")
self.rules = []
for key_name, section in self.config.items():
if section.__class__ is Section:
keys = section.keys()
rules = {}
for key in keys:
if key not in self.valid_config:
self.log.warning("invalid key %s in section %s", key, section.name)
else:
rules[key] = section[key]
self.rules.append(rules)
# Create CloudWatch Connection
self._bind()
示例3: __init__
def __init__(self, config=None):
"""
Create a new instance of the GraphiteHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
# Initialize Data
self.socket = None
# Initialize Options
self.proto = self.config['proto'].lower().strip()
self.host = self.config['host']
self.port = int(self.config['port'])
self.timeout = float(self.config['timeout'])
self.keepalive = bool(self.config['keepalive'])
self.keepaliveinterval = int(self.config['keepaliveinterval'])
self.batch_size = int(self.config['batch'])
self.max_backlog_multiplier = int(
self.config['max_backlog_multiplier'])
self.trim_backlog_multiplier = int(
self.config['trim_backlog_multiplier'])
self.flow_info = self.config['flow_info']
self.scope_id = self.config['scope_id']
self.metrics = []
self.reconnect_interval = int(self.config['reconnect_interval'])
self.last_connect_timestamp = -1
# Connect
self._connect()
示例4: __init__
def __init__(self, config=None):
"""
Create a new instance of the LibratoHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
logging.debug("Initialized Librato handler.")
if librato is None:
logging.error("Failed to load librato module")
return
# Initialize Options
api = librato.connect(self.config['user'],
self.config['apikey'])
self.queue = api.new_queue()
self.queue_max_size = int(self.config['queue_max_size'])
self.queue_max_interval = int(self.config['queue_max_interval'])
self.queue_max_timestamp = int(time.time() + self.queue_max_interval)
self.current_n_measurements = 0
# If a user leaves off the ending comma, cast to a array for them
include_filters = self.config['include_filters']
if isinstance(include_filters, basestring):
include_filters = [include_filters]
self.include_reg = re.compile(r'(?:%s)' % '|'.join(include_filters))
示例5: __init__
def __init__(self, config=None):
# Initialize Handler
Handler.__init__(self, config)
if discovery is None:
logging.error("Failed to load apiclient.discovery")
return
elif GoogleCredentials is None:
logging.error("Failed to load "
"oauth2client.client.GoogleCredentials")
return
# Initialize options
self.topic = self.config['topic']
self.scopes = self.config['scopes']
self.retries = int(self.config['retries'])
self.batch = self.config['batch']
self.batch_size = int(self.config['batch_size'])
self.metrics = []
tags_items = self.config['tags']
self.tags = {}
for item in tags_items:
k, v = item.split(':')
self.tags[k] = v
# Initialize client
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(self.scopes)
self.client = discovery.build('pubsub', 'v1', credentials=credentials)
示例6: __init__
def __init__(self, config=None):
"""
Create a new instance of the StatsdHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
logging.debug("Initialized statsd handler.")
if not statsd:
self.log.error('statsd import failed. Handler disabled')
self.enabled = False
return
if not hasattr(statsd, 'StatsClient'):
self.log.warn('python-statsd support is deprecated '
'and will be removed in the future. '
'Please use https://pypi.python.org/pypi/statsd/')
# Initialize Options
self.host = self.config['host']
self.port = int(self.config['port'])
self.batch_size = int(self.config['batch'])
self.metrics = []
self.old_values = {}
# Connect
self._connect()
示例7: __init__
def __init__(self, config=None):
"""
Create a new instance of rmqHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
# Initialize Data
self.connection = None
self.channel = None
# Initialize Options
self.server = self.config.get('server', '127.0.0.1')
self.port = int(self.config.get('port', 5672))
self.topic_exchange = self.config.get('topic_exchange', 'diamond')
self.vhost = self.config.get('vhost', '')
self.user = self.config.get('user', 'guest')
self.password = self.config.get('password', 'guest')
self.routing_key = self.config.get('routing_key', 'metric')
self.custom_routing_key = self.config.get(
'custom_routing_key', 'diamond')
if not pika:
self.log.error('pika import failed. Handler disabled')
return
# Create rabbitMQ topic exchange and bind
try:
self._bind()
except pika.exceptions.AMQPConnectionError:
self.log.error('Failed to bind to rabbitMQ topic exchange')
示例8: __init__
def __init__(self, config=None):
"""
Create a new instance of the LibratoHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
logging.debug("Initialized Librato handler.")
if librato is None:
logging.error("Failed to load librato module")
return
# Initialize Options
self.api = librato.connect(self.config["user"], self.config["apikey"])
self.queue = []
self.queue_max_age = int(self.config["queue_max_age"])
self.queue_max_size = int(self.config["queue_max_size"])
self.queue_max_interval = int(self.config["queue_max_interval"])
self.queue_max_timestamp = int(time.time() + self.queue_max_interval)
self.disable_force_flush = bool(self.config["disable_force_flush"])
# If a user leaves off the ending comma, cast to a array for them
include_filters = self.config["include_filters"]
if isinstance(include_filters, basestring):
include_filters = [include_filters]
self.include_reg = re.compile(r"(?:%s)" % "|".join(include_filters))
示例9: __init__
def __init__(self, config=None):
"""
Create a new instance of the SensuHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
# Initialize Data
self.socket = None
# Initialize Options
self.proto = self.config['proto'].lower().strip()
self.host = self.config['host']
self.port = int(self.config['port'])
self.timeout = int(self.config['timeout'])
self.keepalive = bool(self.config['keepalive'])
self.keepaliveinterval = int(self.config['keepaliveinterval'])
self.batch_size = int(self.config['batch'])
self.max_backlog_multiplier = int(
self.config['max_backlog_multiplier'])
self.trim_backlog_multiplier = int(
self.config['trim_backlog_multiplier'])
self.metrics = []
# Connect
self._connect()
示例10: __init__
def __init__(self, config=None):
"""
Create a new instance of the ObservabilityHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
logging.debug("Initialized Observability handler.")
if oauth2 is None:
logging.error("Failed to load oauthlib module")
return
if requests_oauthlib is None:
logging.error("Failed to load requests_oauthlib module")
return
# Initialize client
self.client_key = self.config['client_key']
self.client_secret = self.config['client_secret']
self.floor_seconds = int(self.config['floor_seconds'])
self.queue = []
self.queue_max_age = int(self.config['queue_max_age'])
client = oauth2.BackendApplicationClient(client_id=self.client_key)
self.session = requests_oauthlib.OAuth2Session(client=client)
self.token = None
示例11: __init__
def __init__(self, config=None):
"""
Create a new instance of the HostedGraphiteHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
self.key = self.config['apikey'].lower().strip()
self.graphite = GraphiteHandler(self.config)
示例12: __init__
def __init__(self, config=None):
"""
New instance of LogentriesDiamondHandler class
"""
Handler.__init__(self, config)
self.log_token = self.config.get('log_token', None)
self.queue_size = int(self.config['queue_size'])
self.queue = deque([])
if self.log_token is None:
raise Exception
示例13: __init__
def __init__(self, config=None):
Handler.__init__(self, config)
self.metrics = []
self.batch_size = int(self.config['batch'])
self.url = self.config['url']
self.auth_token = self.config['auth_token']
self.batch_max_interval = self.config['batch_max_interval']
self.resetBatchTimeout()
if self.auth_token == "":
logging.error("Failed to load Signalfx module")
return
示例14: __init__
def __init__(self, config=None):
"""
initialize Netuitive api and populate agent host metadata
"""
if not netuitive:
self.log.error('netuitive import failed. Handler disabled')
self.enabled = False
return
try:
Handler.__init__(self, config)
logging.debug("initialize Netuitive handler")
self.version = self._get_version()
self.api = netuitive.Client(self.config['url'], self.config[
'api_key'], self.version)
self.element = netuitive.Element(
location=self.config.get('location'))
self.batch_size = int(self.config['batch'])
self.max_backlog_multiplier = int(
self.config['max_backlog_multiplier'])
self.trim_backlog_multiplier = int(
self.config['trim_backlog_multiplier'])
self._add_sys_meta()
self._add_aws_meta()
self._add_docker_meta()
self._add_azure_meta()
self._add_config_tags()
self._add_config_relations()
self._add_collectors()
self.flush_time = 0
try:
self.config['write_metric_fqns'] = str_to_bool(self.config['write_metric_fqns'])
except KeyError, e:
self.log.warning('write_metric_fqns missing from the config')
self.config['write_metric_fqns'] = False
if self.config['write_metric_fqns']:
self.metric_fqns_path = self.config['metric_fqns_path']
truncate_fqn_file = open(self.metric_fqns_path, "w")
truncate_fqn_file.close()
logging.debug(self.config)
示例15: __init__
def __init__(self, config=None):
"""
Create a new instance of the InfluxdbeHandler
"""
# Initialize Handler
Handler.__init__(self, config)
# Initialize Options
if self.config['ssl'] == "True":
self.ssl = True
else:
self.ssl = False
self.hostname = self.config['hostname']
self.port = int(self.config['port'])
self.username = self.config['username']
self.password = self.config['password']
self.database = self.config['database']
self.batch_size = int(self.config['batch_size'])
self.metric_max_cache = int(self.config['cache_size'])
self.batch_count = 0
self.time_precision = self.config['time_precision']
self.timeout = self.config['timeout']
self.influxdb_version = self.config['influxdb_version']
self.using_0_8 = False
if self.influxdb_version in ['0.8', '.8']:
if not InfluxDB08Client:
self.log.error(
'influxdb.influxdb08.client.InfluxDBClient import failed. '
'Handler disabled')
self.enabled = False
return
else:
self.client = InfluxDB08Client
self.using_0_8 = True
else:
if not InfluxDBClient:
self.log.error('influxdb.client.InfluxDBClient import failed. '
'Handler disabled')
self.enabled = False
return
else:
self.client = InfluxDBClient
# Initialize Data
self.batch = {}
self.influx = None
self.batch_timestamp = time.time()
self.time_multiplier = 1
# Connect
self._connect()