当前位置: 首页>>代码示例>>Python>>正文


Python StatsClient.incr方法代码示例

本文整理汇总了Python中statsd.StatsClient.incr方法的典型用法代码示例。如果您正苦于以下问题:Python StatsClient.incr方法的具体用法?Python StatsClient.incr怎么用?Python StatsClient.incr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statsd.StatsClient的用法示例。


在下文中一共展示了StatsClient.incr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: StatsdStatsLogger

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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)
开发者ID:tan31989,项目名称:caravel,代码行数:29,代码来源:stats_logger.py

示例2: StaticticStatsD

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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)
开发者ID:dreadatour,项目名称:gossip,代码行数:37,代码来源:stats.py

示例3: send_stats

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
def send_stats(last_timestamp, last_message_count, json_filename):
	with open(json_filename) as data_file:
		data = json.load(data_file)

	current_timestamp = data["now"]
	current_message_count = data["messages"]

	secs = False
	msgs = False

	if last_timestamp is False:
		print "Starting up, first pass...."
	elif current_message_count < last_message_count:
		print "Looks like dump1090 restarted, message count reset (%d)" % current_message_count
	else:
		secs = current_timestamp - last_timestamp
		msgs = current_message_count - last_message_count
		
		print "{0} sec\t{1} messages\t{2} messages per sec avg".format(secs, msgs, (msgs / secs))

	last_timestamp = current_timestamp
	last_message_count = current_message_count
	threading.Timer(INTERVAL, send_stats, [last_timestamp, last_message_count, json_filename]).start()

	aircrafts_5s = []
	aircrafts_10s = []
	aircrafts_30s = []
	aircrafts_60s = []

	for aircraft in data["aircraft"]:
		if aircraft["seen"] < 5:
			aircrafts_5s.append(aircraft["hex"])
		if aircraft["seen"] < 10:
			aircrafts_10s.append(aircraft["hex"])
		if aircraft["seen"] < 30:
			aircrafts_30s.append(aircraft["hex"])
		if aircraft["seen"] < 60:
			aircrafts_60s.append(aircraft["hex"])

	print "\t5s:{0}\t10s:{1}\t30s:{2}\t60s:{3}".format(len(aircrafts_5s), len(aircrafts_10s), len(aircrafts_30s), len(aircrafts_60s))

	radio_name = sys.argv[1]

	if secs:
		client = StatsClient(STATSD_HOST)
		client.incr("radios.%s.message_rate" % radio_name, msgs)

		pipe = client.pipeline()
		c = 0
		max_msg_size = 20
		for hex in aircrafts_10s:
			pipe.set("radios.%s.aircraft" % radio_name, hex)
			c = c + 1
			if c == max_msg_size:
				pipe.send()
				c = 0
		if c != max_msg_size:
			pipe.send()
开发者ID:dsilvers,项目名称:dump1090-statsd,代码行数:60,代码来源:aircraft-to-statsd.py

示例4: test_disabled_client

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
def test_disabled_client():
    """ Assert that a cliend with disabled=True does not send any data to
    statsd.
    """
    sc = StatsClient(host=ADDR[0], port=ADDR[1], disable=True)
    sc._sock = mock.Mock()

    sc.incr('foo')

    eq_(sc._sock.call_count, 0)
开发者ID:tiriplicamihai,项目名称:pystatsd,代码行数:12,代码来源:tests.py

示例5: StatsdStatsLogger

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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 gauge(self, key):
            # pylint: disable=no-value-for-parameter
            self.client.gauge(key)
开发者ID:alanmcruickshank,项目名称:caravel,代码行数:15,代码来源:stats_logger.py

示例6: StatsDBackend

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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)
开发者ID:gabrielpjordao,项目名称:flask-stats,代码行数:27,代码来源:flask_stats.py

示例7: _Statsd

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
class _Statsd(object):
    def __init__(self, config):
        if config.get('datadog', True):
            initialize(statsd_host=config['host'],
                       statsd_port=config['port'],
                       prefix=config['prefix'])
            self.datadog = True
            self._statsd = statsd
        else:
            self.datadog = False
            self._statsd = StatsClient(config['host'],
                                       config['port'],
                                       config['prefix'])

    def incr(self, metric, count=1, rate=1, **kw):
        if self.datadog:
            return self._statsd.increment(metric, value=count,
                                          sample_rate=rate, **kw)
        else:
            return self._statsd.incr(metric, count=count, rate=rate)

    def timer(self, metric, rate=1, **kw):
        if self.datadog:
            return self._statsd.timed(metric, sample_rate=rate, **kw)
        else:
            return self._statsd.timer(metric, rate=rate)
开发者ID:armenzg,项目名称:absearch,代码行数:28,代码来源:server.py

示例8: StatsD

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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)
开发者ID:adsabs,项目名称:flask-statsd,代码行数:43,代码来源:flask_statsd.py

