How to use the perfmetrics.statsd_client function in perfmetrics

To help you get started, we’ve selected a few perfmetrics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / pypi-legacy / webui.py View on Github external
def run(self):
        ''' Run the request, handling all uncaught errors and finishing off
            cleanly.
        '''
        if self.failed:
            # failed during initialization
            self.fail(self.failed)
            return
        self.store = store.Store(
            self.config,
            queue=self.queue,
            redis=self.count_redis,
            package_bucket=self.package_bucket,
        )
        self.statsd = statsd_client()
        self.dogstatsd = dogstatsd
        try:
            try:
                self.store.get_cursor() # make sure we can connect
                self.inner_run()
            except NotFound, err:
                self.fail('Not Found (%s)' % err, code=404)
            except Gone, err:
                self.fail('Gone (%s)' % err, code=410, headers={"Cache-Control": "max-age=31557600, public"})
            except Unauthorised, message:
                message = str(message)
                if not message:
                    message = 'You must login to access this feature'
                msg = unauth_message%self.__dict__
                self.fail(message, code=401, heading='Login required',
                    content=msg, headers={'WWW-Authenticate':
github pypa / pypi-legacy / fncache.py View on Github external
expires:   Default key expiration time
        capacity:  Approximate Maximum size of caching set
        prefix:    Prefix for all keys in the cache
        tag:       String (formattable optional) to tag keys with for purging
            arg_index/kwarg_name: Choose One, the tag string will be formatted with that argument
        slice_obj: Slice object to cut out un picklable thingz
        """
        self.conn = conn
        self.expires = expires
        self.capacity = capacity
        self.prefix = prefix
        self.tag = tag
        self.arg_index = arg_index
        self.kwarg_name = kwarg_name
        self.slice = slice_obj
        self.statsd = statsd_client()
        self.dogstatsd = dogstatsd
github pypa / pypi-legacy / rpc.py View on Github external
cache_redis = None
else:
    cache_redis = redis.StrictRedis.from_url(conf.cache_redis_url, **redis_kwargs)

# Note: slice object is to cut off the instance of Store that would be passed along
package_tag_lru = RedisLru(cache_redis, expires=86400, tag="pkg~%s", arg_index=1, slice_obj=slice(1, None))
cache_by_pkg = package_tag_lru.decorator

if conf.xmlrpc_redis_url is None:
    xmlrpc_redis = None
else:
    xmlrpc_redis = redis.StrictRedis.from_url(conf.xmlrpc_redis_url, **redis_kwargs)

STATSD_URI = "statsd://127.0.0.1:8125?prefix=%s" % (conf.database_name)
set_statsd_client(STATSD_URI)
statsd_reporter = statsd_client()

def log_xmlrpc_request(remote_addr, user_agent, data):
    if conf.xmlrpc_request_log_file:
        try:
            with open(conf.xmlrpc_request_log_file, 'a') as f:
                params, method = xmlrpclib.loads(data)
                dogstatsd.increment('xmlrpc.request', tags=['method:{}'.format(method)])
                record = json.dumps({
                    'timestamp': datetime.datetime.utcnow().isoformat(),
                    'remote_addr': remote_addr,
                    'user_agent': user_agent,
                    'method': method,
                    'params': params,
                    'type': 'request',
                })
                f.write(record + '\n')

perfmetrics

Send performance metrics about Python code to Statsd

BSD-2-Clause
Latest version published 6 months ago

Package Health Score

59 / 100
Full package analysis

Similar packages