本文整理汇总了Python中statsd.StatsClient.timing方法的典型用法代码示例。如果您正苦于以下问题:Python StatsClient.timing方法的具体用法?Python StatsClient.timing怎么用?Python StatsClient.timing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsd.StatsClient
的用法示例。
在下文中一共展示了StatsClient.timing方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StaticticStatsD
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StaticticStatsD(object):
"""
Send stats to statsd.
"""
def __init__(self, hostname, host, port, prefix=None):
self.client = StatsClient(host, port, prefix=prefix)
self.hostname = hostname
def incr(self, metric, value=1, prefix=None):
"""
Increment 'metric' counter with 'value'.
"""
if prefix is not None:
metric = '%s.%s' % (prefix, metric)
self.client.incr(metric, value)
# separate metric for hostname
if self.hostname is not None:
metric = '%s.%s' % (self.hostname, metric)
self.client.incr(metric, value)
def timing(self, metric, value, prefix=None):
"""
Send 'metric' timing.
"""
if prefix is not None:
metric = '%s.%s' % (prefix, metric)
self.client.timing(metric, value)
# separate metric for hostname
if self.hostname is not None:
metric = '%s.%s' % (self.hostname, metric)
self.client.timing(metric, value)
示例2: StatsdStatsLogger
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StatsdStatsLogger(BaseStatsLogger):
def __init__(self, host='localhost', port=8125,
prefix='superset', statsd_client=None):
"""
Initializes from either params or a supplied, pre-constructed statsd client.
If statsd_client argument is given, all other arguments are ignored and the
supplied client will be used to emit metrics.
"""
if statsd_client:
self.client = statsd_client
else:
self.client = StatsClient(host=host, port=port, prefix=prefix)
def incr(self, key):
self.client.incr(key)
def decr(self, key):
self.client.decr(key)
def timing(self, key, value):
self.client.timing(key, value)
def gauge(self, key):
# pylint: disable=no-value-for-parameter
self.client.gauge(key)
示例3: StatsdStatsLogger
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StatsdStatsLogger(BaseStatsLogger):
def __init__(self, host, port, prefix='superset'):
self.client = StatsClient(host=host, port=port, prefix=prefix)
def incr(self, key):
self.client.incr(key)
def decr(self, key):
self.client.decr(key)
def timing(self, key, value):
self.client.timing(key, value)
def gauge(self, key):
# pylint: disable=no-value-for-parameter
self.client.gauge(key)
示例4: StatsDBackend
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StatsDBackend(BaseBackend):
name = 'statsd'
def __init__(self, config):
self.config = config
self.config.setdefault('STATSD_HOST', 'localhost')
self.config.setdefault('STATSD_PORT', 8125)
self.config.setdefault('STATSD_PREFIX', None)
self.statsd = StatsClient(self.config['STATSD_HOST'],
self.config['STATSD_PORT'],
self.config['STATSD_PREFIX'])
def timing(self, stat_name, delta):
return self.statsd.timing(stat_name, delta, self.config['STATS_RATE'])
def incr(self, stat_name, count=1):
return self.statsd.incr(stat_name, count, self.config['STATS_RATE'])
def decr(self, stat_name, count=1):
return self.statsd.decr(stat_name, count, self.config['STATS_RATE'])
def gauge(self, stat_name, value, delta=False):
return self.statsd.gauge(stat_name, value, self.config['STATS_RATE'], delta)
示例5: StatsD
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StatsD(object):
def __init__(self, app=None, config=None):
self.config = None
self.statsd = None
if app is not None:
self.init_app(app)
else:
self.app = None
def init_app(self, app, config=None):
if config is not None:
self.config = config
elif self.config is None:
self.config = app.config
self.config.setdefault('STATSD_HOST', 'localhost')
self.config.setdefault('STATSD_PORT', 8125)
self.config.setdefault('STATSD_PREFIX', None)
self.app = app
self.statsd = StatsClient(self.config['STATSD_HOST'],
self.config['STATSD_PORT'], self.config['STATSD_PREFIX'])
def timer(self, *args, **kwargs):
return self.statsd.timer(*args, **kwargs)
def timing(self, *args, **kwargs):
return self.statsd.timing(*args, **kwargs)
def incr(self, *args, **kwargs):
return self.statsd.incr(*args, **kwargs)
def decr(self, *args, **kwargs):
return self.statsd.decr(*args, **kwargs)
def gauge(self, *args, **kwargs):
return self.statsd.gauge(*args, **kwargs)
def set(self, *args, **kwargs):
return self.statsd.set(*args, **kwargs)
示例6: StatsD
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
class StatsD(object):
def __init__(self, app=None, config=None):
self.config = None
self.statsd = None
if app is not None:
self.init_app(app)
else:
self.app = None
def init_app(self, app, config=None):
if config is not None:
self.config = config
elif self.config is None:
self.config = app.config
self.config.setdefault("STATSD_HOST", "localhost")
self.config.setdefault("STATSD_PORT", 8125)
self.config.setdefault("STATSD_PREFIX", None)
self.app = app
self.statsd = StatsClient(
host=self.config["STATSD_HOST"], port=self.config["STATSD_PORT"], prefix=self.config["STATSD_PREFIX"]
)
def timer(self, *args, **kwargs):
return self.statsd.timer(*args, **kwargs)
def timing(self, *args, **kwargs):
return self.statsd.timing(*args, **kwargs)
def incr(self, *args, **kwargs):
return self.statsd.incr(*args, **kwargs)
def decr(self, *args, **kwargs):
return self.statsd.decr(*args, **kwargs)
def gauge(self, *args, **kwargs):
return self.statsd.gauge(*args, **kwargs)
示例7: print
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
#conn.commit()
except:
exceptioncount+=1
exceptionlist.append(sys.exc_info()[0])
logger.exception("Exception:")
query2="update factual_duplicates_last_check set checked_on=now(),last_city_checked=%s"
values=list()
values.append(last_city_checked)
cur.execute(query2,values)
conn.commit()
print("Completed:",cityname,statename)
logger.info("Completed:%s %s",cityname,statename)
print ("total rows:",rowcount)
print ("duplicates:",duplicatecount)
print(exceptionlist)
print("total Exceptions:",exceptioncount)
dt = int((time.time() - start) )
statsd.timing('slept', dt)
print("total time taken (s):",dt)
logger.info("Total Rows:%s",rowcount)
logger.info("Duplicate Rows:%s",duplicatecount)
logger.info("Total Exceptions:%s",exceptioncount)
logger.info("Total time taken (s):%s",dt)
cur.close()
conn.close()
示例8: open
# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import timing [as 别名]
output = open('slow-{ts}.csv'.format(ts=ts[:10]), 'a')
line = "{ts};{rt};{slugs}".format(ts=ts, rt=rt,
slugs=";".join(slugs))
output.write(line)
output.write('\n')
print line
if action == 'users':
logger.setLevel(logging.INFO)
handler = logging.handlers.TimedRotatingFileHandler('users.log', when='D', interval=1)
handler.setLevel(logging.INFO)
logger.addHandler(handler)
statsd = StatsClient('localhost', 8125)
for a in TrackUsers(EventsHose(r, chan)):
t = a[2]
action = a[7]
statsd.timing('action.%s' % action, int(t))
logger.info(" ".join([str(b) for b in a]))
if action == 'errors':
log = logging.getLogger('raven')
log.setLevel(logging.DEBUG)
handler = logging.handlers.TimedRotatingFileHandler('raven.log', when='D', interval=1)
handler.setLevel(logging.DEBUG)
log.addHandler(handler)
hose = EventsHose(r, chan)
dumper = yaml.Dumper
for rq, query, message, ts, agent, source, body in TrackErrors(hose):
status = message['status']
print status
request = UNQUOTE.subn(r"\1", yaml.dump(query, allow_unicode=True,
default_flow_style=False).replace('!!python/unicode ', ''))[0]
print request