示例9: StatsD

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [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)
开发者ID:tarzan0820,项目名称:flask-statsd,代码行数:41,代码来源:flask_statsd.py

示例10: StatsClient

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
from flask import Flask, render_template, g, request, redirect
import requests
import json
from collections import OrderedDict
import datetime
import pymongo
from statsd import StatsClient

statsd = StatsClient(host='127.0.0.1',
                     port=8125)

statsd.incr('start')


app = Flask(__name__)

conn = pymongo.MongoClient()
db = conn.blog

@app.route("/")
@statsd.timer('index')
def index():
    statsd.incr('index_pageview')
    articles = db.articles.find().sort('created_at', pymongo.DESCENDING).limit(10)
    ret = []
    for article in articles:
        user = db.users.find_one({'user_id': article['user_id']})
        article['user'] = user
        ret.append(article)
    latest_users = db.users.find().sort('created_at', pymongo.DESCENDING).limit(10)
    return render_template('index.html', articles=ret, latest_users=latest_users)
开发者ID:ybrs,项目名称:graphite-statsd-presentation,代码行数:33,代码来源:app.py

示例11: StatsClient

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
from statsd import StatsClient
from datetime import datetime
from time import sleep

statsd_client = StatsClient(host='metrics')

print 'incrementing by \"n\"'             # print start statement
for x in range(100,1000,100):             # start of loop
    statsd_client.incr('sd_incr_count',x) # increment by X value
    print 'increment by {}'.format(x)     # print increment log
开发者ID:rjjanuary,项目名称:thermos,代码行数:12,代码来源:statsd_4_increment_by.py

示例12: StatsdMetrics

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
class StatsdMetrics(Metrics):

    def __init__(self, host='localhost', port=8125, prefix=None):
        self.statsd = StatsClient(host, port, prefix)

    def fanout_timer(self, feed_class):
        return self.statsd.timer('%s.fanout_latency' % feed_class.__name__)

    def feed_reads_timer(self, feed_class):
        return self.statsd.timer('%s.read_latency' % feed_class.__name__)

    def on_feed_read(self, feed_class, activities_count):
        self.statsd.incr('%s.reads' % feed_class.__name__, activities_count)

    def on_feed_write(self, feed_class, activities_count):
        self.statsd.incr('%s.writes' % feed_class.__name__, activities_count)

    def on_feed_remove(self, feed_class, activities_count):
        self.statsd.incr('%s.deletes' % feed_class.__name__, activities_count)

    def on_fanout(self, feed_class, operation, activities_count=1):
        metric = (feed_class.__name__, operation.__name__)
        self.statsd.incr('%s.fanout.%s' % metric, activities_count)

    def on_activity_published(self):
        self.statsd.incr('activities.published')

    def on_activity_removed(self):
        self.statsd.incr('activities.removed')
开发者ID:0xD3ADB33F,项目名称:Stream-Framework,代码行数:31,代码来源:statsd.py

示例13: StatsClient

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
from evdev import InputDevice, categorize, ecodes
import secrets
from statsd import StatsClient

c = StatsClient(host=secrets.GRAPHITE_URL, port=8126, prefix=None)

dev = InputDevice('/dev/input/event0')

for event in dev.read_loop():
  if event.type == ecodes.EV_KEY:
    if event.value == 01:
      c.incr('keystroke', count=1, rate=1)
开发者ID:mattjbarlow,项目名称:keystrokes,代码行数:14,代码来源:keycounts.py

示例14: StatsClient

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
#!/usr/bin/python

from statsd import StatsClient
import os

statsd = StatsClient(host='metrics.ccs.neu.edu')

if os.getenv('PAM_TYPE') == 'open_session':
  statsd.incr('ccs.linux.102.logins')
else:
  statsd.decr('ccs.linux.102.logins')

开发者ID:pranav,项目名称:metrics3,代码行数:13,代码来源:client.py

示例15: get_option

# 需要导入模块: from statsd import StatsClient [as 别名]
# 或者: from statsd.StatsClient import incr [as 别名]
    conn = util.opendb()
    c = conn.cursor()

    util.create_schema(c)
    auth = util.authinfo(c)
    
    (q,option) = get_option(c,q)
    last_q = q.split(' ')[-1]
    if q.startswith('_'):   # option
        process_option(c,q)
    elif q.startswith('+'): # add bookmark
        add_bookmark(c,q)
    elif last_q.startswith('#') and (':' not in q): # tag expansion
        pbsearch_tag(c,'',last_q[1:])
    else:
        pbsearch_sql(c,option,q)
    
    util.closedb(conn)

if __name__ == '__main__':
    try:
        statsd = StatsClient(host='g.jmjeong.com',
                             port=8125,
                             prefix='jmjeong.alfred.bookmark')

        with statsd.timer('main'):
            statsd.incr('launch');
            main()
    except:
        main()
开发者ID:jmjeong,项目名称:alfred-extension,代码行数:32,代码来源:main.py


注:本文中的statsd.StatsClient.incr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。