How to use the perfmetrics.set_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 / fncache.py View on Github external
import redis

from functools import wraps

from perfmetrics import statsd_client
from perfmetrics import set_statsd_client

from dogadapter import dogstatsd

import config

root = os.path.dirname(os.path.abspath(__file__))
conf = config.Config(os.path.join(root, "config.ini"))

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


class RedisLru(object):
    """
    Redis backed LRU cache for functions which return an object which
    can survive json.dumps() and json.loads() intact
    """

    def __init__(self, conn, expires=86400, capacity=5000, prefix="lru", tag=None, arg_index=None, kwarg_name=None, slice_obj=slice(None)):
        """
        conn:      Redis Connection Object
        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
github pypa / pypi-legacy / webui.py View on Github external
from dogadapter import dogstatsd

from constants import DOMAIN_BLACKLIST

# Authomatic
from authadapters import PyPIAdapter
import authomatic
from authomatic.providers import openid
from authomatic.providers import oauth2
from browserid.jwt import parse

root = os.path.dirname(os.path.abspath(__file__))
conf = config.Config(os.path.join(root, "config.ini"))

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


EMPTY_RSS = """


 
  <title>PyPI Recent Updates</title>
  https://pypi.python.org/pypi
  Recent updates to the Python Package Index
  en
 

"""


WAREHOUSE_UPLOAD_MIGRATION_URL = "https://packaging.python.org/guides/migrating-to-pypi-org/#uploading"
github pypa / pypi-legacy / rpc.py View on Github external
if conf.cache_redis_url is None:
    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',
                })

perfmetrics

Send performance metrics about Python code to Statsd

BSD-2-Clause
Latest version published 11 months ago

Package Health Score

53 / 100
Full package analysis

Similar packages