本文整理汇总了Python中statsd.StatsClient方法的典型用法代码示例。如果您正苦于以下问题:Python statsd.StatsClient方法的具体用法?Python statsd.StatsClient怎么用?Python statsd.StatsClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsd
的用法示例。
在下文中一共展示了statsd.StatsClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def __init__(self, env):
self.env = env
conf = env.config.get(ConfigKeys.STATS_SERVICE)
host = conf.get(ConfigKeys.HOST)
if env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
self.statsd = MockStatsd()
else:
import statsd
port = conf.get(ConfigKeys.PORT)
prefix = 'dino'
if ConfigKeys.PREFIX in conf:
prefix = conf.get(ConfigKeys.PREFIX)
if ConfigKeys.INCLUDE_HOST_NAME in conf:
include_host_name = conf.get(ConfigKeys.INCLUDE_HOST_NAME)
if include_host_name is not None and str(include_host_name).strip().lower() in ['yes', '1', 'true']:
import socket
prefix = '%s.%s' % (prefix, socket.gethostname())
self.statsd = statsd.StatsClient(host, int(port), prefix=prefix)
示例2: disk
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def disk():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.disk')
while True:
for path, label in PATHS:
disk_usage = psutil.disk_usage(path)
st = os.statvfs(path)
total_inode = st.f_files
free_inode = st.f_ffree
inode_percentage = int(100*(float(total_inode - free_inode) / total_inode))
c.gauge('%s.inodes.percent' % label, inode_percentage)
c.gauge('%s.total' % label, disk_usage.total)
c.gauge('%s.used' % label, disk_usage.used)
c.gauge('%s.free' % label, disk_usage.free)
c.gauge('%s.percent' % label, disk_usage.percent)
time.sleep(GRANULARITY)
示例3: cpu_times_percent
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def cpu_times_percent():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.cpu')
while True:
value = psutil.cpu_percent(interval=1)
c.gauge('system_wide.percent', value)
cpu_t_percent = psutil.cpu_times_percent(interval=1)
c.gauge('system_wide.times_percent.user', cpu_t_percent.user)
c.gauge('system_wide.times_percent.nice', cpu_t_percent.nice)
c.gauge('system_wide.times_percent.system', cpu_t_percent.system)
c.gauge('system_wide.times_percent.idle', cpu_t_percent.idle)
c.gauge('system_wide.times_percent.iowait', cpu_t_percent.iowait)
c.gauge('system_wide.times_percent.irq', cpu_t_percent.irq)
c.gauge('system_wide.times_percent.softirq', cpu_t_percent.softirq)
c.gauge('system_wide.times_percent.steal', cpu_t_percent.steal)
c.gauge('system_wide.times_percent.guest', cpu_t_percent.guest)
c.gauge('system_wide.times_percent.guest_nice', cpu_t_percent.guest_nice)
time.sleep(GRANULARITY)
示例4: memory
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def memory():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.memory')
while True:
swap = psutil.swap_memory()
c.gauge('swap.total', swap.total)
c.gauge('swap.used', swap.used)
c.gauge('swap.free', swap.free)
c.gauge('swap.percent', swap.percent)
virtual = psutil.virtual_memory()
c.gauge('virtual.total', virtual.total)
c.gauge('virtual.available', virtual.available)
c.gauge('virtual.used', virtual.used)
c.gauge('virtual.free', virtual.free)
c.gauge('virtual.percent', virtual.percent)
c.gauge('virtual.active', virtual.active)
c.gauge('virtual.inactive', virtual.inactive)
c.gauge('virtual.buffers', virtual.buffers)
c.gauge('virtual.cached', virtual.cached)
time.sleep(GRANULARITY)
示例5: online_count
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def online_count():
c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'online')
while True:
for _, _, community, db_num in hosts:
count = r_servers[community].scard('users:multicast')
c.gauge('%s.count' % community, count)
sessions = r_servers[community].hgetall('session:count')
session_count = 0
for _, value in sessions.items():
session_count += int(float(str(value, 'utf-8')))
c.gauge('%s.count' % community, count)
c.gauge('%s.sessions' % community, session_count)
time.sleep(GRANULARITY)
示例6: connect
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def connect(self, params):
self.logger.info("Connect: Connecting..")
host = params.get('host')
port = params.get('port')
prefix = params.get('prefix', None)
protocol = params.get('protocol')
self.host = host
self.port = port
self.protocol = protocol
if protocol == 'TCP':
timeout = params.get('tcp', None)['timeout']
timeout = None if timeout == 0 else timeout
self.instance = statsd.TCPStatsClient(host, port, prefix, timeout)
elif protocol == 'UDP':
maxudpsize = params.get('udp', 512)
if maxudpsize is not None:
maxudpsize = maxudpsize['maxudpsize']
self.instance = statsd.StatsClient(host, port, prefix, maxudpsize)
示例7: __init__
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def __init__(self, interface_dict):
self.log = logging.getLogger('Main.Feeds.RPC')
self.worker_pools = {}
self.interface_dict = interface_dict
self.mon_con = statsd.StatsClient(
host = settings_file.GRAPHITE_DB_IP,
port = 8125,
prefix = 'ReadableWebProxy.FetchAgent',
)
self.debug_interval = 10
self.chunk_flush_interval = 10
self.last_debug = time.time() - self.debug_interval
self.last_chunk_flush = time.time() - self.chunk_flush_interval
os.makedirs(settings_file.CHUNK_CACHE_DIR, exist_ok=True)
示例8: init
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def init():
global _client
statsd_host = os.environ.get('FLANKER_METRICS_HOST')
statsd_port = os.environ.get('FLANKER_METRICS_PORT')
statsd_prfx = os.environ.get('FLANKER_METRICS_PREFIX')
if not statsd_host or not statsd_port or not statsd_prfx:
return
try:
import statsd
except ImportError:
return
_client = statsd.StatsClient(statsd_host, statsd_port, prefix=statsd_prfx)
示例9: get_statsd_logger
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def get_statsd_logger(self):
if conf.getboolean('scheduler', 'statsd_on'):
from statsd import StatsClient
if conf.has_option('scheduler', 'statsd_custom_client_path'):
stats_class = conf.getimport('scheduler', 'statsd_custom_client_path')
if not issubclass(stats_class, StatsClient):
raise AirflowConfigException(
"Your custom Statsd client must extend the statsd.StatsClient in order to ensure "
"backwards compatibility."
)
else:
log.info("Successfully loaded custom Statsd client")
else:
stats_class = StatsClient
statsd = stats_class(
host=conf.get('scheduler', 'statsd_host'),
port=conf.getint('scheduler', 'statsd_port'),
prefix=conf.get('scheduler', 'statsd_prefix'))
allow_list_validator = AllowListValidator(conf.get('scheduler', 'statsd_allow_list', fallback=None))
return SafeStatsdLogger(statsd, allow_list_validator)
示例10: __init__
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def __init__(self, config=None):
# Shouldn't be trying imports in __init__.
# It turns what should be a load error into a runtime error
config = normalize_config(config)
self.config = config
self.client = InfluxDBClient(config['host'], config['port'], config['user'], config['passw'], config['db'], config['ssl'])
self.schemas = [(re.compile(patt), step) for (patt, step) in config['schema']]
try:
self.statsd_client = statsd.StatsClient(config['statsd'].get('host'),
config['statsd'].get('port', 8125)) \
if 'statsd' in config and config['statsd'].get('host') else NullStatsd()
except NameError:
logger.warning("Statsd client configuration present but 'statsd' module"
"not installed - ignoring statsd configuration..")
self.statsd_client = NullStatsd()
self._setup_logger(config['log_level'], config['log_file'])
self.es = None
if config['es_enabled']:
try:
from elasticsearch import Elasticsearch
except ImportError:
logger.warning("Elasticsearch configuration present but 'elasticsearch'"
"module not installed - ignoring elasticsearch configuration..")
else:
self.es = Elasticsearch(config['es_hosts'])
示例11: _get_statsd_client
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def _get_statsd_client(*, prefix: str) -> StatsClient:
"""
Object pool method that reuse already created StatsClient based on prefix
:param prefix:
:return:
"""
if not has_app_context() or not current_app.config[config.IS_STATSD_ON]:
return None
else:
if prefix not in __STATSD_POOL:
with __STATSD_POOL_LOCK:
if prefix not in __STATSD_POOL:
LOGGER.info('Instantiate StatsClient with prefix {}'.format(prefix))
statsd_client = StatsClient(prefix=prefix)
__STATSD_POOL[prefix] = statsd_client
return statsd_client
if LOGGER.isEnabledFor(logging.DEBUG):
LOGGER.debug('Reuse StatsClient with prefix {}'.format(prefix))
return __STATSD_POOL[prefix]
示例12: test_get_statsd_client
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def test_get_statsd_client(self) -> None:
with patch.object(current_app, 'config') as mock_config, \
patch.object(StatsClient, '__init__', return_value=None) as mock_statsd_init:
mock_config.return_value.single.return_value = True
statsd_client1 = _get_statsd_client(prefix='foo')
self.assertIsNotNone(statsd_client1)
statsd_client2 = _get_statsd_client(prefix='foo')
self.assertIsNotNone(statsd_client2)
self.assertEqual(statsd_client1, statsd_client2)
self.assertEqual(mock_statsd_init.call_count, 1)
statsd_client3 = _get_statsd_client(prefix='bar')
self.assertIsNotNone(statsd_client3)
statsd_client4 = _get_statsd_client(prefix='bar')
self.assertIsNotNone(statsd_client4)
self.assertEqual(statsd_client3, statsd_client4)
self.assertNotEqual(statsd_client1, statsd_client3)
self.assertEqual(mock_statsd_init.call_count, 2)
示例13: get_statsd_client
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def get_statsd_client(self):
if not statsd:
return None
statsd_args = {}
if self._statsd_host:
statsd_args['host'] = self._statsd_host
if self._statsd_port:
statsd_args['port'] = self._statsd_port
if statsd_args:
try:
return statsd.StatsClient(**statsd_args)
except Exception:
self.log.warning('Cannot establish connection to statsd')
return None
else:
return None
示例14: _get_statsd_client
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def _get_statsd_client(*, prefix: str) -> StatsClient:
"""
Object pool method that reuse already created StatsClient based on prefix
:param prefix:
"""
if not current_app.config[config.STATS_FEATURE_KEY]:
# return if stats feature is not enabled
return None
else:
if prefix not in _STATSD_POOL:
with _STATSD_POOL_LOCK:
if prefix not in _STATSD_POOL:
LOGGER.info('Instantiate StatsClient with prefix {}'.format(prefix))
statsd_client = StatsClient(prefix=prefix)
_STATSD_POOL[prefix] = statsd_client
return statsd_client
if LOGGER.isEnabledFor(logging.DEBUG):
LOGGER.debug('Reuse StatsClient with prefix {}'.format(prefix))
return _STATSD_POOL[prefix]
示例15: __init__
# 需要导入模块: import statsd [as 别名]
# 或者: from statsd import StatsClient [as 别名]
def __init__(self,
conf,
task,
publisher=NoopPublisher()):
# type: (ConfigTree, Task, Publisher) -> None
self.task = task
self.conf = conf
self.publisher = publisher
self.scoped_conf = Scoped.get_scoped_conf(self.conf,
self.get_scope())
if self.scoped_conf.get_bool(DefaultJob.IS_STATSD_ENABLED, False):
prefix = 'amundsen.databuilder.job.{}'.format(self.scoped_conf.get_string(DefaultJob.JOB_IDENTIFIER))
LOGGER.info('Setting statsd for job metrics with prefix: {}'.format(prefix))
self.statsd = StatsClient(prefix=prefix)
else:
self.statsd = None