@
glasslion tingyun-database.redis.pyfrom tingyun.api.tracert.redis_trace import wrap_redis_trace
from tingyun.api.tracert.function_trace import wrap_function_trace
rewrite_command = ['setex', 'lrem', 'zadd']
basic_command = [
'append', 'bgrewriteaof', 'bgsave', 'bitcount', 'bitop', 'bitpos', 'blpop', 'brpop', 'brpoplpush', 'client_getname',
'client_kill', 'client_list', 'client_setname', 'config_get', 'config_resetstat', 'config_rewrite', 'config_set',
'connection_pool', 'dbsize', 'debug_object', 'decr', 'delete', 'dump', 'echo', 'eval', 'evalsha', 'execute_command',
'exists', 'expire', 'expireat', 'flushall', 'flushdb', 'from_url', 'get', 'getbit', 'getrange', 'getset', 'hdel',
'hexists', 'hget', 'hgetall', 'hincrby', 'hincrbyfloat', 'hkeys', 'hlen', 'hmget', 'hmset', 'hscan', 'hscan_iter',
'hset', 'hsetnx', 'hvals', 'incr', 'incrby', 'incrbyfloat', 'info', 'keys', 'lastsave', 'lindex', 'linsert', 'llen',
'lock', 'lpop', 'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'mget', 'move', 'mset', 'msetnx',
'object', 'parse_response', 'persist', 'pexpire', 'pexpireat', 'pfadd', 'pfcount', 'pfmerge', 'ping',
'pipeline', 'psetex', 'pttl', 'publish', 'pubsub', 'randomkey', 'register_script', 'rename',
'renamenx', 'response_callbacks', 'restore', 'rpop', 'rpoplpush', 'rpush', 'rpushx', 'sadd', 'save',
'scan', 'scan_iter', 'scard', 'script_exists', 'script_flush', 'script_kill', 'script_load', 'sdiff',
'sdiffstore', 'set', 'set_response_callback', 'setbit', 'setex', 'setnx', 'setrange', 'shutdown',
'sinter', 'sinterstore', 'sismember', 'slaveof', 'slowlog_get', 'slowlog_len', 'slowlog_reset',
'smembers', 'smove', 'sort', 'spop', 'srandmember', 'srem', 'sscan', 'sscan_iter', 'strlen', 'substr',
'sunion', 'sunionstore', 'time', 'transaction', 'ttl', 'type', 'unwatch', 'watch', 'zadd', 'zcard',
'zcount', 'zincrby', 'zinterstore', 'zlexcount', 'zrange', 'zrangebylex', 'zrangebyscore', 'zrank',
'zrem', 'zremrangebylex', 'zremrangebyrank', 'zremrangebyscore', 'zrevrange', 'zrevrangebyscore',
'zrevrank', 'zscan', 'zscan_iter', 'zscore', 'zunionstore']
def detect_connection (module ):
"""
:param module:
:return:
"""
if hasattr (module, 'Connection') and hasattr (module.Connection, 'connect'):
wrap_function_trace (module, "Connection.connect", name="connect")
def detect_client_operation (module ):
"""
:param module:
:return:
"""
if hasattr (module, 'StrictRedis'):
for command in basic_command:
if hasattr (module.StrictRedis, command ):
wrap_redis_trace (module, "StrictRedis.%s" % command, command )
if hasattr (module, 'Redis'):
for command in rewrite_command:
if hasattr (module.Redis, command ):
wrap_redis_trace (module, "Redis.%s" % command, command )
elif hasattr (module, 'Redis'):
for command in basic_command:
if hasattr (module.Redis, command ):
wrap_redis_trace (module, "Redis.%s" % command, command )
newrelic_database.nosql_redis.pyimport newrelic.api.function_trace
_methods_1 = ['bgrewriteaof', 'bgsave', 'config_get', 'config_set',
'dbsize', 'debug_object', 'delete', 'echo', 'flushall',
'flushdb', 'info', 'lastsave', 'object', 'ping', 'save',
'shutdown', 'slaveof', 'append', 'decr', 'exists',
'expire', 'expireat', 'get', 'getbit', 'getset', 'incr',
'keys', 'mget', 'mset', 'msetnx', 'move', 'persist',
'randomkey', 'rename', 'renamenx', 'set', 'setbit',
'setex', 'setnx', 'setrange', 'strlen', 'substr', 'ttl',
'type', 'blpop', 'brpop', 'brpoplpush', 'lindex',
'linsert', 'llen', 'lpop', 'lpush', 'lpushx', 'lrange',
'lrem', 'lset', 'ltrim', 'rpop', 'rpoplpush', 'rpush',
'rpushx', 'sort', 'sadd', 'scard', 'sdiff', 'sdiffstore',
'sinter', 'sinterstore', 'sismember', 'smembers',
'smove', 'spop', 'srandmember', 'srem', 'sunion',
'sunionstore', 'zadd', 'zcard', 'zcount', 'zincrby',
'zinterstore', 'zrange', 'zrangebyscore', 'zrank', 'zrem',
'zremrangebyrank', 'zremrangebyscore', 'zrevrange',
'zrevrangebyscore', 'zrevrank', 'zscore', 'zunionstore',
'hdel', 'hexists', 'hget', 'hgetall', 'hincrby', 'hkeys',
'hlen', 'hset', 'hsetnx', 'hmset', 'hmget', 'hvals',
'publish']
_methods_2 = ['setex', 'lrem', 'zadd']
def instrument_redis_connection (module ):
newrelic.api.function_trace.wrap_function_trace (
module, 'Connection.connect')
def instrument_redis_client (module ):
if hasattr (module, 'StrictRedis'):
for method in _methods_1:
if hasattr (module.StrictRedis, method ):
newrelic.api.function_trace.wrap_function_trace (
module, 'StrictRedis.%s' % method )
else:
for method in _methods_1:
if hasattr (module.Redis, method ):
newrelic.api.function_trace.wrap_function_trace (
module, 'Redis.%s' % method )
for method in _methods_2:
if hasattr (module.Redis, method ):
newrelic.api.function_trace.wrap_function_trace (module, 'Redis.%s' % method )